xref: /netbsd-src/sys/arch/news68k/dev/if_le.c (revision 95d875fb90b1458e4f1de6950286ddcd6644bc61)
1 /*	$NetBSD: if_le.c,v 1.1 1999/12/09 14:53:05 tsutsui 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 /*
40  * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
41  */
42 
43 #include "opt_inet.h"
44 #include "bpfilter.h"
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/mbuf.h>
49 #include <sys/socket.h>
50 #include <sys/device.h>
51 
52 #include <net/if.h>
53 #include <net/if_ether.h>
54 #include <net/if_media.h>
55 
56 #ifdef INET
57 #include <netinet/in.h>
58 #include <netinet/if_inarp.h>
59 #endif
60 
61 #include <machine/cpu.h>
62 
63 #include <news68k/dev/hbvar.h>
64 
65 #include <dev/ic/lancereg.h>
66 #include <dev/ic/lancevar.h>
67 #include <dev/ic/am7990reg.h>
68 #include <dev/ic/am7990var.h>
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) && !defined(_LKM)
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 int leintr __P((int));
111 
112 hide void
113 lewrcsr(sc, port, val)
114 	struct lance_softc *sc;
115 	u_int16_t port, val;
116 {
117 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
118 
119 	ler1->ler1_rap = port;
120 	ler1->ler1_rdp = val;
121 }
122 
123 hide u_int16_t
124 lerdcsr(sc, port)
125 	struct lance_softc *sc;
126 	u_int16_t port;
127 {
128 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
129 	u_int16_t val;
130 
131 	ler1->ler1_rap = port;
132 	val = ler1->ler1_rdp;
133 	return (val);
134 }
135 
136 int
137 le_match(parent, cf, aux)
138 	struct device *parent;
139 	struct cfdata *cf;
140 	void *aux;
141 {
142 	struct hb_attach_args *ha = aux;
143 	int addr;
144 
145 	if (strcmp(ha->ha_name, "le"))
146 		return 0;
147 
148 	switch(cf->cf_unit) {
149 
150 	case 0:
151 		addr = IIOV(LANCE_PORT);	/* XXX hard coded now... */
152 		break;
153 	case 1:
154 		addr = LANCE_PORT1;	/* XXX */
155 		break;
156 	case 2:
157 		addr = LANCE_PORT2;	/* XXX */
158 		break;
159 
160 	default:
161 		return 0;
162 	}
163 
164 	if (badaddr((void *)addr, 1))
165 		return 0;
166 
167 	return 1;
168 }
169 
170 void
171 le_attach(parent, self, aux)
172 	struct device *parent, *self;
173 	void *aux;
174 {
175 	struct le_softc *lesc = (struct le_softc *)self;
176 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
177 	/*struct hb_attach_args *ha = aux;*/
178 	u_char *p;
179 
180 	switch (sc->sc_dev.dv_unit) {
181 
182 	case 0:
183 		lesc->sc_r1 = (void *)IIOV(LANCE_PORT);	/* XXX */
184 		sc->sc_mem = (void *)IIOV(LANCE_MEMORY);
185 		p = (u_char *)IIOV(LANCE_ID+16);
186 		break;
187 	case 1:
188 		lesc->sc_r1 = (void *)LANCE_PORT1;/* XXX */
189 		sc->sc_mem = (void *)LANCE_MEMORY1;
190 		p = (u_char *)(LANCE_ID1+16);
191 		break;
192 	case 2:
193 		lesc->sc_r1 = (void *)LANCE_PORT2;	/* XXX */
194 		sc->sc_mem = (void *)LANCE_MEMORY2;
195 		p = (u_char *)(LANCE_ID2+16);
196 		break;
197 
198 	default:
199 		panic("le_attach");
200 	}
201 
202 	sc->sc_memsize = 0x4000;	/* 16K */
203 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
204 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
205 
206 	sc->sc_enaddr[0] = (*p++ << 4);
207 	sc->sc_enaddr[0] |= *p++ & 0x0f;
208 	sc->sc_enaddr[1] = (*p++ << 4);
209 	sc->sc_enaddr[1] |= *p++ & 0x0f;
210 	sc->sc_enaddr[2] = (*p++ << 4);
211 	sc->sc_enaddr[2] |= *p++ & 0x0f;
212 	sc->sc_enaddr[3] = (*p++ << 4);
213 	sc->sc_enaddr[3] |= *p++ & 0x0f;
214 	sc->sc_enaddr[4] = (*p++ << 4);
215 	sc->sc_enaddr[4] |= *p++ & 0x0f;
216 	sc->sc_enaddr[5] = (*p++ << 4);
217 	sc->sc_enaddr[5] |= *p++ & 0x0f;
218 
219 	sc->sc_copytodesc = lance_copytobuf_contig;
220 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
221 	sc->sc_copytobuf = lance_copytobuf_contig;
222 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
223 	sc->sc_zerobuf = lance_zerobuf_contig;
224 
225 	sc->sc_rdcsr = lerdcsr;
226 	sc->sc_wrcsr = lewrcsr;
227 	sc->sc_hwinit = NULL;
228 
229 	am7990_config(&lesc->sc_am7990);
230 }
231 
232 int
233 leintr(unit)
234 	int unit;
235 {
236 	struct am7990_softc *sc;
237 	extern struct cfdriver le_cd;
238 
239 	if (unit >= le_cd.cd_ndevs)
240 		return 0;
241 
242 	sc = le_cd.cd_devs[unit];
243 	return am7990_intr(sc);
244 }
245