1 /* $OpenBSD: if_ep_pci.c,v 1.18 1998/09/19 10:08:06 maja Exp $ */ 2 /* $NetBSD: if_ep_pci.c,v 1.13 1996/10/21 22:56:38 thorpej Exp $ */ 3 4 /* 5 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org> 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. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Herb Peyerl. 19 * 4. The name of Herb Peyerl may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "bpfilter.h" 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/mbuf.h> 39 #include <sys/socket.h> 40 #include <sys/ioctl.h> 41 #include <sys/errno.h> 42 #include <sys/syslog.h> 43 #include <sys/select.h> 44 #include <sys/device.h> 45 46 #include <net/if.h> 47 #include <net/if_dl.h> 48 #include <net/if_types.h> 49 #include <net/if_media.h> 50 51 #ifdef INET 52 #include <netinet/in.h> 53 #include <netinet/in_systm.h> 54 #include <netinet/in_var.h> 55 #include <netinet/ip.h> 56 #include <netinet/if_ether.h> 57 #endif 58 59 #if NBPFILTER > 0 60 #include <net/bpf.h> 61 #include <net/bpfdesc.h> 62 #endif 63 64 #include <machine/cpu.h> 65 #include <machine/bus.h> 66 #include <machine/intr.h> 67 68 #include <dev/ic/elink3var.h> 69 #include <dev/ic/elink3reg.h> 70 71 #include <dev/pci/pcivar.h> 72 #include <dev/pci/pcireg.h> 73 #include <dev/pci/pcidevs.h> 74 75 /* 76 * PCI constants. 77 * XXX These should be in a common file! 78 */ 79 #define PCI_CONN 0x48 /* Connector type */ 80 #define PCI_CBIO 0x10 /* Configuration Base IO Address */ 81 82 int ep_pci_match __P((struct device *, void *, void *)); 83 void ep_pci_attach __P((struct device *, struct device *, void *)); 84 85 struct cfattach ep_pci_ca = { 86 sizeof(struct ep_softc), ep_pci_match, ep_pci_attach 87 }; 88 89 int 90 ep_pci_match(parent, match, aux) 91 struct device *parent; 92 void *match, *aux; 93 { 94 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 95 96 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM) 97 return 0; 98 99 switch (PCI_PRODUCT(pa->pa_id)) { 100 case PCI_PRODUCT_3COM_3C590: 101 case PCI_PRODUCT_3COM_3C595MII: 102 case PCI_PRODUCT_3COM_3C595T4: 103 case PCI_PRODUCT_3COM_3C595TX: 104 break; 105 default: 106 return 0; 107 } 108 109 return 1; 110 } 111 112 void 113 ep_pci_attach(parent, self, aux) 114 struct device *parent, *self; 115 void *aux; 116 { 117 struct ep_softc *sc = (void *)self; 118 struct pci_attach_args *pa = aux; 119 pci_chipset_tag_t pc = pa->pa_pc; 120 bus_space_tag_t iot = pa->pa_iot; 121 bus_addr_t iobase; 122 bus_size_t iosize; 123 pci_intr_handle_t ih; 124 pcireg_t i; 125 const char *intrstr = NULL; 126 127 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)) { 128 printf(": can't find i/o space\n"); 129 return; 130 } 131 132 if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_ioh)) { 133 printf(": can't map i/o space\n"); 134 return; 135 } 136 137 sc->sc_iot = iot; 138 sc->bustype = EP_BUS_PCI; 139 140 i = pci_conf_read(pc, pa->pa_tag, PCI_CONN); 141 142 GO_WINDOW(0); 143 144 printf(":"); 145 146 epconfig(sc, EP_CHIPSET_VORTEX, NULL); 147 148 /* Enable the card. */ 149 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 150 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 151 PCI_COMMAND_MASTER_ENABLE); 152 153 /* Map and establish the interrupt. */ 154 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 155 pa->pa_intrline, &ih)) { 156 printf(", couldn't map interrupt\n"); 157 return; 158 } 159 intrstr = pci_intr_string(pc, ih); 160 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, 161 sc, sc->sc_dev.dv_xname); 162 if (sc->sc_ih == NULL) { 163 printf(": couldn't establish interrupt"); 164 if (intrstr != NULL) 165 printf(" at %s", intrstr); 166 printf("\n"); 167 return; 168 } 169 printf(" %s\n", intrstr); 170 } 171