1/* $OpenBSD: if_sm_isa.c,v 1.17 2023/09/11 08:41:26 mvs 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 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * 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/timeout.h> 44#include <sys/device.h> 45 46#include <net/if.h> 47#include <net/if_media.h> 48 49#include <netinet/in.h> 50#include <netinet/if_ether.h> 51 52#if NBPFILTER > 0 53#include <net/bpf.h> 54#endif 55 56#include <machine/intr.h> 57#include <machine/bus.h> 58 59#include <dev/mii/mii.h> 60#include <dev/mii/miivar.h> 61 62#include <dev/ic/smc91cxxreg.h> 63#include <dev/ic/smc91cxxvar.h> 64 65#include <dev/isa/isavar.h> 66 67int sm_isa_match(struct device *, void *, void *); 68void sm_isa_attach(struct device *, struct device *, void *); 69 70struct sm_isa_softc { 71 struct smc91cxx_softc sc_smc; /* real "smc" softc */ 72 73 /* ISA-specific goo. */ 74 void *sc_ih; /* interrupt cookie */ 75}; 76 77const struct cfattach sm_isa_ca = { 78 sizeof(struct sm_isa_softc), sm_isa_match, sm_isa_attach 79}; 80 81int 82sm_isa_match(struct device *parent, void *match, void *aux) 83{ 84 struct isa_attach_args *ia = aux; 85 bus_space_tag_t iot = ia->ia_iot; 86 bus_space_handle_t ioh; 87 u_int16_t tmp; 88 int rv = 0; 89 extern const char *smc91cxx_idstrs[]; 90 91 /* Disallow wildcarded values. */ 92 if (ia->ia_irq == -1) 93 return (0); 94 if (ia->ia_iobase == -1) 95 return (0); 96 97 /* Map i/o space. */ 98 if (bus_space_map(iot, ia->ia_iobase, SMC_IOSIZE, 0, &ioh)) 99 return (0); 100 101 /* Check that high byte of BANK_SELECT is what we expect. */ 102 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W); 103 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) 104 goto out; 105 106 /* 107 * Switch to bank 0 and perform the test again. 108 * XXX INVASIVE! 109 */ 110 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0); 111 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W); 112 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) 113 goto out; 114 115 /* 116 * Switch to bank 1 and check the base address register. 117 * XXX INVASIVE! 118 */ 119 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1); 120 tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W); 121 if (ia->ia_iobase != ((tmp >> 3) & 0x3e0)) 122 goto out; 123 124 /* 125 * Check for a recognized chip id. 126 * XXX INVASIVE! 127 */ 128 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3); 129 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W); 130 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL) 131 goto out; 132 133 /* 134 * Assume we have an SMC91Cxx. 135 */ 136 ia->ia_iosize = SMC_IOSIZE; 137 rv = 1; 138 139 out: 140 bus_space_unmap(iot, ioh, SMC_IOSIZE); 141 return (rv); 142} 143 144void 145sm_isa_attach(struct device *parent, struct device *self, void *aux) 146{ 147 struct sm_isa_softc *isc = (struct sm_isa_softc *)self; 148 struct smc91cxx_softc *sc = &isc->sc_smc; 149 struct isa_attach_args *ia = aux; 150 bus_space_tag_t iot = ia->ia_iot; 151 bus_space_handle_t ioh; 152 153 printf("\n"); 154 155 /* Map i/o space. */ 156 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) 157 panic("sm_isa_attach: can't map i/o space"); 158 159 sc->sc_bst = iot; 160 sc->sc_bsh = ioh; 161 162 /* should always be enabled */ 163 sc->sc_enabled = 1; 164 165 /* XXX Should get Ethernet address from EEPROM!! */ 166 167 /* Perform generic initialization. */ 168 smc91cxx_attach(sc, NULL); 169 170 /* Establish the interrupt handler. */ 171 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 172 IPL_NET, smc91cxx_intr, sc, sc->sc_dev.dv_xname); 173 if (isc->sc_ih == NULL) 174 printf("%s: couldn't establish interrupt handler\n", 175 sc->sc_dev.dv_xname); 176} 177