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