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