1 /* $OpenBSD: if_sm_isa.c,v 1.1 1998/09/26 19:09:15 fgsch Exp $ */ 2 /* $NetBSD: if_sm_isa.c,v 1.4 1998/07/05 06:49:14 jonathan Exp $ */ 3 4 /*- 5 * Copyright (c) 1997 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 10 * NASA Ames Research Center. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the NetBSD 23 * Foundation, Inc. and its contributors. 24 * 4. Neither the name of The NetBSD Foundation nor the names of its 25 * contributors may be used to endorse or promote products derived 26 * from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41 #include "bpfilter.h" 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/mbuf.h> 46 #include <sys/socket.h> 47 #include <sys/ioctl.h> 48 #include <sys/errno.h> 49 #include <sys/syslog.h> 50 #include <sys/select.h> 51 #include <sys/device.h> 52 53 #include <net/if.h> 54 #include <net/if_dl.h> 55 #ifdef __NetBSD__ 56 #include <net/if_ether.h> 57 #endif 58 #include <net/if_media.h> 59 60 #ifdef INET 61 #include <netinet/in.h> 62 #include <netinet/in_systm.h> 63 #include <netinet/in_var.h> 64 #include <netinet/ip.h> 65 #ifdef __NetBSD__ 66 #include <netinet/if_inarp.h> 67 #else 68 #include <netinet/if_ether.h> 69 #endif 70 #endif 71 72 #ifdef NS 73 #include <netns/ns.h> 74 #include <netns/ns_if.h> 75 #endif 76 77 #if NBPFILTER > 0 78 #include <net/bpf.h> 79 #include <net/bpfdesc.h> 80 #endif 81 82 #include <machine/intr.h> 83 #include <machine/bus.h> 84 85 #include <dev/ic/smc91cxxreg.h> 86 #include <dev/ic/smc91cxxvar.h> 87 88 #include <dev/isa/isavar.h> 89 90 int sm_isa_match __P((struct device *, void *, void *)); 91 void sm_isa_attach __P((struct device *, struct device *, void *)); 92 93 struct sm_isa_softc { 94 struct smc91cxx_softc sc_smc; /* real "smc" softc */ 95 96 /* ISA-specific goo. */ 97 void *sc_ih; /* interrupt cookie */ 98 }; 99 100 struct cfattach sm_isa_ca = { 101 sizeof(struct sm_isa_softc), sm_isa_match, sm_isa_attach 102 }; 103 104 int 105 sm_isa_match(parent, match, aux) 106 struct device *parent; 107 void *match, *aux; 108 { 109 struct isa_attach_args *ia = aux; 110 bus_space_tag_t iot = ia->ia_iot; 111 bus_space_handle_t ioh; 112 u_int16_t tmp; 113 int rv = 0; 114 extern const char *smc91cxx_idstrs[]; 115 116 /* Disallow wildcarded values. */ 117 if (ia->ia_irq == -1) 118 return (0); 119 if (ia->ia_iobase == -1) 120 return (0); 121 122 /* Map i/o space. */ 123 if (bus_space_map(iot, ia->ia_iobase, SMC_IOSIZE, 0, &ioh)) 124 return (0); 125 126 /* Check that high byte of BANK_SELECT is what we expect. */ 127 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W); 128 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) 129 goto out; 130 131 /* 132 * Switch to bank 0 and perform the test again. 133 * XXX INVASIVE! 134 */ 135 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0); 136 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W); 137 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) 138 goto out; 139 140 /* 141 * Switch to bank 1 and check the base address register. 142 * XXX INVASIVE! 143 */ 144 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1); 145 tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W); 146 if (ia->ia_iobase != ((tmp >> 3) & 0x3e0)) 147 goto out; 148 149 /* 150 * Check for a recognized chip id. 151 * XXX INVASIVE! 152 */ 153 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3); 154 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W); 155 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL) 156 goto out; 157 158 /* 159 * Assume we have an SMC91Cxx. 160 */ 161 ia->ia_iosize = SMC_IOSIZE; 162 rv = 1; 163 164 out: 165 bus_space_unmap(iot, ioh, SMC_IOSIZE); 166 return (rv); 167 } 168 169 void 170 sm_isa_attach(parent, self, aux) 171 struct device *parent, *self; 172 void *aux; 173 { 174 struct sm_isa_softc *isc = (struct sm_isa_softc *)self; 175 struct smc91cxx_softc *sc = &isc->sc_smc; 176 struct isa_attach_args *ia = aux; 177 bus_space_tag_t iot = ia->ia_iot; 178 bus_space_handle_t ioh; 179 180 printf("\n"); 181 182 /* Map i/o space. */ 183 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) 184 panic("sm_isa_attach: can't map i/o space"); 185 186 sc->sc_bst = iot; 187 sc->sc_bsh = ioh; 188 189 /* should always be enabled */ 190 sc->sc_enabled = 1; 191 192 /* XXX Should get Ethernet address from EEPROM!! */ 193 194 /* Perform generic intialization. */ 195 smc91cxx_attach(sc, NULL); 196 197 /* Establish the interrupt handler. */ 198 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 199 IPL_NET, smc91cxx_intr, sc, sc->sc_dev.dv_xname); 200 if (isc->sc_ih == NULL) 201 printf("%s: couldn't establish interrupt handler\n", 202 sc->sc_dev.dv_xname); 203 } 204