if_le_lebuffer.c revision 1.2 1 /* $NetBSD: if_le_lebuffer.c,v 1.2 1998/08/15 10:51:20 mycroft Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
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 NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*-
41 * Copyright (c) 1996
42 * The President and Fellows of Harvard College. All rights reserved.
43 * Copyright (c) 1992, 1993
44 * The Regents of the University of California. All rights reserved.
45 *
46 * This code is derived from software contributed to Berkeley by
47 * Ralph Campbell and Rick Macklem.
48 *
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 * notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 * notice, this list of conditions and the following disclaimer in the
56 * documentation and/or other materials provided with the distribution.
57 * 3. All advertising materials mentioning features or use of this software
58 * must display the following acknowledgement:
59 * This product includes software developed by Aaron Brown and
60 * Harvard University.
61 * This product includes software developed by the University of
62 * California, Berkeley and its contributors.
63 * 4. Neither the name of the University nor the names of its contributors
64 * may be used to endorse or promote products derived from this software
65 * without specific prior written permission.
66 *
67 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 * SUCH DAMAGE.
78 *
79 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
80 */
81
82 #include "opt_inet.h"
83 #include "bpfilter.h"
84
85 #include <sys/param.h>
86 #include <sys/systm.h>
87 #include <sys/mbuf.h>
88 #include <sys/syslog.h>
89 #include <sys/socket.h>
90 #include <sys/device.h>
91 #include <sys/malloc.h>
92
93 #include <net/if.h>
94 #include <net/if_ether.h>
95 #include <net/if_media.h>
96
97 #ifdef INET
98 #include <netinet/in.h>
99 #include <netinet/if_inarp.h>
100 #endif
101
102 #include <machine/autoconf.h>
103 #include <machine/cpu.h>
104
105 #include <dev/sbus/sbusvar.h>
106 #include <dev/sbus/lebuffervar.h>
107
108 #include <dev/ic/lancereg.h>
109 #include <dev/ic/lancevar.h>
110 #include <dev/ic/am7990reg.h>
111 #include <dev/ic/am7990var.h>
112
113 /*
114 * LANCE registers.
115 */
116 struct lereg1 {
117 volatile u_int16_t ler1_rdp; /* data port */
118 volatile u_int16_t ler1_rap; /* register select port */
119 };
120
121 struct le_softc {
122 struct am7990_softc sc_am7990; /* glue to MI code */
123 struct sbusdev sc_sd; /* sbus device */
124 bus_space_tag_t sc_bustag;
125 bus_dma_tag_t sc_dmatag;
126 struct lereg1 *sc_r1; /* LANCE registers */
127 };
128
129
130 int lematch_lebuffer __P((struct device *, struct cfdata *, void *));
131 void leattach_lebuffer __P((struct device *, struct device *, void *));
132
133 /*
134 * Media types supported.
135 */
136 static int lemedia[] = {
137 IFM_ETHER|IFM_10_T,
138 };
139 #define NLEMEDIA (sizeof(lemedia) / sizeof(lemedia[0]))
140
141 struct cfattach le_lebuffer_ca = {
142 sizeof(struct le_softc), lematch_lebuffer, leattach_lebuffer
143 };
144
145 extern struct cfdriver le_cd;
146
147 #if defined(_KERNEL) && !defined(_LKM)
148 #include "opt_ddb.h"
149 #endif
150
151 #ifdef DDB
152 #define integrate
153 #define hide
154 #else
155 #define integrate static __inline
156 #define hide static
157 #endif
158
159 static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
160 static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
161
162 static void
163 lewrcsr(sc, port, val)
164 struct lance_softc *sc;
165 u_int16_t port, val;
166 {
167 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
168
169 ler1->ler1_rap = port;
170 ler1->ler1_rdp = val;
171
172 #if defined(SUN4M)
173 /*
174 * We need to flush the Sbus->Mbus write buffers. This can most
175 * easily be accomplished by reading back the register that we
176 * just wrote (thanks to Chris Torek for this solution).
177 */
178 if (CPU_ISSUN4M) {
179 volatile u_int16_t discard;
180 discard = ler1->ler1_rdp;
181 }
182 #endif
183 }
184
185 static u_int16_t
186 lerdcsr(sc, port)
187 struct lance_softc *sc;
188 u_int16_t port;
189 {
190 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
191 u_int16_t val;
192
193 ler1->ler1_rap = port;
194 val = ler1->ler1_rdp;
195 return (val);
196 }
197
198 int
199 lematch_lebuffer(parent, cf, aux)
200 struct device *parent;
201 struct cfdata *cf;
202 void *aux;
203 {
204 struct sbus_attach_args *sa = aux;
205
206 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
207 }
208
209
210 #define SAME_LANCE(bp, sa) \
211 ((bp->val[0] == sa->sa_slot && bp->val[1] == sa->sa_offset) || \
212 (bp->val[0] == -1 && bp->val[1] == sc->sc_dev.dv_unit))
213
214
215 void
216 leattach_lebuffer(parent, self, aux)
217 struct device *parent, *self;
218 void *aux;
219 {
220 struct sbus_attach_args *sa = aux;
221 struct le_softc *lesc = (struct le_softc *)self;
222 struct lance_softc *sc = &lesc->sc_am7990.lsc;
223 struct lebuf_softc *lebuf = (struct lebuf_softc *)parent;
224 bus_space_handle_t bh;
225 /* XXX the following declarations should be elsewhere */
226 extern void myetheraddr __P((u_char *));
227
228 lesc->sc_bustag = sa->sa_bustag;
229 lesc->sc_dmatag = sa->sa_dmatag;
230
231 if (bus_space_map2(sa->sa_bustag,
232 sa->sa_slot,
233 sa->sa_offset,
234 sizeof(struct lereg1),
235 BUS_SPACE_MAP_LINEAR,
236 0, &bh)) {
237 printf("%s @ lebuffer: cannot map registers\n", self->dv_xname);
238 return;
239 }
240 lesc->sc_r1 = (struct lereg1 *)bh;
241
242 sc->sc_mem = lebuf->sc_buffer;
243 sc->sc_memsize = lebuf->sc_bufsiz;
244 sc->sc_addr = 0; /* Lance view is offset by buffer location */
245 lebuf->attached = 1;
246
247 /* That old black magic... */
248 sc->sc_conf3 = getpropint(sa->sa_node, "busmaster-regval",
249 LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON);
250
251 /* Assume SBus is grandparent */
252 lesc->sc_sd.sd_reset = (void *)lance_reset;
253 sbus_establish(&lesc->sc_sd, parent);
254
255 if (sa->sa_bp != NULL && strcmp(sa->sa_bp->name, le_cd.cd_name) == 0 &&
256 SAME_LANCE(sa->sa_bp, sa))
257 sa->sa_bp->dev = &sc->sc_dev;
258
259 sc->sc_supmedia = lemedia;
260 sc->sc_nsupmedia = NLEMEDIA;
261 sc->sc_defaultmedia = lemedia[0];
262
263 myetheraddr(sc->sc_enaddr);
264
265 sc->sc_copytodesc = lance_copytobuf_contig;
266 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
267 sc->sc_copytobuf = lance_copytobuf_contig;
268 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
269 sc->sc_zerobuf = lance_zerobuf_contig;
270
271 sc->sc_rdcsr = lerdcsr;
272 sc->sc_wrcsr = lewrcsr;
273
274 am7990_config(&lesc->sc_am7990);
275
276 (void)bus_intr_establish(lesc->sc_bustag, sa->sa_pri, 0,
277 am7990_intr, sc);
278 }
279