Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.3
      1  1.3   thorpej /*	$NetBSD: if_le.c,v 1.3 2002/10/02 05:06:54 thorpej Exp $	*/
      2  1.1  drochner 
      3  1.1  drochner /*
      4  1.1  drochner  * Copyright (c) 1997, 1999
      5  1.1  drochner  *	Matthias Drochner.  All rights reserved.
      6  1.1  drochner  *
      7  1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8  1.1  drochner  * modification, are permitted provided that the following conditions
      9  1.1  drochner  * are met:
     10  1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11  1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     12  1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15  1.1  drochner  *
     16  1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  drochner  *
     27  1.1  drochner  */
     28  1.1  drochner 
     29  1.1  drochner #include "opt_inet.h"
     30  1.1  drochner 
     31  1.1  drochner #include <sys/param.h>
     32  1.1  drochner #include <sys/systm.h>
     33  1.1  drochner #include <sys/socket.h>
     34  1.1  drochner #include <sys/device.h>
     35  1.1  drochner 
     36  1.1  drochner #include <net/if.h>
     37  1.1  drochner #include <net/if_ether.h>
     38  1.1  drochner #include <net/if_media.h>
     39  1.1  drochner 
     40  1.1  drochner #ifdef INET
     41  1.1  drochner #include <netinet/in.h>
     42  1.1  drochner #include <netinet/if_inarp.h>
     43  1.1  drochner #endif
     44  1.1  drochner 
     45  1.1  drochner #include <machine/cpu.h>
     46  1.1  drochner #include <machine/pte.h>
     47  1.1  drochner 
     48  1.1  drochner #include <machine/autoconf.h>
     49  1.1  drochner 
     50  1.1  drochner #include <dev/ic/lancereg.h>
     51  1.1  drochner #include <dev/ic/lancevar.h>
     52  1.1  drochner #include <dev/ic/am79900reg.h>
     53  1.1  drochner #include <dev/ic/am79900var.h>
     54  1.1  drochner 
     55  1.1  drochner #include <cesfic/cesfic/isr.h>
     56  1.1  drochner 
     57  1.1  drochner int lematch __P((struct device *, struct cfdata *, void *));
     58  1.1  drochner void leattach __P((struct device *, struct device *, void *));
     59  1.1  drochner 
     60  1.3   thorpej CFATTACH_DECL(le, sizeof(struct am79900_softc),
     61  1.3   thorpej     lematch, leattach, NULL, NULL);
     62  1.1  drochner 
     63  1.1  drochner int	leintr __P((void *));
     64  1.1  drochner 
     65  1.1  drochner void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
     66  1.1  drochner u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
     67  1.1  drochner 
     68  1.1  drochner static char *lebase, *lemembase;
     69  1.1  drochner 
     70  1.1  drochner void
     71  1.1  drochner lewrcsr(sc, port, val)
     72  1.1  drochner 	struct lance_softc *sc;
     73  1.1  drochner 	u_int16_t port, val;
     74  1.1  drochner {
     75  1.1  drochner 	*(volatile int *)(lebase + 4) = port;
     76  1.1  drochner 	*(volatile int *)(lebase + 0) = val;
     77  1.1  drochner }
     78  1.1  drochner 
     79  1.1  drochner u_int16_t
     80  1.1  drochner lerdcsr(sc, port)
     81  1.1  drochner 	struct lance_softc *sc;
     82  1.1  drochner 	u_int16_t port;
     83  1.1  drochner {
     84  1.1  drochner 	u_int16_t val;
     85  1.1  drochner 
     86  1.1  drochner 	*(volatile int *)(lebase + 4) = port;
     87  1.1  drochner 	val = *(volatile int *)(lebase + 0);
     88  1.1  drochner 	return (val);
     89  1.1  drochner }
     90  1.1  drochner 
     91  1.1  drochner int
     92  1.1  drochner lematch(parent, match, aux)
     93  1.1  drochner 	struct device *parent;
     94  1.1  drochner 	struct cfdata *match;
     95  1.1  drochner 	void *aux;
     96  1.1  drochner {
     97  1.1  drochner 	return (1);
     98  1.1  drochner }
     99  1.1  drochner 
    100  1.1  drochner /*
    101  1.1  drochner  * Interface exists: make available by filling in network interface
    102  1.1  drochner  * record.  System will initialize the interface when it is ready
    103  1.1  drochner  * to accept packets.
    104  1.1  drochner  */
    105  1.1  drochner extern void sic_enable_int __P((int, int, int, int, int));
    106  1.1  drochner static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23};
    107  1.1  drochner void
    108  1.1  drochner leattach(parent, self, aux)
    109  1.1  drochner 	struct device *parent, *self;
    110  1.1  drochner 	void *aux;
    111  1.1  drochner {
    112  1.1  drochner 	int i;
    113  1.1  drochner 	struct lance_softc *sc = (struct lance_softc *)self;
    114  1.1  drochner 
    115  1.1  drochner 	mainbus_map(0x4c000000, 0x10000, 0, (void **)&lemembase);
    116  1.1  drochner 	mainbus_map(0x48000000, 0x1000, 0, (void **)&lebase);
    117  1.1  drochner 
    118  1.1  drochner 	sc->sc_mem = lemembase;
    119  1.1  drochner 	sc->sc_conf3 = LE_C3_BSWP;
    120  1.1  drochner 	sc->sc_addr = 0x4c000000;
    121  1.1  drochner 	sc->sc_memsize = 64 * 1024;
    122  1.1  drochner 
    123  1.1  drochner 	if (cesfic_getetheraddr(sc->sc_enaddr)) {
    124  1.1  drochner 		/* fallback */
    125  1.1  drochner 		for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
    126  1.1  drochner 			sc->sc_enaddr[i] = hwa[i];
    127  1.1  drochner 		}
    128  1.1  drochner 	}
    129  1.1  drochner 
    130  1.1  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    131  1.1  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    132  1.1  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    133  1.1  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    134  1.1  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    135  1.1  drochner 
    136  1.1  drochner 	sc->sc_rdcsr = lerdcsr;
    137  1.1  drochner 	sc->sc_wrcsr = lewrcsr;
    138  1.1  drochner 	sc->sc_hwinit = NULL;
    139  1.1  drochner 
    140  1.1  drochner 	lewrcsr(sc, 4, 0x44);
    141  1.1  drochner 	am79900_config((struct am79900_softc *)sc);
    142  1.1  drochner 
    143  1.1  drochner 	/* Establish the interrupt handler. */
    144  1.1  drochner 	(void) isrlink(leintr, sc, 3, ISRPRI_NET);
    145  1.1  drochner 	sic_enable_int(17, 0, 1, 3, 0);
    146  1.1  drochner }
    147  1.1  drochner 
    148  1.1  drochner int
    149  1.1  drochner leintr(arg)
    150  1.1  drochner 	void *arg;
    151  1.1  drochner {
    152  1.1  drochner 	struct lance_softc *sc = arg;
    153  1.1  drochner 	u_int16_t isr4;
    154  1.1  drochner 
    155  1.1  drochner 	isr4 = lerdcsr(sc, 4);
    156  1.1  drochner 	if (isr4 & 0x08) {
    157  1.1  drochner 		lewrcsr(sc, 4, isr4);
    158  1.1  drochner 		return (1);
    159  1.1  drochner 	}
    160  1.1  drochner 
    161  1.1  drochner 	return (am79900_intr(sc));
    162  1.1  drochner }
    163