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