if_le.c revision 1.36 1 1.36 thorpej /* $NetBSD: if_le.c,v 1.36 1996/12/17 08:41:13 thorpej Exp $ */
2 1.20 cgd
3 1.24 mycroft /*-
4 1.24 mycroft * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 1.24 mycroft * Copyright (c) 1992, 1993
6 1.24 mycroft * The Regents of the University of California. All rights reserved.
7 1.24 mycroft *
8 1.24 mycroft * This code is derived from software contributed to Berkeley by
9 1.24 mycroft * Ralph Campbell and Rick Macklem.
10 1.1 cgd *
11 1.1 cgd * Redistribution and use in source and binary forms, with or without
12 1.1 cgd * modification, are permitted provided that the following conditions
13 1.1 cgd * are met:
14 1.1 cgd * 1. Redistributions of source code must retain the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer.
16 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 cgd * notice, this list of conditions and the following disclaimer in the
18 1.1 cgd * documentation and/or other materials provided with the distribution.
19 1.1 cgd * 3. All advertising materials mentioning features or use of this software
20 1.1 cgd * must display the following acknowledgement:
21 1.1 cgd * This product includes software developed by the University of
22 1.1 cgd * California, Berkeley and its contributors.
23 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
24 1.1 cgd * may be used to endorse or promote products derived from this software
25 1.1 cgd * without specific prior written permission.
26 1.1 cgd *
27 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 cgd * SUCH DAMAGE.
38 1.1 cgd *
39 1.24 mycroft * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 1.1 cgd */
41 1.1 cgd
42 1.1 cgd #include "bpfilter.h"
43 1.1 cgd
44 1.5 mycroft #include <sys/param.h>
45 1.5 mycroft #include <sys/systm.h>
46 1.5 mycroft #include <sys/mbuf.h>
47 1.24 mycroft #include <sys/syslog.h>
48 1.5 mycroft #include <sys/socket.h>
49 1.24 mycroft #include <sys/device.h>
50 1.5 mycroft
51 1.5 mycroft #include <net/if.h>
52 1.1 cgd
53 1.1 cgd #ifdef INET
54 1.5 mycroft #include <netinet/in.h>
55 1.5 mycroft #include <netinet/if_ether.h>
56 1.1 cgd #endif
57 1.1 cgd
58 1.36 thorpej #include <machine/autoconf.h>
59 1.5 mycroft #include <machine/cpu.h>
60 1.18 mycroft #include <machine/mtpr.h>
61 1.24 mycroft
62 1.5 mycroft #include <hp300/hp300/isr.h>
63 1.25 thorpej
64 1.18 mycroft #ifdef USELEDS
65 1.18 mycroft #include <hp300/hp300/led.h>
66 1.18 mycroft #endif
67 1.1 cgd
68 1.36 thorpej #ifndef NEWCONFIG
69 1.5 mycroft #include <hp300/dev/device.h>
70 1.36 thorpej #endif
71 1.30 thorpej
72 1.30 thorpej #include <dev/ic/am7990reg.h>
73 1.30 thorpej #include <dev/ic/am7990var.h>
74 1.30 thorpej
75 1.36 thorpej #include <hp300/dev/dioreg.h>
76 1.36 thorpej #include <hp300/dev/diovar.h>
77 1.36 thorpej #include <hp300/dev/diodevs.h>
78 1.5 mycroft #include <hp300/dev/if_lereg.h>
79 1.24 mycroft #include <hp300/dev/if_levar.h>
80 1.1 cgd
81 1.36 thorpej #ifdef NEWCONFIG
82 1.36 thorpej int lematch __P((struct device *, struct cfdata *, void *));
83 1.36 thorpej void leattach __P((struct device *, struct device *, void *));
84 1.36 thorpej
85 1.36 thorpej struct cfattach le_ca = {
86 1.36 thorpej sizeof(struct le_softc), lematch, leattach
87 1.36 thorpej };
88 1.36 thorpej #else /* ! NEWCONFIG */
89 1.24 mycroft #include "le.h"
90 1.24 mycroft struct le_softc le_softc[NLE];
91 1.13 mycroft
92 1.24 mycroft int lematch __P((struct hp_device *));
93 1.24 mycroft void leattach __P((struct hp_device *));
94 1.13 mycroft
95 1.24 mycroft struct driver ledriver = {
96 1.24 mycroft lematch, leattach, "le",
97 1.24 mycroft };
98 1.36 thorpej #endif /* NEWCONFIG */
99 1.36 thorpej
100 1.36 thorpej int leintr __P((void *));
101 1.13 mycroft
102 1.1 cgd /* offsets for: ID, REGS, MEM, NVRAM */
103 1.1 cgd int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
104 1.29 christos
105 1.30 thorpej hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
106 1.30 thorpej hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
107 1.1 cgd
108 1.30 thorpej hide void
109 1.13 mycroft lewrcsr(sc, port, val)
110 1.30 thorpej struct am7990_softc *sc;
111 1.24 mycroft u_int16_t port, val;
112 1.13 mycroft {
113 1.30 thorpej register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
114 1.30 thorpej register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
115 1.13 mycroft
116 1.13 mycroft do {
117 1.13 mycroft ler1->ler1_rap = port;
118 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
119 1.13 mycroft do {
120 1.13 mycroft ler1->ler1_rdp = val;
121 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
122 1.13 mycroft }
123 1.13 mycroft
124 1.30 thorpej hide u_int16_t
125 1.13 mycroft lerdcsr(sc, port)
126 1.30 thorpej struct am7990_softc *sc;
127 1.24 mycroft u_int16_t port;
128 1.13 mycroft {
129 1.30 thorpej register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
130 1.30 thorpej register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
131 1.24 mycroft u_int16_t val;
132 1.13 mycroft
133 1.13 mycroft do {
134 1.13 mycroft ler1->ler1_rap = port;
135 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
136 1.13 mycroft do {
137 1.13 mycroft val = ler1->ler1_rdp;
138 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
139 1.13 mycroft return (val);
140 1.13 mycroft }
141 1.13 mycroft
142 1.36 thorpej #ifdef NEWCONFIG
143 1.36 thorpej int
144 1.36 thorpej lematch(parent, match, aux)
145 1.36 thorpej struct device *parent;
146 1.36 thorpej struct cfdata *match;
147 1.36 thorpej void *aux;
148 1.36 thorpej {
149 1.36 thorpej struct dio_attach_args *da = aux;
150 1.36 thorpej
151 1.36 thorpej if (da->da_id == DIO_DEVICE_ID_LAN)
152 1.36 thorpej return (1);
153 1.36 thorpej return (0);
154 1.36 thorpej }
155 1.36 thorpej #else /* ! NEWCONFIG */
156 1.23 thorpej int
157 1.23 thorpej lematch(hd)
158 1.23 thorpej struct hp_device *hd;
159 1.23 thorpej {
160 1.23 thorpej register struct lereg0 *ler0;
161 1.30 thorpej struct le_softc *lesc = &le_softc[hd->hp_unit];
162 1.23 thorpej
163 1.23 thorpej ler0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
164 1.23 thorpej if (ler0->ler0_id != LEID)
165 1.23 thorpej return (0);
166 1.23 thorpej
167 1.23 thorpej hd->hp_ipl = LE_IPL(ler0->ler0_status);
168 1.30 thorpej lesc->sc_hd = hd;
169 1.23 thorpej
170 1.23 thorpej return (1);
171 1.23 thorpej }
172 1.36 thorpej #endif /* NEWCONFIG */
173 1.23 thorpej
174 1.1 cgd /*
175 1.1 cgd * Interface exists: make available by filling in network interface
176 1.1 cgd * record. System will initialize the interface when it is ready
177 1.1 cgd * to accept packets.
178 1.1 cgd */
179 1.36 thorpej #ifdef NEWCONFIG
180 1.36 thorpej void
181 1.36 thorpej leattach(parent, self, aux)
182 1.36 thorpej struct device *parent, *self;
183 1.36 thorpej void *aux;
184 1.36 thorpej #else /* ! NEWCONFIG */
185 1.23 thorpej void
186 1.1 cgd leattach(hd)
187 1.1 cgd struct hp_device *hd;
188 1.36 thorpej #endif /* NEWCONFIG */
189 1.1 cgd {
190 1.1 cgd register struct lereg0 *ler0;
191 1.36 thorpej #ifdef NEWCONFIG
192 1.36 thorpej struct dio_attach_args *da = aux;
193 1.36 thorpej struct le_softc *lesc = (struct le_softc *)self;
194 1.36 thorpej caddr_t addr;
195 1.36 thorpej #else
196 1.30 thorpej struct le_softc *lesc = &le_softc[hd->hp_unit];
197 1.36 thorpej caddr_t addr = hd->hp_addr;
198 1.36 thorpej #endif /* NEWCONFIG */
199 1.31 thorpej struct am7990_softc *sc = &lesc->sc_am7990;
200 1.1 cgd char *cp;
201 1.36 thorpej int i, ipl;
202 1.36 thorpej
203 1.36 thorpej #ifdef NEWCONFIG
204 1.36 thorpej addr = iomap(dio_scodetopa(da->da_scode), da->da_size);
205 1.36 thorpej if (addr == 0) {
206 1.36 thorpej printf("\n%s: can't map LANCE registers\n",
207 1.36 thorpej sc->sc_dev.dv_xname);
208 1.36 thorpej return;
209 1.36 thorpej }
210 1.36 thorpej #endif /* NEWCONFIG */
211 1.1 cgd
212 1.36 thorpej ler0 = lesc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)addr);
213 1.24 mycroft ler0->ler0_id = 0xFF;
214 1.24 mycroft DELAY(100);
215 1.24 mycroft
216 1.36 thorpej #ifdef NEWCONFIG
217 1.36 thorpej ipl = DIO_IPL(addr);
218 1.36 thorpej printf(" ipl %d", ipl);
219 1.36 thorpej #else /* ! NEWCONFIG */
220 1.24 mycroft /* XXXX kluge for now */
221 1.34 thorpej hd->hp_dev.dv_class = DV_IFNET;
222 1.36 thorpej bcopy(&hd->hp_dev, &sc->sc_dev, sizeof(struct device));
223 1.36 thorpej ipl = hd->hp_ipl;
224 1.36 thorpej #endif /* NEWCONFIG */
225 1.24 mycroft
226 1.36 thorpej lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)addr);
227 1.36 thorpej sc->sc_mem = (void *)(lestd[2] + (int)addr);
228 1.24 mycroft sc->sc_conf3 = LE_C3_BSWP;
229 1.24 mycroft sc->sc_addr = 0;
230 1.24 mycroft sc->sc_memsize = 16384;
231 1.1 cgd
232 1.1 cgd /*
233 1.1 cgd * Read the ethernet address off the board, one nibble at a time.
234 1.1 cgd */
235 1.36 thorpej cp = (char *)(lestd[3] + (int)addr);
236 1.13 mycroft for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
237 1.13 mycroft sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
238 1.1 cgd cp++;
239 1.13 mycroft sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
240 1.1 cgd cp++;
241 1.1 cgd }
242 1.1 cgd
243 1.28 cgd sc->sc_copytodesc = am7990_copytobuf_contig;
244 1.28 cgd sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
245 1.28 cgd sc->sc_copytobuf = am7990_copytobuf_contig;
246 1.28 cgd sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
247 1.28 cgd sc->sc_zerobuf = am7990_zerobuf_contig;
248 1.25 thorpej
249 1.30 thorpej sc->sc_rdcsr = lerdcsr;
250 1.30 thorpej sc->sc_wrcsr = lewrcsr;
251 1.30 thorpej sc->sc_hwinit = NULL;
252 1.30 thorpej
253 1.30 thorpej am7990_config(sc);
254 1.24 mycroft
255 1.27 thorpej /* Establish the interrupt handler. */
256 1.36 thorpej (void) isrlink(leintr, sc, ipl, ISRPRI_NET);
257 1.1 cgd ler0->ler0_status = LE_IE;
258 1.1 cgd }
259 1.14 mycroft
260 1.30 thorpej int
261 1.30 thorpej leintr(arg)
262 1.27 thorpej void *arg;
263 1.26 thorpej {
264 1.30 thorpej struct am7990_softc *sc = arg;
265 1.26 thorpej u_int16_t isr;
266 1.26 thorpej
267 1.26 thorpej #ifdef USELEDS
268 1.26 thorpej isr = lerdcsr(sc, LE_CSR0);
269 1.26 thorpej
270 1.26 thorpej if ((isr & LE_C0_INTR) == 0)
271 1.26 thorpej return (0);
272 1.26 thorpej
273 1.26 thorpej if (isr & LE_C0_RINT)
274 1.26 thorpej if (inledcontrol == 0)
275 1.26 thorpej ledcontrol(0, 0, LED_LANRCV);
276 1.26 thorpej
277 1.26 thorpej if (isr & LE_C0_TINT)
278 1.26 thorpej if (inledcontrol == 0)
279 1.26 thorpej ledcontrol(0, 0, LED_LANXMT);
280 1.26 thorpej #endif /* USELEDS */
281 1.26 thorpej
282 1.30 thorpej return (am7990_intr(sc));
283 1.26 thorpej }
284