if_le.c revision 1.2 1 /* $NetBSD: if_le.c,v 1.2 1998/07/05 00:51:12 jonathan 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/adrsmap.h>
61
62 #include <dev/ic/am7990reg.h>
63 #include <dev/ic/am7990var.h>
64
65 /*
66 * LANCE registers.
67 * The real stuff is in dev/ic/am7990reg.h
68 */
69 struct lereg1 {
70 volatile u_int16_t ler1_rdp; /* data port */
71 volatile u_int16_t ler1_rap; /* register select port */
72 };
73
74 /*
75 * Ethernet software status per interface.
76 * The real stuff is in dev/ic/am7990var.h
77 */
78 struct le_softc {
79 struct am7990_softc sc_am7990; /* glue to MI code */
80
81 struct lereg1 *sc_r1; /* LANCE registers */
82 };
83
84 static int le_match __P((struct device *, struct cfdata *, void *));
85 static void le_attach __P((struct device *, struct device *, void *));
86
87 struct cfattach le_ca = {
88 sizeof(struct le_softc), le_match, le_attach
89 };
90
91 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
92 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
93
94 hide void
95 lewrcsr(sc, port, val)
96 struct am7990_softc *sc;
97 u_int16_t port, val;
98 {
99 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
100
101 ler1->ler1_rap = port;
102 ler1->ler1_rdp = val;
103 }
104
105 hide u_int16_t
106 lerdcsr(sc, port)
107 struct am7990_softc *sc;
108 u_int16_t port;
109 {
110 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
111 u_int16_t val;
112
113 ler1->ler1_rap = port;
114 val = ler1->ler1_rdp;
115 return (val);
116 }
117
118 int
119 le_match(parent, cf, aux)
120 struct device *parent;
121 struct cfdata *cf;
122 void *aux;
123 {
124 struct confargs *ca = aux;
125 int addr;
126
127 if (strcmp(ca->ca_name, "le"))
128 return 0;
129
130 switch(cf->cf_unit) {
131
132 case 0:
133 addr = LANCE_PORT;
134 break;
135 case 1:
136 addr = LANCE_PORT1;
137 break;
138 case 2:
139 addr = LANCE_PORT2;
140 break;
141
142 default:
143 return 0;
144 }
145
146 if (badaddr((void *)addr, 1))
147 return 0;
148
149 return 1;
150 }
151
152 void
153 le_attach(parent, self, aux)
154 struct device *parent, *self;
155 void *aux;
156 {
157 struct le_softc *lesc = (struct le_softc *)self;
158 struct am7990_softc *sc = &lesc->sc_am7990;
159 /*struct confargs *ca = aux;*/
160 u_char *p;
161
162 switch (sc->sc_dev.dv_unit) {
163
164 case 0:
165 lesc->sc_r1 = (void *)LANCE_PORT;
166 sc->sc_mem = (void *)LANCE_MEMORY;
167 p = (u_char *)(ETHER_ID+16);
168 break;
169 case 1:
170 lesc->sc_r1 = (void *)LANCE_PORT1;
171 sc->sc_mem = (void *)LANCE_MEMORY1;
172 p = (u_char *)(ETHER_ID1+16);
173 break;
174 case 2:
175 lesc->sc_r1 = (void *)LANCE_PORT2;
176 sc->sc_mem = (void *)LANCE_MEMORY2;
177 p = (u_char *)(ETHER_ID2+16);
178 break;
179
180 default:
181 panic("le_attach");
182 }
183
184 sc->sc_memsize = 0x4000; /* 16K */
185 sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
186 sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
187
188 sc->sc_enaddr[0] = (*p++ << 4);
189 sc->sc_enaddr[0] |= *p++ & 0x0f;
190 sc->sc_enaddr[1] = (*p++ << 4);
191 sc->sc_enaddr[1] |= *p++ & 0x0f;
192 sc->sc_enaddr[2] = (*p++ << 4);
193 sc->sc_enaddr[2] |= *p++ & 0x0f;
194 sc->sc_enaddr[3] = (*p++ << 4);
195 sc->sc_enaddr[3] |= *p++ & 0x0f;
196 sc->sc_enaddr[4] = (*p++ << 4);
197 sc->sc_enaddr[4] |= *p++ & 0x0f;
198 sc->sc_enaddr[5] = (*p++ << 4);
199 sc->sc_enaddr[5] |= *p++ & 0x0f;
200
201 sc->sc_copytodesc = am7990_copytobuf_contig;
202 sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
203 sc->sc_copytobuf = am7990_copytobuf_contig;
204 sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
205 sc->sc_zerobuf = am7990_zerobuf_contig;
206
207 sc->sc_rdcsr = lerdcsr;
208 sc->sc_wrcsr = lewrcsr;
209 sc->sc_hwinit = NULL;
210
211 am7990_config(sc);
212 }
213
214 int
215 leintr(unit)
216 int unit;
217 {
218 struct am7990_softc *sc;
219 extern struct cfdriver le_cd;
220
221 if (unit >= le_cd.cd_ndevs)
222 return 0;
223
224 sc = le_cd.cd_devs[unit];
225 return am7990_intr(sc);
226 }
227