Home | History | Annotate | Line # | Download | only in pci
if_re_pci.c revision 1.22
      1  1.22   tsutsui /*	$NetBSD: if_re_pci.c,v 1.22 2007/02/04 03:20:23 tsutsui Exp $	*/
      2   1.4      yamt 
      3   1.4      yamt /*
      4   1.4      yamt  * Copyright (c) 1997, 1998-2003
      5   1.4      yamt  *	Bill Paul <wpaul (at) windriver.com>.  All rights reserved.
      6   1.4      yamt  *
      7   1.4      yamt  * Redistribution and use in source and binary forms, with or without
      8   1.4      yamt  * modification, are permitted provided that the following conditions
      9   1.4      yamt  * are met:
     10   1.4      yamt  * 1. Redistributions of source code must retain the above copyright
     11   1.4      yamt  *    notice, this list of conditions and the following disclaimer.
     12   1.4      yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.4      yamt  *    notice, this list of conditions and the following disclaimer in the
     14   1.4      yamt  *    documentation and/or other materials provided with the distribution.
     15   1.4      yamt  * 3. All advertising materials mentioning features or use of this software
     16   1.4      yamt  *    must display the following acknowledgement:
     17   1.4      yamt  *	This product includes software developed by Bill Paul.
     18   1.4      yamt  * 4. Neither the name of the author nor the names of any co-contributors
     19   1.4      yamt  *    may be used to endorse or promote products derived from this software
     20   1.4      yamt  *    without specific prior written permission.
     21   1.4      yamt  *
     22   1.4      yamt  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     23   1.4      yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.4      yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.4      yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     26   1.4      yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27   1.4      yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28   1.4      yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29   1.4      yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30   1.4      yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31   1.4      yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     32   1.4      yamt  * THE POSSIBILITY OF SUCH DAMAGE.
     33   1.4      yamt  */
     34   1.4      yamt 
     35   1.4      yamt /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/re/if_re.c,v 1.20 2004/04/11 20:34:08 ru Exp $ */
     36   1.4      yamt 
     37   1.1  jonathan /*
     38   1.1  jonathan  * RealTek 8139C+/8169/8169S/8110S PCI NIC driver
     39   1.1  jonathan  *
     40   1.1  jonathan  * Written by Bill Paul <wpaul (at) windriver.com>
     41   1.1  jonathan  * Senior Networking Software Engineer
     42   1.1  jonathan  * Wind River Systems
     43   1.1  jonathan  *
     44  1.21  christos  * NetBSD bus-specific frontends for written by
     45   1.1  jonathan  * Jonathan Stone <jonathan (at) netbsd.org>
     46   1.1  jonathan  */
     47   1.1  jonathan 
     48   1.1  jonathan #include "bpfilter.h"
     49   1.1  jonathan #include "vlan.h"
     50   1.1  jonathan 
     51   1.1  jonathan #include <sys/types.h>
     52   1.1  jonathan 
     53   1.1  jonathan #include <sys/param.h>
     54   1.1  jonathan #include <sys/endian.h>
     55   1.1  jonathan #include <sys/systm.h>
     56   1.1  jonathan #include <sys/sockio.h>
     57   1.1  jonathan #include <sys/mbuf.h>
     58   1.1  jonathan #include <sys/malloc.h>
     59   1.1  jonathan #include <sys/kernel.h>
     60   1.1  jonathan #include <sys/socket.h>
     61   1.1  jonathan #include <sys/device.h>
     62   1.1  jonathan 
     63   1.1  jonathan #include <net/if.h>
     64   1.1  jonathan #include <net/if_arp.h>
     65   1.1  jonathan #include <net/if_dl.h>
     66   1.1  jonathan #include <net/if_ether.h>
     67   1.1  jonathan #include <net/if_media.h>
     68   1.1  jonathan #include <net/if_vlanvar.h>
     69   1.1  jonathan 
     70   1.5    briggs #include <machine/bus.h>
     71   1.5    briggs 
     72   1.1  jonathan #include <dev/mii/mii.h>
     73   1.1  jonathan #include <dev/mii/miivar.h>
     74   1.1  jonathan 
     75   1.5    briggs #include <dev/pci/pcireg.h>
     76   1.5    briggs #include <dev/pci/pcivar.h>
     77   1.5    briggs #include <dev/pci/pcidevs.h>
     78   1.5    briggs 
     79   1.1  jonathan #include <dev/ic/rtl81x9reg.h>
     80   1.1  jonathan #include <dev/ic/rtl81x9var.h>
     81   1.1  jonathan #include <dev/ic/rtl8169var.h>
     82   1.1  jonathan 
     83   1.1  jonathan struct re_pci_softc {
     84   1.1  jonathan 	struct rtk_softc sc_rtk;
     85   1.1  jonathan 
     86   1.1  jonathan 	void *sc_ih;
     87   1.1  jonathan 	pci_chipset_tag_t sc_pc;
     88   1.1  jonathan 	pcitag_t sc_pcitag;
     89   1.1  jonathan };
     90   1.1  jonathan 
     91  1.20   tsutsui static int	re_pci_match(struct device *, struct cfdata *, void *);
     92   1.1  jonathan static void	re_pci_attach(struct device *, struct device *, void *);
     93   1.1  jonathan 
     94   1.1  jonathan /*
     95   1.1  jonathan  * Various supported device vendors/types and their names.
     96   1.1  jonathan  */
     97   1.6  jdolecek static const struct rtk_type re_devs[] = {
     98  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8139,
     99  1.19   tsutsui 	    RTK_HWREV_8139CPLUS,
    100  1.19   tsutsui 	    "RealTek 8139C+ 10/100BaseTX" },
    101  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8101E,
    102  1.19   tsutsui 	    RTK_HWREV_8100E,
    103  1.19   tsutsui 	    "RealTek 8100E PCIe 10/100BaseTX" },
    104  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8101E,
    105  1.19   tsutsui 	    RTK_HWREV_8101E,
    106  1.19   tsutsui 	    "RealTek 8101E PCIe 10/100BaseTX" },
    107  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8168,
    108  1.19   tsutsui 	    RTK_HWREV_8168_SPIN1,
    109  1.19   tsutsui 	    "RealTek 8168B/8111B PCIe Gigabit Ethernet" },
    110  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8168,
    111  1.19   tsutsui 	    RTK_HWREV_8168_SPIN2,
    112  1.19   tsutsui 	    "RealTek 8168B/8111B PCIe Gigabit Ethernet" },
    113  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8169,
    114  1.19   tsutsui 	    RTK_HWREV_8169,
    115  1.19   tsutsui 	    "RealTek 8169 Gigabit Ethernet" },
    116  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8169,
    117  1.19   tsutsui 	    RTK_HWREV_8169S,
    118  1.19   tsutsui 	    "RealTek 8169S Single-chip Gigabit Ethernet" },
    119  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8169,
    120  1.19   tsutsui 	    RTK_HWREV_8110S,
    121  1.19   tsutsui 	    "RealTek 8110S Single-chip Gigabit Ethernet" },
    122  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8169,
    123  1.19   tsutsui 	    RTK_HWREV_8169_8110SB,
    124  1.19   tsutsui 	    "RealTek 8169SB/8110SB Single-chip Gigabit Ethernet" },
    125  1.19   tsutsui 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8169SC,
    126  1.19   tsutsui 	    RTK_HWREV_8169_8110SC,
    127  1.19   tsutsui 	    "RealTek 8169SC/8110SC Single-chip Gigabit Ethernet" },
    128  1.19   tsutsui 	{ PCI_VENDOR_COREGA, PCI_PRODUCT_COREGA_LAPCIGT,
    129  1.19   tsutsui 	    RTK_HWREV_8169S,
    130  1.19   tsutsui 	    "Corega CG-LAPCIGT Gigabit Ethernet" },
    131  1.19   tsutsui 	{ PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DGE528T,
    132  1.19   tsutsui 	    RTK_HWREV_8169S,
    133  1.19   tsutsui 	    "D-Link DGE-528T Gigabit Ethernet" },
    134  1.19   tsutsui 	{ PCI_VENDOR_USR2, PCI_PRODUCT_USR2_USR997902,
    135  1.19   tsutsui 	    RTK_HWREV_8169S,
    136  1.19   tsutsui 	    "US Robotics (3Com) USR997902 Gigabit Ethernet" },
    137  1.19   tsutsui 	{ PCI_VENDOR_LINKSYS, PCI_PRODUCT_LINKSYS_EG1032,
    138  1.19   tsutsui 	    RTK_HWREV_8169S,
    139  1.19   tsutsui 	    "Linksys EG1032 rev. 3 Gigabit Ethernet" },
    140   1.1  jonathan 	{ 0, 0, 0, NULL }
    141   1.1  jonathan };
    142   1.1  jonathan 
    143   1.6  jdolecek static const struct rtk_hwrev re_hwrevs[] = {
    144   1.1  jonathan 	{ RTK_HWREV_8139, RTK_8139,  "" },
    145   1.1  jonathan 	{ RTK_HWREV_8139A, RTK_8139, "A" },
    146   1.1  jonathan 	{ RTK_HWREV_8139AG, RTK_8139, "A-G" },
    147   1.1  jonathan 	{ RTK_HWREV_8139B, RTK_8139, "B" },
    148   1.1  jonathan 	{ RTK_HWREV_8130, RTK_8139, "8130" },
    149   1.1  jonathan 	{ RTK_HWREV_8139C, RTK_8139, "C" },
    150   1.1  jonathan 	{ RTK_HWREV_8139D, RTK_8139, "8139D/8100B/8100C" },
    151   1.1  jonathan 	{ RTK_HWREV_8139CPLUS, RTK_8139CPLUS, "C+"},
    152  1.19   tsutsui 	{ RTK_HWREV_8168_SPIN1, RTK_8169, "8168B/8111B"},
    153  1.19   tsutsui 	{ RTK_HWREV_8168_SPIN2, RTK_8169, "8168B/8111B"},
    154   1.1  jonathan 	{ RTK_HWREV_8169, RTK_8169, "8169"},
    155   1.1  jonathan 	{ RTK_HWREV_8169S, RTK_8169, "8169S"},
    156   1.1  jonathan 	{ RTK_HWREV_8110S, RTK_8169, "8110S"},
    157  1.19   tsutsui 	{ RTK_HWREV_8169_8110SB, RTK_8169, "8169SB"},
    158  1.19   tsutsui 	{ RTK_HWREV_8169_8110SC, RTK_8169, "8169SC"},
    159  1.19   tsutsui 	{ RTK_HWREV_8100E, RTK_8169, "8100E"},
    160  1.19   tsutsui 	{ RTK_HWREV_8101E, RTK_8169, "8101E"},
    161   1.1  jonathan 	{ RTK_HWREV_8100, RTK_8139, "8100"},
    162   1.1  jonathan 	{ RTK_HWREV_8101, RTK_8139, "8101"},
    163   1.1  jonathan 	{ 0, 0, NULL }
    164   1.1  jonathan };
    165   1.1  jonathan 
    166  1.11       riz #define RE_LINKSYS_EG1032_SUBID	0x00241737
    167  1.11       riz 
    168  1.20   tsutsui CFATTACH_DECL(re_pci, sizeof(struct re_pci_softc), re_pci_match, re_pci_attach,
    169   1.1  jonathan 	      NULL, NULL);
    170   1.1  jonathan 
    171   1.1  jonathan /*
    172   1.1  jonathan  * Probe for a RealTek 8139C+/8169/8110 chip. Check the PCI vendor and device
    173   1.1  jonathan  * IDs against our list and return a device name if we find a match.
    174   1.1  jonathan  */
    175   1.1  jonathan static int
    176  1.20   tsutsui re_pci_match(struct device *parent, struct cfdata *match, void *aux)
    177   1.1  jonathan {
    178  1.22   tsutsui 	const struct rtk_type	*t;
    179   1.1  jonathan 	struct pci_attach_args	*pa = aux;
    180  1.22   tsutsui 	bus_space_tag_t		iot, memt, bst;
    181  1.22   tsutsui 	bus_space_handle_t	ioh, memh, bsh;
    182  1.22   tsutsui 	bus_size_t		memsize, iosize, bsize;
    183   1.1  jonathan 	u_int32_t		hwrev;
    184  1.11       riz 	pcireg_t subid;
    185  1.22   tsutsui 	boolean_t ioh_valid, memh_valid;
    186  1.11       riz 
    187  1.11       riz 	subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    188  1.11       riz 
    189  1.11       riz 	/* special-case Linksys EG1032, since rev 2 uses sk(4) */
    190  1.11       riz 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_LINKSYS &&
    191  1.11       riz 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_LINKSYS_EG1032 &&
    192  1.11       riz 	    subid == RE_LINKSYS_EG1032_SUBID)
    193  1.11       riz 		return 1;
    194   1.1  jonathan 
    195   1.1  jonathan 	t = re_devs;
    196   1.1  jonathan 
    197   1.3   kanaoka 	while (t->rtk_name != NULL) {
    198   1.1  jonathan 		if ((PCI_VENDOR(pa->pa_id) == t->rtk_vid) &&
    199   1.1  jonathan 		    (PCI_PRODUCT(pa->pa_id) == t->rtk_did)) {
    200   1.1  jonathan 
    201   1.1  jonathan 			/*
    202   1.1  jonathan 			 * Temporarily map the I/O space
    203   1.1  jonathan 			 * so we can read the chip ID register.
    204   1.1  jonathan 			 */
    205  1.22   tsutsui 			ioh_valid = (pci_mapreg_map(pa, RTK_PCI_LOIO,
    206  1.22   tsutsui 			    PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
    207  1.22   tsutsui 			    NULL, &iosize) == 0);
    208  1.22   tsutsui 			memh_valid = (pci_mapreg_map(pa, RTK_PCI_LOMEM,
    209  1.22   tsutsui 			    PCI_MAPREG_TYPE_MEM, 0, &memt, &memh,
    210  1.22   tsutsui 			    NULL, &memsize) == 0);
    211  1.22   tsutsui 			if (ioh_valid) {
    212  1.22   tsutsui 				bst = iot;
    213  1.22   tsutsui 				bsh = ioh;
    214  1.22   tsutsui 				bsize = iosize;
    215  1.22   tsutsui 			} else if (memh_valid) {
    216  1.22   tsutsui 				bst = memt;
    217  1.22   tsutsui 				bsh = memh;
    218  1.22   tsutsui 				bsize = memsize;
    219  1.22   tsutsui 			} else
    220   1.7      yamt 				return 0;
    221  1.22   tsutsui 			hwrev = bus_space_read_4(bst, bsh, RTK_TXCFG) &
    222  1.22   tsutsui 			    RTK_TXCFG_HWREV;
    223  1.22   tsutsui 			bus_space_unmap(bst, bsh, bsize);
    224   1.1  jonathan 			if (t->rtk_basetype == hwrev)
    225   1.1  jonathan 				return 2;	/* defeat rtk(4) */
    226   1.1  jonathan 		}
    227   1.1  jonathan 		t++;
    228   1.1  jonathan 	}
    229   1.1  jonathan 
    230   1.1  jonathan 	return 0;
    231   1.1  jonathan }
    232   1.1  jonathan 
    233   1.1  jonathan static void
    234  1.18  christos re_pci_attach(struct device *parent, struct device *self, void *aux)
    235   1.1  jonathan {
    236   1.1  jonathan 	struct re_pci_softc	*psc = (void *)self;
    237   1.1  jonathan 	struct rtk_softc	*sc = &psc->sc_rtk;
    238   1.1  jonathan 	struct pci_attach_args 	*pa = aux;
    239   1.1  jonathan 	pci_chipset_tag_t pc = pa->pa_pc;
    240   1.1  jonathan 	pci_intr_handle_t ih;
    241   1.1  jonathan 	const char *intrstr = NULL;
    242   1.6  jdolecek 	const struct rtk_type	*t;
    243   1.6  jdolecek 	const struct rtk_hwrev	*hw_rev;
    244  1.22   tsutsui 	uint32_t		hwrev;
    245   1.1  jonathan 	int			error = 0;
    246   1.3   kanaoka 	int			pmreg;
    247  1.22   tsutsui 	boolean_t		ioh_valid, memh_valid;
    248   1.1  jonathan 	pcireg_t		command;
    249  1.22   tsutsui 	bus_space_tag_t		iot, memt;
    250  1.22   tsutsui 	bus_space_handle_t	ioh, memh;
    251  1.22   tsutsui 	bus_size_t		iosize, memsize, bsize;
    252   1.1  jonathan 
    253   1.1  jonathan 
    254   1.1  jonathan 	/*
    255   1.1  jonathan 	 * Handle power management nonsense.
    256   1.1  jonathan 	 */
    257   1.3   kanaoka 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
    258   1.3   kanaoka 		command = pci_conf_read(pc, pa->pa_tag, pmreg + PCI_PMCSR);
    259  1.15   tsutsui 		if (command & PCI_PMCSR_STATE_MASK) {
    260   1.3   kanaoka 			u_int32_t		iobase, membase, irq;
    261   1.3   kanaoka 
    262   1.3   kanaoka 			/* Save important PCI config data. */
    263   1.3   kanaoka 			iobase = pci_conf_read(pc, pa->pa_tag, RTK_PCI_LOIO);
    264   1.3   kanaoka 			membase = pci_conf_read(pc, pa->pa_tag, RTK_PCI_LOMEM);
    265   1.3   kanaoka 			irq = pci_conf_read(pc, pa->pa_tag, PCI_INTERRUPT_REG);
    266   1.3   kanaoka 
    267   1.3   kanaoka 			/* Reset the power state. */
    268   1.3   kanaoka 			aprint_normal("%s: chip is is in D%d power mode "
    269   1.3   kanaoka 		    	    "-- setting to D0\n", sc->sc_dev.dv_xname,
    270  1.15   tsutsui 		    	    command & PCI_PMCSR_STATE_MASK);
    271   1.3   kanaoka 
    272  1.15   tsutsui 			command &= ~PCI_PMCSR_STATE_MASK;
    273   1.3   kanaoka 			pci_conf_write(pc, pa->pa_tag,
    274   1.3   kanaoka 			    pmreg + PCI_PMCSR, command);
    275   1.3   kanaoka 
    276   1.3   kanaoka 			/* Restore PCI config data. */
    277   1.3   kanaoka 			pci_conf_write(pc, pa->pa_tag, RTK_PCI_LOIO, iobase);
    278   1.3   kanaoka 			pci_conf_write(pc, pa->pa_tag, RTK_PCI_LOMEM, membase);
    279   1.3   kanaoka 			pci_conf_write(pc, pa->pa_tag, PCI_INTERRUPT_REG, irq);
    280   1.3   kanaoka 		}
    281   1.3   kanaoka 	}
    282   1.1  jonathan 
    283   1.1  jonathan 	/*
    284   1.1  jonathan 	 * Map control/status registers.
    285   1.1  jonathan 	 */
    286   1.1  jonathan 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    287   1.1  jonathan 	command |= PCI_COMMAND_MASTER_ENABLE;
    288   1.1  jonathan 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
    289   1.1  jonathan 
    290  1.22   tsutsui 	ioh_valid = (pci_mapreg_map(pa, RTK_PCI_LOIO, PCI_MAPREG_TYPE_IO, 0,
    291  1.22   tsutsui 	    &iot, &ioh, NULL, &iosize) == 0);
    292  1.22   tsutsui 	memh_valid = (pci_mapreg_map(pa, RTK_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
    293  1.22   tsutsui 	    &memt, &memh, NULL, &memsize) == 0);
    294  1.22   tsutsui 	if (ioh_valid) {
    295  1.22   tsutsui 		sc->rtk_btag = iot;
    296  1.22   tsutsui 		sc->rtk_bhandle = ioh;
    297  1.22   tsutsui 		bsize = iosize;
    298  1.22   tsutsui 	} else if (memh_valid) {
    299  1.22   tsutsui 		sc->rtk_btag = memt;
    300  1.22   tsutsui 		sc->rtk_bhandle = memh;
    301  1.22   tsutsui 		bsize = memsize;
    302  1.22   tsutsui 	} else {
    303  1.22   tsutsui 		aprint_error("%s: can't map registers\n", sc->sc_dev.dv_xname);
    304   1.2   kanaoka 		return;
    305   1.1  jonathan 	}
    306  1.22   tsutsui 
    307   1.1  jonathan 	t = re_devs;
    308   1.1  jonathan 	hwrev = CSR_READ_4(sc, RTK_TXCFG) & RTK_TXCFG_HWREV;
    309   1.1  jonathan 
    310   1.3   kanaoka 	while (t->rtk_name != NULL) {
    311   1.1  jonathan 		if ((PCI_VENDOR(pa->pa_id) == t->rtk_vid) &&
    312   1.1  jonathan 		    (PCI_PRODUCT(pa->pa_id) == t->rtk_did)) {
    313   1.1  jonathan 
    314   1.1  jonathan 			if (t->rtk_basetype == hwrev)
    315   1.1  jonathan 				break;
    316   1.1  jonathan 		}
    317   1.1  jonathan 		t++;
    318   1.1  jonathan 	}
    319   1.3   kanaoka 	aprint_normal(": %s\n", t->rtk_name);
    320   1.1  jonathan 
    321   1.1  jonathan 	hw_rev = re_hwrevs;
    322   1.1  jonathan 	hwrev = CSR_READ_4(sc, RTK_TXCFG) & RTK_TXCFG_HWREV;
    323   1.1  jonathan 	while (hw_rev->rtk_desc != NULL) {
    324   1.1  jonathan 		if (hw_rev->rtk_rev == hwrev) {
    325   1.1  jonathan 			sc->rtk_type = hw_rev->rtk_type;
    326   1.1  jonathan 			break;
    327   1.1  jonathan 		}
    328   1.1  jonathan 		hw_rev++;
    329   1.1  jonathan 	}
    330   1.1  jonathan 
    331   1.1  jonathan 	sc->sc_dmat = pa->pa_dmat;
    332   1.1  jonathan 
    333   1.1  jonathan 	/*
    334   1.1  jonathan 	 * No power/enable/disable machinery for PCI attac;
    335   1.1  jonathan 	 * mark the card enabled now.
    336   1.1  jonathan 	 */
    337   1.1  jonathan 	sc->sc_flags |= RTK_ENABLED;
    338   1.8     perry 
    339   1.1  jonathan 	/* Hook interrupt last to avoid having to lock softc */
    340   1.1  jonathan 	/* Allocate interrupt */
    341   1.1  jonathan 	if (pci_intr_map(pa, &ih)) {
    342   1.3   kanaoka 		aprint_error("%s: couldn't map interrupt\n",
    343   1.3   kanaoka 		    sc->sc_dev.dv_xname);
    344   1.2   kanaoka 		return;
    345   1.1  jonathan 	}
    346   1.1  jonathan 	intrstr = pci_intr_string(pc, ih);
    347   1.1  jonathan 	psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, re_intr, sc);
    348   1.1  jonathan 	if (psc->sc_ih == NULL) {
    349   1.3   kanaoka 		aprint_error("%s: couldn't establish interrupt",
    350   1.1  jonathan 		    sc->sc_dev.dv_xname);
    351   1.1  jonathan 		if (intrstr != NULL)
    352   1.3   kanaoka 			aprint_error(" at %s", intrstr);
    353   1.3   kanaoka 		aprint_error("\n");
    354   1.1  jonathan 		return;
    355   1.1  jonathan 	}
    356   1.1  jonathan 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    357   1.1  jonathan 
    358   1.2   kanaoka 	re_attach(sc);
    359   1.2   kanaoka 
    360   1.2   kanaoka 	/*
    361  1.17   tsutsui 	 * Perform hardware diagnostic on the original RTL8169.
    362  1.17   tsutsui 	 * Some 32-bit cards were incorrectly wired and would
    363  1.17   tsutsui 	 * malfunction if plugged into a 64-bit slot.
    364   1.2   kanaoka 	 */
    365  1.17   tsutsui 	if (hwrev == RTK_HWREV_8169) {
    366  1.17   tsutsui 		error = re_diag(sc);
    367  1.17   tsutsui 		if (error) {
    368  1.17   tsutsui 			aprint_error(
    369  1.17   tsutsui 			    "%s: attach aborted due to hardware diag failure\n",
    370  1.17   tsutsui 			    sc->sc_dev.dv_xname);
    371  1.17   tsutsui 
    372  1.17   tsutsui 			re_detach(sc);
    373  1.17   tsutsui 
    374  1.17   tsutsui 			if (psc->sc_ih != NULL) {
    375  1.17   tsutsui 				pci_intr_disestablish(pc, psc->sc_ih);
    376  1.17   tsutsui 				psc->sc_ih = NULL;
    377  1.17   tsutsui 			}
    378   1.2   kanaoka 
    379  1.17   tsutsui 			if (bsize)
    380  1.17   tsutsui 				bus_space_unmap(sc->rtk_btag, sc->rtk_bhandle,
    381  1.17   tsutsui 				    bsize);
    382   1.2   kanaoka 		}
    383   1.2   kanaoka 	}
    384   1.1  jonathan }
    385