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