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