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