if_le.c revision 1.1 1 /* $NetBSD: if_le.c,v 1.1 2000/01/05 08:48:56 nisimura 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
43
44 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.1 2000/01/05 08:48:56 nisimura Exp $");
45
46 #include "opt_inet.h"
47 #include "bpfilter.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <sys/device.h>
54
55 #include <net/if.h>
56 #include <net/if_ether.h>
57 #include <net/if_media.h>
58
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/if_inarp.h>
62 #endif
63
64 #include <machine/cpu.h>
65 #include <machine/autoconf.h>
66
67 #include <luna68k/luna68k/isr.h>
68
69 #include <dev/ic/lancereg.h>
70 #include <dev/ic/lancevar.h>
71 #include <dev/ic/am7990reg.h>
72 #include <dev/ic/am7990var.h>
73
74 /*
75 * LANCE registers.
76 */
77 struct lereg1 {
78 volatile u_int16_t ler1_rdp; /* data port */
79 volatile u_int16_t ler1_rap; /* register select port */
80 };
81
82 /*
83 * Ethernet software status per interface.
84 *
85 * Each interface is referenced by a network interface structure,
86 * arpcom.ac_if, which the routing code uses to locate the interface.
87 * This structure contains the output queue for the interface, its address, ...
88 */
89 struct le_softc {
90 struct am7990_softc sc_am7990; /* glue to MI code */
91
92 struct lereg1 *sc_r1; /* LANCE registers */
93 };
94
95 static int le_match __P((struct device *, struct cfdata *, void *));
96 static void le_attach __P((struct device *, struct device *, void *));
97
98 const struct cfattach le_ca = {
99 sizeof(struct le_softc), le_match, le_attach
100 };
101 extern struct cfdriver le_cd;
102
103 static void lesrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
104 static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
105 static void myetheraddr __P((u_int8_t *));
106
107 static void
108 lesrcsr(sc, port, val)
109 struct lance_softc *sc;
110 u_int16_t port, val;
111 {
112 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
113
114 ler1->ler1_rap = port;
115 ler1->ler1_rdp = val;
116 }
117
118 static u_int16_t
119 lerdcsr(sc, port)
120 struct lance_softc *sc;
121 u_int16_t port;
122 {
123 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
124 u_int16_t val;
125
126 ler1->ler1_rap = port;
127 val = ler1->ler1_rdp;
128 return (val);
129 }
130
131 static int
132 le_match(parent, cf, aux)
133 struct device *parent;
134 struct cfdata *cf;
135 void *aux;
136 {
137 struct mainbus_attach_args *ma = aux;
138
139 if (strcmp(ma->ma_name, le_cd.cd_name))
140 return (0);
141
142 return (1);
143 }
144
145 void
146 le_attach(parent, self, aux)
147 struct device *parent, *self;
148 void *aux;
149 {
150 struct le_softc *lesc = (void *)self;
151 struct lance_softc *sc = &lesc->sc_am7990.lsc;
152 struct mainbus_attach_args *ma = aux;
153
154 /* Map control registers. */
155 lesc->sc_r1 = (struct lereg1 *)ma->ma_addr; /* LANCE */
156
157 sc->sc_mem = (void *)0x71010000; /* SRAM */
158 sc->sc_conf3 = LE_C3_BSWP;
159 sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
160 sc->sc_memsize = 64 * 1024; /* 64KB */
161
162 myetheraddr(sc->sc_enaddr);
163
164 sc->sc_copytodesc = lance_copytobuf_contig;
165 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
166 sc->sc_copytobuf = lance_copytobuf_contig;
167 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
168 sc->sc_zerobuf = lance_zerobuf_contig;
169
170 sc->sc_rdcsr = lerdcsr;
171 sc->sc_wrcsr = lesrcsr;
172 sc->sc_hwinit = NULL;
173
174 am7990_config(&lesc->sc_am7990);
175
176 isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET);
177 }
178
179 /*
180 * LUNA-I has 1Mbit CPU ROM, which contains MAC address directly
181 * readable at 0x4100FFE0 as a sequence of 12 ASCII characters.
182 *
183 * LUNA-II has 16Kbit NVSRAM on its ethercard, whose contents are
184 * accessible 4bit-wise by ctl register operation. The register is
185 * mapped at 0xF1000004.
186 */
187 void
188 myetheraddr(ether)
189 u_int8_t *ether;
190 {
191 unsigned i, loc;
192 u_int8_t *ea;
193 volatile struct { u_int32_t ctl; } *ds1220;
194
195 switch (machtype) {
196 case LUNA_I:
197 ea = (u_int8_t *)0x4101FFE0;
198 for (i = 0; i < 6; i++) {
199 int u, l;
200
201 u = ea[0];
202 u = (u < 'A') ? u & 0xf : u - 'A' + 10;
203 l = ea[1];
204 l = (l < 'A') ? l & 0xf : l - 'A' + 10;
205
206 ether[i] = l | (u << 4);
207 ea += 2;
208 }
209 break;
210 case LUNA_II:
211 ds1220 = (void *)0xF1000004;
212 loc = 12;
213 for (i = 0; i < 6; i++) {
214 unsigned u, l, hex;
215
216 ds1220->ctl = (loc) << 16;
217 u = 0xf0 & (ds1220->ctl >> 12);
218 ds1220->ctl = (loc + 1) << 16;
219 l = 0x0f & (ds1220->ctl >> 16);
220 hex = (u < '9') ? l : l + 9;
221
222 ds1220->ctl = (loc + 2) << 16;
223 u = 0xf0 & (ds1220->ctl >> 12);
224 ds1220->ctl = (loc + 3) << 16;
225 l = 0x0f & (ds1220->ctl >> 16);
226
227 ether[i] = ((u < '9') ? l : l + 9) | (hex << 4);
228 loc += 4;
229 }
230 break;
231 default:
232 ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a;
233 ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00;
234 break;
235 }
236 }
237