if_le.c revision 1.8 1 /* $NetBSD: if_le.c,v 1.8 2019/06/30 02:11:56 tsutsui Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell and Rick Macklem.
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
35 */
36
37 /*-
38 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
39 *
40 * This code is derived from software contributed to Berkeley by
41 * Ralph Campbell and Rick Macklem.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
72 */
73
74 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
75
76 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.8 2019/06/30 02:11:56 tsutsui Exp $");
77
78 #include "opt_inet.h"
79
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/mbuf.h>
83 #include <sys/socket.h>
84 #include <sys/device.h>
85
86 #include <net/if.h>
87 #include <net/if_ether.h>
88 #include <net/if_media.h>
89
90 #ifdef INET
91 #include <netinet/in.h>
92 #include <netinet/if_inarp.h>
93 #endif
94
95 #include <machine/cpu.h>
96 #include <machine/autoconf.h>
97
98 #include <luna68k/luna68k/isr.h>
99
100 #include <dev/ic/lancereg.h>
101 #include <dev/ic/lancevar.h>
102 #include <dev/ic/am7990reg.h>
103 #include <dev/ic/am7990var.h>
104
105 #include "ioconf.h"
106
107 /*
108 * LANCE registers.
109 */
110 struct lereg1 {
111 volatile uint16_t ler1_rdp; /* data port */
112 volatile uint16_t ler1_rap; /* register select port */
113 };
114
115 /*
116 * Ethernet software status per interface.
117 *
118 * Each interface is referenced by a network interface structure,
119 * arpcom.ac_if, which the routing code uses to locate the interface.
120 * This structure contains the output queue for the interface, its address, ...
121 */
122 struct le_softc {
123 struct am7990_softc sc_am7990; /* glue to MI code */
124
125 struct lereg1 *sc_r1; /* LANCE registers */
126 };
127
128 static int le_match(device_t, cfdata_t, void *);
129 static void le_attach(device_t, device_t, void *);
130
131 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
132 le_match, le_attach, NULL, NULL);
133
134 static void lesrcsr(struct lance_softc *, uint16_t, uint16_t);
135 static uint16_t lerdcsr(struct lance_softc *, uint16_t);
136 static void myetheraddr(uint8_t *);
137
138 static void
139 lesrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
140 {
141 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
142
143 ler1->ler1_rap = port;
144 ler1->ler1_rdp = val;
145 }
146
147 static uint16_t
148 lerdcsr(struct lance_softc *sc, uint16_t port)
149 {
150 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
151 uint16_t val;
152
153 ler1->ler1_rap = port;
154 val = ler1->ler1_rdp;
155 return val;
156 }
157
158 static int
159 le_match(device_t parent, cfdata_t cf, void *aux)
160 {
161 struct mainbus_attach_args *ma = aux;
162
163 if (strcmp(ma->ma_name, le_cd.cd_name))
164 return 0;
165
166 return 1;
167 }
168
169 void
170 le_attach(device_t parent, device_t self, void *aux)
171 {
172 struct le_softc *lesc = device_private(self);
173 struct lance_softc *sc = &lesc->sc_am7990.lsc;
174 struct mainbus_attach_args *ma = aux;
175
176 sc->sc_dev = self;
177
178 /* Map control registers. */
179 lesc->sc_r1 = (struct lereg1 *)ma->ma_addr; /* LANCE */
180
181 sc->sc_mem = (void *)0x71010000; /* SRAM */
182 sc->sc_conf3 = LE_C3_BSWP;
183 sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
184 sc->sc_memsize = 64 * 1024; /* 64KB */
185
186 myetheraddr(sc->sc_enaddr);
187
188 sc->sc_copytodesc = lance_copytobuf_contig;
189 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
190 sc->sc_copytobuf = lance_copytobuf_contig;
191 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
192 sc->sc_zerobuf = lance_zerobuf_contig;
193
194 sc->sc_rdcsr = lerdcsr;
195 sc->sc_wrcsr = lesrcsr;
196 sc->sc_hwinit = NULL;
197
198 am7990_config(&lesc->sc_am7990);
199
200 isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET);
201 }
202
203 /*
204 * LUNA-I has 1Mbit CPU ROM, which contains MAC address directly
205 * readable at 0x4100FFE0 as a sequence of 12 ASCII characters.
206 *
207 * LUNA-II has 16Kbit NVSRAM on its ethercard, whose contents are
208 * accessible 4bit-wise by ctl register operation. The register is
209 * mapped at 0xF1000004.
210 */
211 void
212 myetheraddr(uint8_t *ether)
213 {
214 unsigned int i, loc;
215 uint8_t *ea;
216 volatile struct { uint32_t ctl; } *ds1220;
217
218 switch (machtype) {
219 case LUNA_I:
220 ea = (uint8_t *)0x4101FFE0;
221 for (i = 0; i < ETHER_ADDR_LEN; i++) {
222 int u, l;
223
224 u = ea[0];
225 u = (u < 'A') ? u & 0xf : u - 'A' + 10;
226 l = ea[1];
227 l = (l < 'A') ? l & 0xf : l - 'A' + 10;
228
229 ether[i] = l | (u << 4);
230 ea += 2;
231 }
232 break;
233 case LUNA_II:
234 ds1220 = (void *)0xF1000004;
235 loc = 12;
236 for (i = 0; i < ETHER_ADDR_LEN; i++) {
237 unsigned int u, l, hex;
238
239 ds1220->ctl = (loc) << 16;
240 u = 0xf0 & (ds1220->ctl >> 12);
241 ds1220->ctl = (loc + 1) << 16;
242 l = 0x0f & (ds1220->ctl >> 16);
243 hex = (u < '9') ? l : l + 9;
244
245 ds1220->ctl = (loc + 2) << 16;
246 u = 0xf0 & (ds1220->ctl >> 12);
247 ds1220->ctl = (loc + 3) << 16;
248 l = 0x0f & (ds1220->ctl >> 16);
249
250 ether[i] = ((u < '9') ? l : l + 9) | (hex << 4);
251 loc += 4;
252 }
253 break;
254 default:
255 ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a;
256 ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00;
257 break;
258 }
259 }
260