xref: /netbsd-src/sys/arch/sun3/dev/if_le.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: if_le.c,v 1.32 1996/10/30 00:24:36 gwr 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 
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_ether.h>
56 #endif
57 
58 #include <machine/autoconf.h>
59 #include <machine/cpu.h>
60 #include <machine/dvma.h>
61 #include <machine/isr.h>
62 #include <machine/obio.h>
63 #include <machine/idprom.h>
64 
65 #include <dev/ic/am7990reg.h>
66 #include <dev/ic/am7990var.h>
67 
68 #include <sun3/dev/if_lereg.h>
69 #include <sun3/dev/if_levar.h>
70 
71 static int	le_match __P((struct device *, void *, void *));
72 static void	le_attach __P((struct device *, struct device *, void *));
73 
74 struct cfattach le_ca = {
75 	sizeof(struct le_softc), le_match, le_attach
76 };
77 
78 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
79 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
80 
81 hide void
82 lewrcsr(sc, port, val)
83 	struct am7990_softc *sc;
84 	u_int16_t port, val;
85 {
86 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
87 
88 	ler1->ler1_rap = port;
89 	ler1->ler1_rdp = val;
90 }
91 
92 hide u_int16_t
93 lerdcsr(sc, port)
94 	struct am7990_softc *sc;
95 	u_int16_t port;
96 {
97 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
98 	u_int16_t val;
99 
100 	ler1->ler1_rap = port;
101 	val = ler1->ler1_rdp;
102 	return (val);
103 }
104 
105 int
106 le_match(parent, vcf, aux)
107 	struct device *parent;
108 	void *vcf, *aux;
109 {
110 	struct cfdata *cf = vcf;
111 	struct confargs *ca = aux;
112 
113 	/* Make sure there is something there... */
114 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
115 		return (0);
116 
117 	/* Default interrupt priority. */
118 	if (ca->ca_intpri == -1)
119 		ca->ca_intpri = 3;
120 
121 	return (1);
122 }
123 
124 void
125 le_attach(parent, self, aux)
126 	struct device *parent, *self;
127 	void *aux;
128 {
129 	struct le_softc *lesc = (struct le_softc *)self;
130 	struct am7990_softc *sc = &lesc->sc_am7990;
131 	struct cfdata *cf = self->dv_cfdata;
132 	struct confargs *ca = aux;
133 
134 	lesc->sc_r1 = (struct lereg1 *)
135 	    obio_alloc(ca->ca_paddr, OBIO_AMD_ETHER_SIZE);
136 
137 	sc->sc_memsize = 0x4000;	/* 16K */
138 	sc->sc_mem = dvma_malloc(sc->sc_memsize);
139 	sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
140 	sc->sc_conf3 = LE_C3_BSWP;
141 
142 	idprom_etheraddr(sc->sc_arpcom.ac_enaddr);
143 
144 	sc->sc_copytodesc = am7990_copytobuf_contig;
145 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
146 	sc->sc_copytobuf = am7990_copytobuf_contig;
147 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
148 	sc->sc_zerobuf = am7990_zerobuf_contig;
149 
150 	sc->sc_rdcsr = lerdcsr;
151 	sc->sc_wrcsr = lewrcsr;
152 	sc->sc_hwinit = NULL;
153 
154 	am7990_config(sc);
155 
156 	/* Install interrupt handler. */
157 	isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
158 }
159