Home | History | Annotate | Line # | Download | only in eisa
depca_eisa.c revision 1.1
      1 /*	$NetBSD: depca_eisa.c,v 1.1 2000/08/11 02:27:07 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 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.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * EISA bus front-end for the Digital DEPCA Ethernet controller.
     41  */
     42 
     43 #include "opt_inet.h"
     44 #include "bpfilter.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/mbuf.h>
     49 #include <sys/syslog.h>
     50 #include <sys/socket.h>
     51 #include <sys/device.h>
     52 
     53 #include <net/if.h>
     54 #include <net/if_media.h>
     55 #include <net/if_ether.h>
     56 
     57 #ifdef INET
     58 #include <netinet/in.h>
     59 #include <netinet/if_inarp.h>
     60 #endif
     61 
     62 #include <machine/bus.h>
     63 #include <machine/intr.h>
     64 
     65 #include <dev/eisa/eisareg.h>
     66 #include <dev/eisa/eisavar.h>
     67 #include <dev/eisa/eisadevs.h>
     68 
     69 #include <dev/ic/lancereg.h>
     70 #include <dev/ic/lancevar.h>
     71 #include <dev/ic/am7990reg.h>
     72 #include <dev/ic/am7990var.h>
     73 #include <dev/ic/depcareg.h>
     74 #include <dev/ic/depcavar.h>
     75 
     76 int	depca_eisa_match(struct device *, struct cfdata *, void *);
     77 void	depca_eisa_attach(struct device *, struct device *, void *);
     78 
     79 struct depca_eisa_softc {
     80 	struct depca_softc sc_depca;
     81 
     82 	eisa_chipset_tag_t sc_ec;
     83 	int sc_irq;
     84 	int sc_ist;
     85 };
     86 
     87 struct cfattach depca_eisa_ca = {
     88 	sizeof(struct depca_eisa_softc), depca_eisa_match, depca_eisa_attach,
     89 };
     90 
     91 void	*depca_eisa_intr_establish(struct depca_softc *, struct lance_softc *);
     92 
     93 int
     94 depca_eisa_match(struct device *parent, struct cfdata *match, void *aux)
     95 {
     96 	struct eisa_attach_args *ea = aux;
     97 
     98 	return (strcmp(ea->ea_idstring, "DEC4220") == 0);
     99 }
    100 
    101 #define	DEPCA_ECU_FUNC_NETINTR	0
    102 #define	DEPCA_ECU_FUNC_NETBUF	1
    103 
    104 void
    105 depca_eisa_attach(struct device *parent, struct device *self, void *aux)
    106 {
    107 	struct depca_softc *sc = (void *) self;
    108 	struct depca_eisa_softc *esc = (void *) self;
    109 	struct eisa_attach_args *ea = aux;
    110 	struct eisa_cfg_mem ecm;
    111 	struct eisa_cfg_irq eci;
    112 
    113 	printf(": DEC DE422 Ethernet\n");
    114 
    115 	sc->sc_iot = ea->ea_iot;
    116 	sc->sc_memt = ea->ea_memt;
    117 
    118 	esc->sc_ec = ea->ea_ec;
    119 
    120 	sc->sc_intr_establish = depca_eisa_intr_establish;
    121 
    122 	if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot,
    123 	    DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) {
    124 		printf("%s: unable to find network buffer\n",
    125 		    sc->sc_dev.dv_xname);
    126 		return;
    127 	}
    128 
    129 	printf("%s: shared memory at 0x%lx-0x%lx\n", sc->sc_dev.dv_xname,
    130 	    ecm.ecm_addr, ecm.ecm_addr + ecm.ecm_size - 1);
    131 
    132 	sc->sc_memsize = ecm.ecm_size;
    133 
    134 	if (bus_space_map(sc->sc_iot, EISA_SLOT_ADDR(ea->ea_slot) + 0xc00, 16,
    135 	    0, &sc->sc_ioh) != 0) {
    136 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
    137 		return;
    138 	}
    139 	if (bus_space_map(sc->sc_memt, ecm.ecm_addr, sc->sc_memsize,
    140 	    0, &sc->sc_memh) != 0) {
    141 		printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname);
    142 		return;
    143 	}
    144 
    145 	if (eisa_conf_read_irq(ea->ea_ec, ea->ea_slot,
    146 	    DEPCA_ECU_FUNC_NETINTR, 0, &eci) != 0) {
    147 		printf("%s: unable to determine IRQ\n",
    148 		    sc->sc_dev.dv_xname);
    149 		return;
    150 	}
    151 
    152 	esc->sc_irq = eci.eci_irq;
    153 	esc->sc_ist = eci.eci_ist;
    154 
    155 	depca_attach(sc);
    156 }
    157 
    158 void *
    159 depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
    160 {
    161 	struct depca_eisa_softc *esc = (void *) parent;
    162 	eisa_intr_handle_t ih;
    163 	const char *intrstr;
    164 	void *rv;
    165 
    166 	if (eisa_intr_map(esc->sc_ec, esc->sc_irq, &ih)) {
    167 		printf("%s: unable to map interrupt (%d)\n",
    168 		    parent->sc_dev.dv_xname, esc->sc_irq);
    169 		return (NULL);
    170 	}
    171 	intrstr = eisa_intr_string(esc->sc_ec, ih);
    172 	rv = eisa_intr_establish(esc->sc_ec, ih, esc->sc_ist, IPL_NET,
    173 	    (esc->sc_ist == IST_LEVEL) ? am7990_intr : depca_intredge, child);
    174 	if (rv == NULL) {
    175 		printf("%s: unable to establish interrupt",
    176 		    parent->sc_dev.dv_xname);
    177 		if (intrstr != NULL)
    178 			printf(" at %s", intrstr);
    179 		printf("\n");
    180 		return (NULL);
    181 	}
    182 	if (intrstr != NULL)
    183 		printf("%s: interrupting at %s\n", parent->sc_dev.dv_xname,
    184 		    intrstr);
    185 
    186 	return (rv);
    187 }
    188