if_le_obio.c revision 1.4 1 /* $NetBSD: if_le_obio.c,v 1.4 1998/08/15 10:51:16 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/ic/lancereg.h>
106 #include <dev/ic/lancevar.h>
107 #include <dev/ic/am7990reg.h>
108 #include <dev/ic/am7990var.h>
109
110 /*
111 * LANCE registers.
112 */
113 struct lereg1 {
114 volatile u_int16_t ler1_rdp; /* data port */
115 volatile u_int16_t ler1_rap; /* register select port */
116 };
117
118 struct le_softc {
119 struct am7990_softc sc_am7990; /* glue to MI code */
120 bus_space_tag_t sc_bustag;
121 bus_dma_tag_t sc_dmatag;
122 struct lereg1 *sc_r1; /* LANCE registers */
123 };
124
125 #define MEMSIZE 0x4000 /* LANCE memory size */
126
127 int lematch_obio __P((struct device *, struct cfdata *, void *));
128 void leattach_obio __P((struct device *, struct device *, void *));
129
130 /*
131 * Media types supported.
132 */
133 static int lemedia[] = {
134 IFM_ETHER|IFM_10_T,
135 };
136 #define NLEMEDIA (sizeof(lemedia) / sizeof(lemedia[0]))
137
138 struct cfattach le_obio_ca = {
139 sizeof(struct le_softc), lematch_obio, leattach_obio
140 };
141
142 extern struct cfdriver le_cd;
143
144 #if defined(_KERNEL) && !defined(_LKM)
145 #include "opt_ddb.h"
146 #endif
147
148 #ifdef DDB
149 #define integrate
150 #define hide
151 #else
152 #define integrate static __inline
153 #define hide static
154 #endif
155
156 static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
157 static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
158
159 static void
160 lewrcsr(sc, port, val)
161 struct lance_softc *sc;
162 u_int16_t port, val;
163 {
164 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
165
166 ler1->ler1_rap = port;
167 ler1->ler1_rdp = val;
168 }
169
170 static u_int16_t
171 lerdcsr(sc, port)
172 struct lance_softc *sc;
173 u_int16_t port;
174 {
175 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
176 u_int16_t val;
177
178 ler1->ler1_rap = port;
179 val = ler1->ler1_rdp;
180 return (val);
181 }
182
183 int
184 lematch_obio(parent, cf, aux)
185 struct device *parent;
186 struct cfdata *cf;
187 void *aux;
188 {
189 union obio_attach_args *uoba = aux;
190 struct obio4_attach_args *oba;
191
192 if (uoba->uoba_isobio4 == 0)
193 return (0);
194
195 oba = &uoba->uoba_oba4;
196 return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
197 2, /* probe size */
198 0, /* offset */
199 0, /* flags */
200 NULL, NULL));
201 }
202
203 void
204 leattach_obio(parent, self, aux)
205 struct device *parent, *self;
206 void *aux;
207 {
208 union obio_attach_args *uoba = aux;
209 struct obio4_attach_args *oba = &uoba->uoba_oba4;
210 struct le_softc *lesc = (struct le_softc *)self;
211 struct lance_softc *sc = &lesc->sc_am7990.lsc;
212 bus_space_handle_t bh;
213 bus_dma_segment_t seg;
214 int rseg;
215 /* XXX the following declarations should be elsewhere */
216 extern void myetheraddr __P((u_char *));
217
218 lesc->sc_bustag = oba->oba_bustag;
219 lesc->sc_dmatag = oba->oba_dmatag;
220
221 if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
222 0, sizeof(struct lereg1),
223 0, 0,
224 &bh) != 0) {
225 printf("%s @ obio: cannot map registers\n", self->dv_xname);
226 return;
227 }
228 lesc->sc_r1 = (struct lereg1 *)bh;
229
230 if (oba->oba_bp != NULL &&
231 strcmp(oba->oba_bp->name, le_cd.cd_name) == 0 &&
232 sc->sc_dev.dv_unit == oba->oba_bp->val[1])
233 oba->oba_bp->dev = &sc->sc_dev;
234
235
236 if (bus_dmamem_alloc(lesc->sc_dmatag, MEMSIZE, NBPG, 0,
237 &seg, 1, &rseg,
238 BUS_DMA_NOWAIT | BUS_DMA_24BIT) != 0) {
239 printf("%s @ obio: DMA memory allocation error\n",
240 self->dv_xname);
241 return;
242 }
243 if (bus_dmamem_map(lesc->sc_dmatag, &seg, rseg, MEMSIZE,
244 (caddr_t *)&sc->sc_mem,
245 BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0) {
246 printf("%s @ obio: DMA memory map error\n", self->dv_xname);
247 bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
248 return;
249 }
250 sc->sc_addr = seg.ds_addr & 0xffffff;
251 sc->sc_memsize = MEMSIZE;
252 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
253
254 sc->sc_supmedia = lemedia;
255 sc->sc_nsupmedia = NLEMEDIA;
256 sc->sc_defaultmedia = lemedia[0];
257
258 myetheraddr(sc->sc_enaddr);
259
260 sc->sc_copytodesc = lance_copytobuf_contig;
261 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
262 sc->sc_copytobuf = lance_copytobuf_contig;
263 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
264 sc->sc_zerobuf = lance_zerobuf_contig;
265
266 sc->sc_rdcsr = lerdcsr;
267 sc->sc_wrcsr = lewrcsr;
268
269 am7990_config(&lesc->sc_am7990);
270
271 /* Install interrupt */
272 (void)bus_intr_establish(lesc->sc_bustag, oba->oba_pri, 0,
273 am7990_intr, sc);
274 }
275