root/dev/isa/if_sm_isa.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sm_isa_match
  2. sm_isa_attach

    1 /*      $OpenBSD: if_sm_isa.c,v 1.9 2006/06/17 17:57:00 brad 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/selinfo.h>
   51 #include <sys/timeout.h>
   52 #include <sys/device.h>
   53 
   54 #include <net/if.h>
   55 #include <net/if_dl.h>
   56 #include <net/if_media.h>
   57 
   58 #ifdef INET
   59 #include <netinet/in.h>
   60 #include <netinet/in_systm.h>
   61 #include <netinet/in_var.h>
   62 #include <netinet/ip.h>
   63 #include <netinet/if_ether.h>
   64 #endif
   65 
   66 #if NBPFILTER > 0
   67 #include <net/bpf.h>
   68 #endif
   69 
   70 #include <machine/intr.h>
   71 #include <machine/bus.h>
   72 
   73 #include <net/if_media.h>
   74 
   75 #include <dev/mii/mii.h>
   76 #include <dev/mii/miivar.h>
   77 
   78 #include <dev/ic/smc91cxxreg.h>
   79 #include <dev/ic/smc91cxxvar.h>
   80 
   81 #include <dev/isa/isavar.h>
   82 
   83 int     sm_isa_match(struct device *, void *, void *);
   84 void    sm_isa_attach(struct device *, struct device *, void *);
   85 
   86 struct sm_isa_softc {
   87         struct  smc91cxx_softc sc_smc;          /* real "smc" softc */
   88 
   89         /* ISA-specific goo. */
   90         void    *sc_ih;                         /* interrupt cookie */
   91 };
   92 
   93 struct cfattach sm_isa_ca = {
   94         sizeof(struct sm_isa_softc), sm_isa_match, sm_isa_attach
   95 };
   96 
   97 int
   98 sm_isa_match(parent, match, aux)
   99         struct device *parent;
  100         void *match, *aux;
  101 {
  102         struct isa_attach_args *ia = aux;
  103         bus_space_tag_t iot = ia->ia_iot;
  104         bus_space_handle_t ioh;
  105         u_int16_t tmp;
  106         int rv = 0;
  107         extern const char *smc91cxx_idstrs[];
  108 
  109         /* Disallow wildcarded values. */
  110         if (ia->ia_irq == -1)
  111                 return (0);
  112         if (ia->ia_iobase == -1)
  113                 return (0);
  114 
  115         /* Map i/o space. */
  116         if (bus_space_map(iot, ia->ia_iobase, SMC_IOSIZE, 0, &ioh))
  117                 return (0);
  118 
  119         /* Check that high byte of BANK_SELECT is what we expect. */
  120         tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
  121         if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
  122                 goto out;
  123 
  124         /*
  125          * Switch to bank 0 and perform the test again.
  126          * XXX INVASIVE!
  127          */
  128         bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
  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 1 and check the base address register.
  135          * XXX INVASIVE!
  136          */
  137         bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
  138         tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
  139         if (ia->ia_iobase != ((tmp >> 3) & 0x3e0))
  140                 goto out;
  141 
  142         /*
  143          * Check for a recognized chip id.
  144          * XXX INVASIVE!
  145          */
  146         bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
  147         tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
  148         if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
  149                 goto out;
  150 
  151         /*
  152          * Assume we have an SMC91Cxx.
  153          */
  154         ia->ia_iosize = SMC_IOSIZE;
  155         rv = 1;
  156 
  157  out:
  158         bus_space_unmap(iot, ioh, SMC_IOSIZE);
  159         return (rv);
  160 }
  161 
  162 void
  163 sm_isa_attach(parent, self, aux)
  164         struct device *parent, *self;
  165         void *aux;
  166 {
  167         struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
  168         struct smc91cxx_softc *sc = &isc->sc_smc;
  169         struct isa_attach_args *ia = aux;
  170         bus_space_tag_t iot = ia->ia_iot;
  171         bus_space_handle_t ioh;
  172 
  173         printf("\n");
  174 
  175         /* Map i/o space. */
  176         if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh))
  177                 panic("sm_isa_attach: can't map i/o space");
  178 
  179         sc->sc_bst = iot;
  180         sc->sc_bsh = ioh;
  181 
  182         /* should always be enabled */
  183         sc->sc_enabled = 1;
  184 
  185         /* XXX Should get Ethernet address from EEPROM!! */
  186 
  187         /* Perform generic initialization. */
  188         smc91cxx_attach(sc, NULL);
  189 
  190         /* Establish the interrupt handler. */
  191         isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  192             IPL_NET, smc91cxx_intr, sc, sc->sc_dev.dv_xname);
  193         if (isc->sc_ih == NULL)
  194                 printf("%s: couldn't establish interrupt handler\n",
  195                     sc->sc_dev.dv_xname);
  196 }

/* [<][>][^][v][top][bottom][index][help] */