if_le_isapnp.c revision 1.13 1 /* $NetBSD: if_le_isapnp.c,v 1.13 1998/07/05 06:49:14 jonathan 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) 1997 Jonathan Stone <jonathan (at) NetBSD.org> and
42 * Matthias Drochner. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Jonathan Stone.
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 #include "opt_inet.h"
71 #include "opt_ns.h"
72 #include "bpfilter.h"
73
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/mbuf.h>
77 #include <sys/socket.h>
78 #include <sys/ioctl.h>
79 #include <sys/errno.h>
80 #include <sys/syslog.h>
81 #include <sys/select.h>
82 #include <sys/device.h>
83
84 #include <net/if.h>
85 #include <net/if_dl.h>
86 #include <net/if_ether.h>
87 #include <net/if_media.h>
88
89 #ifdef INET
90 #include <netinet/in.h>
91 #include <netinet/in_systm.h>
92 #include <netinet/in_var.h>
93 #include <netinet/ip.h>
94 #endif
95
96 #ifdef NS
97 #include <netns/ns.h>
98 #include <netns/ns_if.h>
99 #endif
100
101 #if NBPFILTER > 0
102 #include <net/bpf.h>
103 #include <net/bpfdesc.h>
104 #endif
105
106 #include <machine/cpu.h>
107 #include <machine/bus.h>
108 #include <machine/intr.h>
109
110 #include <dev/isa/isavar.h>
111 #include <dev/isa/isadmavar.h>
112
113 #include <dev/isapnp/isapnpreg.h>
114 #include <dev/isapnp/isapnpvar.h>
115
116 #include <dev/ic/am7990reg.h>
117 #include <dev/ic/am7990var.h>
118 #include <dev/isapnp/if_levar.h>
119
120 int le_isapnp_match __P((struct device *, struct cfdata *, void *));
121 void le_isapnp_attach __P((struct device *, struct device *, void *));
122
123 struct cfattach le_isapnp_ca = {
124 sizeof(struct le_softc), le_isapnp_match, le_isapnp_attach
125 };
126
127 int le_isapnp_intredge __P((void *));
128 static void le_isapnp_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
129 static u_int16_t le_isapnp_rdcsr __P((struct am7990_softc *, u_int16_t));
130
131
132 /*
133 * Names accepted by the match routine.
134 */
135 static char *if_le_isapnp_devnames[] = {
136 "TKN0010",
137 0
138 };
139
140 #define LE_ISAPNP_MEMSIZE 16384
141
142 static void
143 le_isapnp_wrcsr(sc, port, val)
144 struct am7990_softc *sc;
145 u_int16_t port, val;
146 {
147 struct le_softc *lesc = (struct le_softc *)sc;
148 bus_space_tag_t iot = lesc->sc_iot;
149 bus_space_handle_t ioh = lesc->sc_ioh;
150
151 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
152 bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
153 }
154
155 static u_int16_t
156 le_isapnp_rdcsr(sc, port)
157 struct am7990_softc *sc;
158 u_int16_t port;
159 {
160 struct le_softc *lesc = (struct le_softc *)sc;
161 bus_space_tag_t iot = lesc->sc_iot;
162 bus_space_handle_t ioh = lesc->sc_ioh;
163 u_int16_t val;
164
165 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
166 val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
167 return (val);
168 }
169
170 int
171 le_isapnp_match(parent, match, aux)
172 struct device *parent;
173 struct cfdata *match;
174 void *aux;
175 {
176 struct isapnp_attach_args *ipa = aux;
177 char **card_name = &if_le_isapnp_devnames[0];
178
179 while (*card_name)
180 if(!strcmp(ipa->ipa_devlogic, *card_name++))
181 return(1);
182
183 return (0);
184 }
185
186 void
187 le_isapnp_attach(parent, self, aux)
188 struct device *parent, *self;
189 void *aux;
190 {
191 struct le_softc *lesc = (void *)self;
192 struct am7990_softc *sc = &lesc->sc_am7990;
193 struct isapnp_attach_args *ipa = aux;
194 bus_space_tag_t iot;
195 bus_space_handle_t ioh;
196 bus_dma_tag_t dmat;
197 bus_dma_segment_t seg;
198 int i, rseg, error;
199
200 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
201 printf("%s: error in region allocation\n",
202 sc->sc_dev.dv_xname);
203 return;
204 }
205
206 lesc->sc_iot = iot = ipa->ipa_iot;
207 lesc->sc_ioh = ioh = ipa->ipa_io[0].h;
208 lesc->sc_dmat = dmat = ipa->ipa_dmat;
209
210 lesc->sc_rap = PCNET_RAP;
211 lesc->sc_rdp = PCNET_RDP;
212
213 /*
214 * Extract the physical MAC address from the ROM.
215 */
216 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
217 sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, PCNET_SAPROM+i);
218
219 /*
220 * Allocate a DMA area for the card.
221 */
222 if (bus_dmamem_alloc(dmat, LE_ISAPNP_MEMSIZE, NBPG, 0, &seg, 1,
223 &rseg, BUS_DMA_NOWAIT)) {
224 printf("%s: couldn't allocate memory for card\n",
225 sc->sc_dev.dv_xname);
226 return;
227 }
228 if (bus_dmamem_map(dmat, &seg, rseg, LE_ISAPNP_MEMSIZE,
229 (caddr_t *)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
230 printf("%s: couldn't map memory for card\n",
231 sc->sc_dev.dv_xname);
232 return;
233 }
234
235 /*
236 * Create and load the DMA map for the DMA area.
237 */
238 if (bus_dmamap_create(dmat, LE_ISAPNP_MEMSIZE, 1,
239 LE_ISAPNP_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
240 printf("%s: couldn't create DMA map\n",
241 sc->sc_dev.dv_xname);
242 bus_dmamem_free(dmat, &seg, rseg);
243 return;
244 }
245 if (bus_dmamap_load(dmat, lesc->sc_dmam,
246 sc->sc_mem, LE_ISAPNP_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
247 printf("%s: coundn't load DMA map\n",
248 sc->sc_dev.dv_xname);
249 bus_dmamem_free(dmat, &seg, rseg);
250 return;
251 }
252
253 sc->sc_conf3 = 0;
254 sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
255 sc->sc_memsize = LE_ISAPNP_MEMSIZE;
256
257 sc->sc_copytodesc = am7990_copytobuf_contig;
258 sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
259 sc->sc_copytobuf = am7990_copytobuf_contig;
260 sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
261 sc->sc_zerobuf = am7990_zerobuf_contig;
262
263 sc->sc_rdcsr = le_isapnp_rdcsr;
264 sc->sc_wrcsr = le_isapnp_wrcsr;
265 sc->sc_hwinit = NULL;
266
267 if (ipa->ipa_ndrq > 0) {
268 if ((error = isa_dmacascade(ipa->ipa_ic,
269 ipa->ipa_drq[0].num)) != 0) {
270 printf("%s: unable to cascade DRQ, error = %d\n",
271 sc->sc_dev.dv_xname, error);
272 return;
273 }
274 }
275
276 lesc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
277 ipa->ipa_irq[0].type, IPL_NET, le_isapnp_intredge, sc);
278
279 printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
280 ipa->ipa_devclass);
281 am7990_config(sc);
282 }
283
284
285 /*
286 * Controller interrupt.
287 */
288 int
289 le_isapnp_intredge(arg)
290 void *arg;
291 {
292
293 if (am7990_intr(arg) == 0)
294 return (0);
295 for (;;)
296 if (am7990_intr(arg) == 0)
297 return (1);
298 }
299