Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.24
      1 /*	$NetBSD: if_le.c,v 1.24 1997/03/17 03:17:34 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      5  * Copyright (c) 1992, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * Ralph Campbell and Rick Macklem.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     40  */
     41 
     42 #include "bpfilter.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/mbuf.h>
     47 #include <sys/syslog.h>
     48 #include <sys/socket.h>
     49 #include <sys/device.h>
     50 
     51 #include <net/if.h>
     52 #include <net/if_ether.h>
     53 #include <net/if_media.h>
     54 
     55 #ifdef INET
     56 #include <netinet/in.h>
     57 #include <netinet/if_inarp.h>
     58 #endif
     59 
     60 #include <machine/cpu.h>
     61 #include <machine/mtpr.h>
     62 
     63 #include <amiga/amiga/device.h>
     64 #include <amiga/amiga/isr.h>
     65 
     66 #include <dev/ic/am7990reg.h>
     67 #include <dev/ic/am7990var.h>
     68 
     69 #include <amiga/dev/zbusvar.h>
     70 #include <amiga/dev/if_levar.h>
     71 
     72 /* offsets for:	   ID,   REGS,    MEM */
     73 int	lestd[] = { 0, 0x4000, 0x8000 };
     74 
     75 int le_zbus_match __P((struct device *, struct cfdata *, void *));
     76 void le_zbus_attach __P((struct device *, struct device *, void *));
     77 
     78 struct cfattach le_zbus_ca = {
     79 	sizeof(struct le_softc), le_zbus_match, le_zbus_attach
     80 };
     81 
     82 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     83 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
     84 
     85 hide void
     86 lewrcsr(sc, port, val)
     87 	struct am7990_softc *sc;
     88 	u_int16_t port, val;
     89 {
     90 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
     91 
     92 	ler1->ler1_rap = port;
     93 	ler1->ler1_rdp = val;
     94 }
     95 
     96 hide u_int16_t
     97 lerdcsr(sc, port)
     98 	struct am7990_softc *sc;
     99 	u_int16_t port;
    100 {
    101 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    102 	u_int16_t val;
    103 
    104 	ler1->ler1_rap = port;
    105 	val = ler1->ler1_rdp;
    106 	return (val);
    107 }
    108 
    109 int
    110 le_zbus_match(parent, cfp, aux)
    111 	struct device *parent;
    112 	struct cfdata *cfp;
    113 	void *aux;
    114 {
    115 	struct zbus_args *zap = aux;
    116 
    117 	/* Commodore ethernet card */
    118 	if (zap->manid == 514 && zap->prodid == 112)
    119 		return (1);
    120 
    121 	/* Ameristar ethernet card */
    122 	if (zap->manid == 1053 && zap->prodid == 1)
    123 		return (1);
    124 
    125 	return (0);
    126 }
    127 
    128 void
    129 le_zbus_attach(parent, self, aux)
    130 	struct device *parent, *self;
    131 	void *aux;
    132 {
    133 	struct le_softc *lesc = (struct le_softc *)self;
    134 	struct am7990_softc *sc = &lesc->sc_am7990;
    135 	struct zbus_args *zap = aux;
    136 	u_long ser;
    137 	u_int8_t myaddr[ETHER_ADDR_LEN];
    138 
    139 	lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)zap->va);
    140 	sc->sc_mem = (void *)(lestd[2] + (int)zap->va);
    141 
    142 	sc->sc_copytodesc = am7990_copytobuf_contig;
    143 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    144 	sc->sc_copytobuf = am7990_copytobuf_contig;
    145 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    146 	sc->sc_zerobuf = am7990_zerobuf_contig;
    147 
    148 	sc->sc_rdcsr = lerdcsr;
    149 	sc->sc_wrcsr = lewrcsr;
    150 	sc->sc_hwinit = NULL;
    151 
    152 	sc->sc_conf3 = LE_C3_BSWP;
    153 	sc->sc_addr = 0x8000;
    154 
    155 	/*
    156 	 * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
    157 	 */
    158 	switch (zap->manid) {
    159 	case 514:
    160 		/* Commodore */
    161 		sc->sc_memsize = 32768;
    162 		sc->sc_enaddr[0] = 0x00;
    163 		sc->sc_enaddr[1] = 0x80;
    164 		sc->sc_enaddr[2] = 0x10;
    165 		break;
    166 
    167 	case 1053:
    168 		/* Ameristar */
    169 		sc->sc_memsize = 32768;
    170 		sc->sc_enaddr[0] = 0x00;
    171 		sc->sc_enaddr[1] = 0x00;
    172 		sc->sc_enaddr[2] = 0x9f;
    173 		break;
    174 
    175 	default:
    176 		panic("le_zbus_attach: bad manid");
    177 	}
    178 
    179 	/*
    180 	 * Serial number for board is used as host ID.
    181 	 */
    182 	ser = (u_long)zap->serno;
    183 	sc->sc_enaddr[3] = (ser >> 16) & 0xff;
    184 	sc->sc_enaddr[4] = (ser >>  8) & 0xff;
    185 	sc->sc_enaddr[5] = (ser      ) & 0xff;
    186 
    187 	am7990_config(sc);
    188 
    189 	lesc->sc_isr.isr_intr = am7990_intr;
    190 	lesc->sc_isr.isr_arg = sc;
    191 	lesc->sc_isr.isr_ipl = 2;
    192 	add_isr(&lesc->sc_isr);
    193 }
    194