xref: /netbsd-src/sys/arch/sun3/dev/if_le.c (revision 1ca5c1b28139779176bd5c13ad7c5f25c0bcd5f8)
1 /*	$NetBSD: if_le.c,v 1.42 2001/05/30 12:28:52 mrg Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Adam Glass and Gordon W. Ross.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "opt_inet.h"
40 #include "bpfilter.h"
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/mbuf.h>
45 #include <sys/syslog.h>
46 #include <sys/socket.h>
47 #include <sys/device.h>
48 
49 #include <net/if.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
52 
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_inarp.h>
56 #endif
57 
58 #include <machine/autoconf.h>
59 #include <machine/cpu.h>
60 #include <machine/dvma.h>
61 #include <machine/idprom.h>
62 
63 #include <dev/ic/lancereg.h>
64 #include <dev/ic/lancevar.h>
65 #include <dev/ic/am7990reg.h>
66 #include <dev/ic/am7990var.h>
67 
68 #define LE_MEMSIZE	0x4000	/* 16K */
69 
70 /*
71  * LANCE registers.
72  * The real stuff is in dev/ic/am7990reg.h
73  */
74 struct lereg1 {
75 	volatile u_int16_t	ler1_rdp;	/* data port */
76 	volatile u_int16_t	ler1_rap;	/* register select port */
77 };
78 
79 /*
80  * Ethernet software status per interface.
81  * The real stuff is in dev/ic/am7990var.h
82  */
83 struct	le_softc {
84 	struct	am7990_softc sc_am7990;	/* glue to MI code */
85 
86 	struct	lereg1 *sc_r1;		/* LANCE registers */
87 };
88 
89 static int	le_match __P((struct device *, struct cfdata *, void *));
90 static void	le_attach __P((struct device *, struct device *, void *));
91 
92 struct cfattach le_ca = {
93 	sizeof(struct le_softc), le_match, le_attach
94 };
95 
96 #if defined(_KERNEL_OPT)
97 #include "opt_ddb.h"
98 #endif
99 
100 #ifdef DDB
101 #define	integrate
102 #define hide
103 #else
104 #define	integrate	static __inline
105 #define hide		static
106 #endif
107 
108 hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
109 hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
110 
111 hide void
112 lewrcsr(sc, port, val)
113 	struct lance_softc *sc;
114 	u_int16_t port, val;
115 {
116 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
117 
118 	ler1->ler1_rap = port;
119 	ler1->ler1_rdp = val;
120 }
121 
122 hide u_int16_t
123 lerdcsr(sc, port)
124 	struct lance_softc *sc;
125 	u_int16_t port;
126 {
127 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
128 	u_int16_t val;
129 
130 	ler1->ler1_rap = port;
131 	val = ler1->ler1_rdp;
132 	return (val);
133 }
134 
135 int
136 le_match(parent, cf, aux)
137 	struct device *parent;
138 	struct cfdata *cf;
139 	void *aux;
140 {
141 	struct confargs *ca = aux;
142 
143 	/* Make sure there is something there... */
144 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
145 		return (0);
146 
147 	/* Default interrupt priority. */
148 	if (ca->ca_intpri == -1)
149 		ca->ca_intpri = 3;
150 
151 	return (1);
152 }
153 
154 void
155 le_attach(parent, self, aux)
156 	struct device *parent, *self;
157 	void *aux;
158 {
159 	struct le_softc *lesc = (struct le_softc *)self;
160 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
161 	struct confargs *ca = aux;
162 
163 	lesc->sc_r1 = bus_mapin(ca->ca_bustype,
164 	    ca->ca_paddr, sizeof(struct lereg1));
165 
166 	sc->sc_memsize = LE_MEMSIZE;
167 	sc->sc_mem = dvma_malloc(sc->sc_memsize);
168 	sc->sc_addr = dvma_kvtopa(sc->sc_mem, ca->ca_bustype);
169 #ifdef	_SUN3X_
170 	sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
171 #else
172 	sc->sc_conf3 = LE_C3_BSWP;
173 #endif
174 
175 	idprom_etheraddr(sc->sc_enaddr);
176 
177 	sc->sc_copytodesc = lance_copytobuf_contig;
178 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
179 	sc->sc_copytobuf = lance_copytobuf_contig;
180 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
181 	sc->sc_zerobuf = lance_zerobuf_contig;
182 
183 	sc->sc_rdcsr = lerdcsr;
184 	sc->sc_wrcsr = lewrcsr;
185 	sc->sc_hwinit = NULL;
186 
187 	am7990_config(&lesc->sc_am7990);
188 
189 	/* Install interrupt handler. */
190 	isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
191 }
192