1 /* $OpenBSD: if_hme_pci.c,v 1.2 2001/08/23 03:44:46 jason Exp $ */ 2 /* $NetBSD: if_hme_pci.c,v 1.3 2000/12/28 22:59:13 sommerfeld Exp $ */ 3 4 /* 5 * Copyright (c) 2000 Matthew R. Green 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * PCI front-end device driver for the HME ethernet device. 34 */ 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/syslog.h> 39 #include <sys/device.h> 40 #include <sys/malloc.h> 41 #include <sys/socket.h> 42 43 #include <net/if.h> 44 #include <net/if_dl.h> 45 #include <net/if_media.h> 46 47 #ifdef INET 48 #include <netinet/in.h> 49 #include <netinet/in_systm.h> 50 #include <netinet/in_var.h> 51 #include <netinet/ip.h> 52 #include <netinet/if_ether.h> 53 #endif 54 55 #include <dev/mii/mii.h> 56 #include <dev/mii/miivar.h> 57 58 #ifdef __sparc64__ 59 #include <machine/autoconf.h> 60 #endif 61 #include <machine/cpu.h> 62 63 #include <dev/pci/pcivar.h> 64 #include <dev/pci/pcireg.h> 65 #include <dev/pci/pcidevs.h> 66 67 #include <dev/ic/hmevar.h> 68 69 struct hme_pci_softc { 70 struct hme_softc hsc_hme; /* HME device */ 71 bus_space_tag_t hsc_memt; 72 bus_space_handle_t hsc_memh; 73 void *hsc_ih; 74 }; 75 76 int hmematch_pci __P((struct device *, void *, void *)); 77 void hmeattach_pci __P((struct device *, struct device *, void *)); 78 79 struct cfattach hme_pci_ca = { 80 sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci 81 }; 82 83 int 84 hmematch_pci(parent, vcf, aux) 85 struct device *parent; 86 void *vcf; 87 void *aux; 88 { 89 struct pci_attach_args *pa = aux; 90 91 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN && 92 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HME) 93 return (1); 94 95 return (0); 96 } 97 98 void 99 hmeattach_pci(parent, self, aux) 100 struct device *parent, *self; 101 void *aux; 102 { 103 struct pci_attach_args *pa = aux; 104 struct hme_pci_softc *hsc = (void *)self; 105 struct hme_softc *sc = &hsc->hsc_hme; 106 pci_intr_handle_t intrhandle; 107 /* XXX the following declarations should be elsewhere */ 108 extern void myetheraddr __P((u_char *)); 109 pcireg_t csr; 110 const char *intrstr; 111 int type; 112 113 /* 114 * enable io/memory-space accesses. this is kinda of gross; but 115 * the hme comes up with neither IO space enabled, or memory space. 116 */ 117 if (pa->pa_memt) 118 pa->pa_flags |= PCI_FLAGS_MEM_ENABLED; 119 if (pa->pa_iot) 120 pa->pa_flags |= PCI_FLAGS_IO_ENABLED; 121 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 122 if (pa->pa_memt) { 123 type = PCI_MAPREG_TYPE_MEM; 124 csr |= PCI_COMMAND_MEM_ENABLE; 125 sc->sc_bustag = pa->pa_memt; 126 } else { 127 type = PCI_MAPREG_TYPE_IO; 128 csr |= PCI_COMMAND_IO_ENABLE; 129 sc->sc_bustag = pa->pa_iot; 130 } 131 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 132 csr | PCI_COMMAND_MEM_ENABLE); 133 134 sc->sc_dmatag = pa->pa_dmat; 135 136 sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */ 137 /* 138 * Map five register banks: 139 * 140 * bank 0: HME SEB registers: +0x0000 141 * bank 1: HME ETX registers: +0x2000 142 * bank 2: HME ERX registers: +0x4000 143 * bank 3: HME MAC registers: +0x6000 144 * bank 4: HME MIF registers: +0x7000 145 * 146 */ 147 148 #define PCI_HME_BASEADDR 0x10 149 if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0, 150 &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL, 0) != 0) 151 { 152 printf(": could not map hme registers\n"); 153 return; 154 } 155 sc->sc_seb = hsc->hsc_memh; 156 sc->sc_etx = hsc->hsc_memh + 0x2000; 157 sc->sc_erx = hsc->hsc_memh + 0x4000; 158 sc->sc_mac = hsc->hsc_memh + 0x6000; 159 sc->sc_mif = hsc->hsc_memh + 0x7000; 160 161 myetheraddr(sc->sc_enaddr); 162 163 sc->sc_burst = 16; /* XXX */ 164 165 /* 166 * call the main configure 167 */ 168 hme_config(sc); 169 170 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, 171 pa->pa_intrline, &intrhandle) != 0) { 172 printf("%s: couldn't map interrupt\n", 173 sc->sc_dev.dv_xname); 174 return; /* bus_unmap ? */ 175 } 176 intrstr = pci_intr_string(pa->pa_pc, intrhandle); 177 hsc->hsc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, 178 hme_intr, sc, self->dv_xname); 179 if (hsc->hsc_ih != NULL) { 180 printf("%s: using %s for interrupt\n", 181 sc->sc_dev.dv_xname, 182 intrstr ? intrstr : "unknown interrupt"); 183 } else { 184 printf("%s: couldn't establish interrupt", 185 sc->sc_dev.dv_xname); 186 if (intrstr != NULL) 187 printf(" at %s", intrstr); 188 printf("\n"); 189 return; /* bus_unmap ? */ 190 } 191 } 192