if_le.c revision 1.37.4.2 1 /* $NetBSD: if_le.c,v 1.37.4.2 1997/03/10 16:08:26 is 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 "bpfilter.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mbuf.h>
47 #include <sys/syslog.h>
48 #include <sys/socket.h>
49 #include <sys/device.h>
50
51 #include <net/if.h>
52 #include <net/if_ether.h>
53
54 #ifdef INET
55 #include <netinet/in.h>
56 #include <netinet/if_inarp.h>
57 #endif
58
59 #include <machine/autoconf.h>
60 #include <machine/cpu.h>
61 #include <machine/mtpr.h>
62
63 #include <hp300/hp300/isr.h>
64
65 #ifdef USELEDS
66 #include <hp300/hp300/led.h>
67 #endif
68
69 #include <dev/ic/am7990reg.h>
70 #include <dev/ic/am7990var.h>
71
72 #include <hp300/dev/dioreg.h>
73 #include <hp300/dev/diovar.h>
74 #include <hp300/dev/diodevs.h>
75 #include <hp300/dev/if_lereg.h>
76 #include <hp300/dev/if_levar.h>
77
78 int lematch __P((struct device *, struct cfdata *, void *));
79 void leattach __P((struct device *, struct device *, void *));
80
81 struct cfattach le_ca = {
82 sizeof(struct le_softc), lematch, leattach
83 };
84
85 int leintr __P((void *));
86
87 /* offsets for: ID, REGS, MEM, NVRAM */
88 int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
89
90 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
91 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
92
93 hide void
94 lewrcsr(sc, port, val)
95 struct am7990_softc *sc;
96 u_int16_t port, val;
97 {
98 register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
99 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
100
101 do {
102 ler1->ler1_rap = port;
103 } while ((ler0->ler0_status & LE_ACK) == 0);
104 do {
105 ler1->ler1_rdp = val;
106 } while ((ler0->ler0_status & LE_ACK) == 0);
107 }
108
109 hide u_int16_t
110 lerdcsr(sc, port)
111 struct am7990_softc *sc;
112 u_int16_t port;
113 {
114 register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
115 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
116 u_int16_t val;
117
118 do {
119 ler1->ler1_rap = port;
120 } while ((ler0->ler0_status & LE_ACK) == 0);
121 do {
122 val = ler1->ler1_rdp;
123 } while ((ler0->ler0_status & LE_ACK) == 0);
124 return (val);
125 }
126
127 int
128 lematch(parent, match, aux)
129 struct device *parent;
130 struct cfdata *match;
131 void *aux;
132 {
133 struct dio_attach_args *da = aux;
134
135 if (da->da_id == DIO_DEVICE_ID_LAN)
136 return (1);
137 return (0);
138 }
139
140 /*
141 * Interface exists: make available by filling in network interface
142 * record. System will initialize the interface when it is ready
143 * to accept packets.
144 */
145 void
146 leattach(parent, self, aux)
147 struct device *parent, *self;
148 void *aux;
149 {
150 register struct lereg0 *ler0;
151 struct dio_attach_args *da = aux;
152 struct le_softc *lesc = (struct le_softc *)self;
153 caddr_t addr;
154 struct am7990_softc *sc = &lesc->sc_am7990;
155 char *cp;
156 int i, ipl;
157
158 addr = iomap(dio_scodetopa(da->da_scode), da->da_size);
159 if (addr == 0) {
160 printf("\n%s: can't map LANCE registers\n",
161 sc->sc_dev.dv_xname);
162 return;
163 }
164
165 ler0 = lesc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)addr);
166 ler0->ler0_id = 0xFF;
167 DELAY(100);
168
169 ipl = DIO_IPL(addr);
170 printf(" ipl %d", ipl);
171
172 lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)addr);
173 sc->sc_mem = (void *)(lestd[2] + (int)addr);
174 sc->sc_conf3 = LE_C3_BSWP;
175 sc->sc_addr = 0;
176 sc->sc_memsize = 16384;
177
178 /*
179 * Read the ethernet address off the board, one nibble at a time.
180 */
181 cp = (char *)(lestd[3] + (int)addr);
182 for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
183 sc->sc_enaddr[i] = (*++cp & 0xF) << 4;
184 cp++;
185 sc->sc_enaddr[i] |= *++cp & 0xF;
186 cp++;
187 }
188
189 sc->sc_copytodesc = am7990_copytobuf_contig;
190 sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
191 sc->sc_copytobuf = am7990_copytobuf_contig;
192 sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
193 sc->sc_zerobuf = am7990_zerobuf_contig;
194
195 sc->sc_rdcsr = lerdcsr;
196 sc->sc_wrcsr = lewrcsr;
197 sc->sc_hwinit = NULL;
198
199 am7990_config(sc);
200
201 /* Establish the interrupt handler. */
202 (void) isrlink(leintr, sc, ipl, ISRPRI_NET);
203 ler0->ler0_status = LE_IE;
204 }
205
206 int
207 leintr(arg)
208 void *arg;
209 {
210 struct am7990_softc *sc = arg;
211 u_int16_t isr;
212
213 #ifdef USELEDS
214 isr = lerdcsr(sc, LE_CSR0);
215
216 if ((isr & LE_C0_INTR) == 0)
217 return (0);
218
219 if (isr & LE_C0_RINT)
220 if (inledcontrol == 0)
221 ledcontrol(0, 0, LED_LANRCV);
222
223 if (isr & LE_C0_TINT)
224 if (inledcontrol == 0)
225 ledcontrol(0, 0, LED_LANXMT);
226 #endif /* USELEDS */
227
228 return (am7990_intr(sc));
229 }
230