1 /* $OpenBSD: if_pgt_pci.c,v 1.11 2009/06/02 04:03:39 jsg Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Marcus Glocker <mglocker@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* 20 * PCI front-end for the PrismGT 21 */ 22 23 #include "bpfilter.h" 24 25 #include <sys/param.h> 26 #include <sys/sockio.h> 27 #include <sys/mbuf.h> 28 #include <sys/kernel.h> 29 #include <sys/socket.h> 30 #include <sys/systm.h> 31 #include <sys/malloc.h> 32 #include <sys/timeout.h> 33 #include <sys/device.h> 34 35 #include <machine/bus.h> 36 #include <machine/intr.h> 37 38 #include <net/if.h> 39 #include <net/if_dl.h> 40 #include <net/if_media.h> 41 42 #include <netinet/in.h> 43 #include <netinet/if_ether.h> 44 45 #include <net80211/ieee80211_var.h> 46 #include <net80211/ieee80211_radiotap.h> 47 48 #include <dev/ic/pgtreg.h> 49 #include <dev/ic/pgtvar.h> 50 51 #include <dev/pci/pcireg.h> 52 #include <dev/pci/pcivar.h> 53 #include <dev/pci/pcidevs.h> 54 55 /* Base Address Register */ 56 #define PGT_PCI_BAR0 0x10 57 58 int pgt_pci_match(struct device *, void *, void *); 59 void pgt_pci_attach(struct device *, struct device *, void *); 60 int pgt_pci_detach(struct device *, int); 61 62 struct pgt_pci_softc { 63 struct pgt_softc sc_pgt; 64 65 pci_chipset_tag_t sc_pc; 66 void *sc_ih; 67 bus_size_t sc_mapsize; 68 }; 69 70 struct cfattach pgt_pci_ca = { 71 sizeof(struct pgt_pci_softc), pgt_pci_match, pgt_pci_attach, 72 pgt_pci_detach 73 }; 74 75 const struct pci_matchid pgt_pci_devices[] = { 76 { PCI_VENDOR_INTERSIL, PCI_PRODUCT_INTERSIL_ISL3877 }, 77 { PCI_VENDOR_INTERSIL, PCI_PRODUCT_INTERSIL_ISL3890 }, 78 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CRWE154G72 } 79 }; 80 81 int 82 pgt_pci_match(struct device *parent, void *match, void *aux) 83 { 84 return (pci_matchbyid((struct pci_attach_args *)aux, pgt_pci_devices, 85 sizeof(pgt_pci_devices) / sizeof(pgt_pci_devices[0]))); 86 } 87 88 void 89 pgt_pci_attach(struct device *parent, struct device *self, void *aux) 90 { 91 struct pgt_pci_softc *psc = (struct pgt_pci_softc *)self; 92 struct pgt_softc *sc = &psc->sc_pgt; 93 struct pci_attach_args *pa = aux; 94 const char *intrstr = NULL; 95 pci_intr_handle_t ih; 96 int error; 97 98 sc->sc_dmat = pa->pa_dmat; 99 psc->sc_pc = pa->pa_pc; 100 101 /* remember chipset */ 102 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTERSIL_ISL3877) 103 sc->sc_flags |= SC_ISL3877; 104 105 /* map control / status registers */ 106 error = pci_mapreg_map(pa, PGT_PCI_BAR0, 107 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, 108 &sc->sc_iotag, &sc->sc_iohandle, NULL, &psc->sc_mapsize, 0); 109 if (error != 0) { 110 printf(": can't map mem space\n"); 111 return; 112 } 113 114 /* map interrupt */ 115 if (pci_intr_map(pa, &ih) != 0) { 116 printf(": can't map interrupt\n"); 117 return; 118 } 119 120 /* disable all interrupts */ 121 bus_space_write_4(sc->sc_iotag, sc->sc_iohandle, PGT_REG_INT_EN, 0); 122 (void)bus_space_read_4(sc->sc_iotag, sc->sc_iohandle, PGT_REG_INT_EN); 123 DELAY(PGT_WRITEIO_DELAY); 124 125 /* establish interrupt */ 126 intrstr = pci_intr_string(psc->sc_pc, ih); 127 psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET, pgt_intr, sc, 128 sc->sc_dev.dv_xname); 129 if (psc->sc_ih == NULL) { 130 printf(": can't establish interrupt"); 131 if (intrstr != NULL) 132 printf(" at %s", intrstr); 133 printf("\n"); 134 return; 135 } 136 printf(": %s\n", intrstr); 137 138 if (rootvp == NULL) 139 mountroothook_establish(pgt_attach, sc); 140 else 141 pgt_attach(sc); 142 } 143 144 int 145 pgt_pci_detach(struct device *self, int flags) 146 { 147 struct pgt_pci_softc *psc = (struct pgt_pci_softc *)self; 148 struct pgt_softc *sc = &psc->sc_pgt; 149 150 pgt_detach(sc); 151 pci_intr_disestablish(psc->sc_pc, psc->sc_ih); 152 153 return (0); 154 } 155