if_le_isapnp.c revision 1.2 1 /* $NetBSD: if_le_isapnp.c,v 1.2 1997/03/31 20:36:38 jonathan Exp $ */
2
3 /*
4 * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org> and
5 * Mattias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jonathan Stone.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "bpfilter.h"
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/mbuf.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
40 #include <sys/errno.h>
41 #include <sys/syslog.h>
42 #include <sys/select.h>
43 #include <sys/device.h>
44
45 #include <net/if.h>
46 #include <net/if_dl.h>
47 #include <net/if_ether.h>
48 #include <net/if_media.h>
49
50 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #endif
56
57 #ifdef NS
58 #include <netns/ns.h>
59 #include <netns/ns_if.h>
60 #endif
61
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #include <net/bpfdesc.h>
65 #endif
66
67 #include <machine/cpu.h>
68 #include <machine/bus.h>
69 #include <machine/intr.h>
70
71 #include <dev/isa/isavar.h>
72 #include <dev/isa/isadmavar.h>
73
74 #include <dev/isapnp/isapnpreg.h>
75 #include <dev/isapnp/isapnpvar.h>
76
77 #include <dev/ic/am7990reg.h>
78 #include <dev/ic/am7990var.h>
79 #include <dev/isapnp/if_levar.h>
80
81 #ifdef __alpha__ /* XXX */
82 /* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
83 #undef vtophys
84 #define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va))
85 #endif
86
87
88
89 #ifdef __BROKEN_INDIRECT_CONFIG
90 int le_isapnp_match __P((struct device *, void *, void *));
91 #else
92 int le_isapnp_match __P((struct device *, struct cfdata *, void *));
93 #endif
94 void le_isapnp_attach __P((struct device *, struct device *, void *));
95
96 struct cfattach ep_isapnp_ca = {
97 sizeof(struct le_softc), le_isapnp_match, le_isapnp_attach
98 };
99
100 int le_isapnp_intredge __P((void *));
101 static void le_isapnp_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
102 static u_int16_t le_isapnp_rdcsr __P((struct am7990_softc *, u_int16_t));
103
104
105 /*
106 * Names accepted by the match routine.
107 */
108 static char *if_le_isapnp_devnames[] = {
109 "TKN0010",
110 0
111 };
112
113
114 static void
115 le_isapnp_wrcsr(sc, port, val)
116 struct am7990_softc *sc;
117 u_int16_t port, val;
118 {
119 struct le_softc *lesc = (struct le_softc *)sc;
120 bus_space_tag_t iot = lesc->sc_iot;
121 bus_space_handle_t ioh = lesc->sc_ioh;
122
123 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
124 bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
125 }
126
127 static u_int16_t
128 le_isapnp_rdcsr(sc, port)
129 struct am7990_softc *sc;
130 u_int16_t port;
131 {
132 struct le_softc *lesc = (struct le_softc *)sc;
133 bus_space_tag_t iot = lesc->sc_iot;
134 bus_space_handle_t ioh = lesc->sc_ioh;
135 u_int16_t val;
136
137 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
138 val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
139 return (val);
140 }
141
142 int
143 le_isapnp_match(parent, match, aux)
144 struct device *parent;
145 #ifdef __BROKEN_INDIRECT_CONFIG
146 void *match;
147 #else
148 struct cfdata *match;
149 #endif
150 void *aux;
151 {
152 struct isapnp_attach_args *ipa = aux;
153 char **card_name = &if_le_isapnp_devnames[0];
154
155 while (*card_name)
156 if(!strcmp(ipa->ipa_devlogic, *card_name++))
157 return(1);
158
159 return (1);
160 }
161
162 void
163 le_isapnp_attach(parent, self, aux)
164 struct device *parent, *self;
165 void *aux;
166 {
167 struct le_softc *lesc = (void *)self;
168 struct am7990_softc *sc = &lesc->sc_am7990;
169 struct isapnp_attach_args *ipa = aux;
170 bus_space_tag_t iot;
171 bus_space_handle_t ioh;
172 int i;
173
174
175 lesc->sc_iot = iot = ipa->ipa_iot;
176 lesc->sc_ioh = ioh = ipa->ipa_io[0].h;
177
178 lesc->sc_rap = PCNET_RAP;
179 lesc->sc_rdp = PCNET_RDP;
180
181 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
182 printf("%s: error in region allocation\n",
183 sc->sc_dev.dv_xname);
184 return;
185 }
186
187 /*
188 * Extract the physical MAC address from the ROM.
189 */
190 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
191 sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, PCNET_SAPROM+i);
192
193 /* XXX SHOULD GET DMA-CAPABLE BUFFER SPACE */
194 sc->sc_mem = malloc(16384, M_DEVBUF, M_NOWAIT);
195 if (sc->sc_mem == 0) {
196 printf("%s: couldn't allocate memory for card\n",
197 sc->sc_dev.dv_xname);
198 return;
199 }
200
201 sc->sc_conf3 = 0;
202 sc->sc_addr = kvtop(sc->sc_mem); /* XXX XXX XXX !! */
203 sc->sc_memsize = 16384;
204
205 sc->sc_copytodesc = am7990_copytobuf_contig;
206 sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
207 sc->sc_copytobuf = am7990_copytobuf_contig;
208 sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
209 sc->sc_zerobuf = am7990_zerobuf_contig;
210
211 sc->sc_rdcsr = le_isapnp_rdcsr;
212 sc->sc_wrcsr = le_isapnp_wrcsr;
213 sc->sc_hwinit = NULL;
214
215 printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
216 ipa->ipa_devclass);
217 am7990_config(sc);
218
219 if (ipa->ipa_ndrq > 0)
220 isa_dmacascade(ipa->ipa_drq[0].num);
221
222 lesc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
223 IST_EDGE, IPL_NET, le_isapnp_intredge, sc);
224 }
225
226
227 /*
228 * Controller interrupt.
229 */
230 int
231 le_isapnp_intredge(arg)
232 void *arg;
233 {
234
235 if (am7990_intr(arg) == 0)
236 return (0);
237 for (;;)
238 if (am7990_intr(arg) == 0)
239 return (1);
240 }
241