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