1 /* $NetBSD: if_tr_isa.c,v 1.11 2002/10/02 03:10:48 thorpej Exp $ */
2
3 /* XXXJRT changes isa_attach_args too early!! */
4
5 /*
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Onno van der Linden.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by The NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: if_tr_isa.c,v 1.11 2002/10/02 03:10:48 thorpej Exp $");
43
44 #undef TRISADEBUG
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/socket.h>
49 #include <sys/device.h>
50
51 #include <net/if.h>
52 #include <net/if_ether.h>
53 #include <net/if_media.h>
54
55 #include <machine/cpu.h>
56 #include <machine/bus.h>
57 #include <machine/intr.h>
58
59 #include <dev/isa/isavar.h>
60
61 #include <dev/ic/tropicreg.h>
62 #include <dev/ic/tropicvar.h>
63
64
65 int tr_isa_probe __P((struct device *, struct cfdata *, void *));
66 int trtcm_isa_probe __P((struct device *, struct cfdata *, void *));
67 int tribm_isa_probe __P((struct device *, struct cfdata *, void *));
68 void tr_isa_attach __P((struct device *, struct device *, void *));
69 int tr_isa_map_io __P((struct isa_attach_args *, bus_space_handle_t *,
70 bus_space_handle_t *));
71 void tr_isa_unmap_io __P((struct isa_attach_args *, bus_space_handle_t,
72 bus_space_handle_t));
73 int trtcm_isa_mediachange __P((struct tr_softc *));
74 void trtcm_isa_mediastatus __P((struct tr_softc *, struct ifmediareq *));
75 #ifdef TRISADEBUG
76 void tr_isa_dumpaip __P((bus_space_tag_t, bus_space_handle_t));
77 #endif
78
79 /*
80 * List of manufacturer specific probe routines. Order is important.
81 */
82 int (*tr_isa_probe_list[])(struct device *, struct cfdata *, void *) = {
83 trtcm_isa_probe,
84 tribm_isa_probe,
85 0
86 };
87
88 CFATTACH_DECL(tr_isa, sizeof(struct tr_softc),
89 tr_isa_probe, tr_isa_attach, NULL, NULL);
90
91 int
92 tr_isa_map_io(ia, pioh, mmioh)
93 struct isa_attach_args *ia;
94 bus_space_handle_t *pioh, *mmioh;
95 {
96 bus_size_t mmio;
97 u_int8_t s;
98
99 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
100 ia->ia_io[0].ir_size, 0, pioh)) {
101 printf("tr_isa_map_io: can't map PIO ports\n");
102 return 1;
103 }
104
105 /* Read adapter switches and calculate addresses of MMIO. */
106 s = bus_space_read_1(ia->ia_iot, *pioh, TR_SWITCH);
107
108 if ((s & 0xfc) < ((TR_MMIO_MINADDR - TR_MMIO_OFFSET) >> 11) ||
109 (s & 0xfc) > ((TR_MMIO_MAXADDR - TR_MMIO_OFFSET) >> 11)) {
110 bus_space_unmap(ia->ia_iot, *pioh, ia->ia_io[0].ir_size);
111 return 1;
112 }
113
114 mmio = ((s & 0xfc) << 11) + TR_MMIO_OFFSET;
115 if (bus_space_map(ia->ia_memt, mmio, TR_MMIO_SIZE, 0, mmioh)) {
116 printf("tr_isa_map_io: can't map MMIO region 0x%05lx/%d\n",
117 mmio, TR_MMIO_SIZE);
118 bus_space_unmap(ia->ia_iot, *pioh, ia->ia_io[0].ir_size);
119 return 1;
120 }
121 return 0;
122 }
123
124 void
125 tr_isa_unmap_io(ia, pioh, mmioh)
126 struct isa_attach_args *ia;
127 bus_space_handle_t pioh, mmioh;
128 {
129 bus_space_unmap(ia->ia_memt, mmioh, TR_MMIO_SIZE);
130 bus_space_unmap(ia->ia_iot, pioh, ia->ia_io[0].ir_size);
131 }
132
133 static u_char tr_isa_id[] = {
134 5, 0, 4, 9, 4, 3, 4, 15, 3, 6, 3, 1, 3, 1, 3, 0, 3, 9, 3, 9, 3, 0, 2, 0
135 };
136
137 /*
138 * XXX handle multiple IBM TR cards (sram mapping !!)
139 */
140
141 int
142 tr_isa_probe(parent, match, aux)
143 struct device *parent;
144 struct cfdata *match;
145 void *aux;
146 {
147 struct isa_attach_args *ia = aux;
148 int i;
149 bus_size_t tr_id;
150 bus_space_handle_t sramh, pioh, mmioh;
151 int probecode;
152 int matched = 0;
153
154 if (ia->ia_nio < 1)
155 return (0);
156 if (ia->ia_niomem < 1)
157 return (0);
158 if (ia->ia_nirq < 1)
159 return (0);
160
161 if (ISA_DIRECT_CONFIG(ia))
162 return (0);
163
164 for (i = 0; tr_isa_probe_list[i] != 0; i++) {
165 probecode = tr_isa_probe_list[i](parent, match, aux);
166 if (probecode < 0)
167 return 0; /* Fail instantly. */
168 if (probecode > 0)
169 break; /* We have a match. */
170 }
171 if (tr_isa_probe_list[i] == 0)
172 return 0; /* Nothing matched. */
173 if (tr_isa_map_io(ia, &pioh, &mmioh))
174 return 0;
175 tr_id = TR_ID_OFFSET;
176 matched = 1;
177 for (i = 0; i < sizeof(tr_isa_id); i++) {
178 if (bus_space_read_1(ia->ia_memt, mmioh, tr_id) !=
179 tr_isa_id[i])
180 matched = 0;
181 tr_id += 2;
182 }
183 #ifdef TRISADEBUG
184 tr_isa_dumpaip(ia->ia_memt, mmioh);
185 #endif
186 tr_isa_unmap_io(ia, pioh, mmioh);
187 if (!matched) {
188 return 0;
189 }
190 if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
191 ia->ia_iomem[0].ir_size, 0, &sramh)) {
192 printf("tr_isa_probe: can't map shared ram\n");
193 return 0;
194 }
195 bus_space_unmap(ia->ia_memt, sramh, ia->ia_iomem[0].ir_size);
196
197 ia->ia_nio = 1;
198 ia->ia_niomem = 1;
199 ia->ia_nirq = 1;
200
201 ia->ia_ndrq = 0;
202
203 return 1;
204 }
205
206 int trtcm_setspeed(struct tr_softc *, int);
207
208 void
209 tr_isa_attach(parent, self, aux)
210 struct device *parent, *self;
211 void *aux;
212 {
213 struct tr_softc *sc = (void *) self;
214 struct isa_attach_args *ia = aux;
215
216 printf("\n");
217
218 sc->sc_piot = ia->ia_iot;
219 sc->sc_memt = ia->ia_memt;
220 if (tr_isa_map_io(ia, &sc->sc_pioh, &sc->sc_mmioh)) {
221 printf("tr_isa_attach: IO space vanished\n");
222 return;
223 }
224 if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr,
225 ia->ia_iomem[0].ir_size, 0, &sc->sc_sramh)) {
226 printf("tr_isa_attach: shared ram space vanished\n");
227 return;
228 }
229 /* set ACA offset */
230 sc->sc_aca = TR_ACA_OFFSET;
231 sc->sc_memwinsz = ia->ia_iomem[0].ir_size;
232 sc->sc_maddr = ia->ia_iomem[0].ir_addr;
233 /*
234 * Determine total RAM on adapter and decide how much to use.
235 * XXX Since we don't use RAM paging, use sc_memwinsz for now.
236 */
237 sc->sc_memsize = sc->sc_memwinsz;
238 sc->sc_memreserved = 0;
239
240 if (tr_reset(sc) != 0)
241 return;
242
243 if (ia->ia_aux != NULL) {
244 sc->sc_mediastatus = trtcm_isa_mediastatus;
245 sc->sc_mediachange = trtcm_isa_mediachange;
246 }
247 else {
248 sc->sc_mediastatus = NULL;
249 sc->sc_mediachange = NULL;
250 }
251
252 if (tr_attach(sc) != 0)
253 return;
254
255 /*
256 * XXX 3Com 619 can use LEVEL intr
257 */
258 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
259 IST_EDGE, IPL_NET, tr_intr, sc);
260 }
261
262 #ifdef TRISADEBUG
263 /*
264 * Dump the adapters AIP
265 */
266 void
267 tr_isa_dumpaip(memt, mmioh)
268 bus_space_tag_t memt;
269 bus_space_handle_t mmioh;
270 {
271 unsigned int off, val;
272 printf("AIP contents:");
273 for (off=0; off < 256; off++) {
274 val = bus_space_read_1(memt, mmioh, TR_MAC_OFFSET + off);
275 if ((off % 16) == 0)
276 printf("\n");
277 printf("%02x ", val);
278 }
279 printf("\n");
280 }
281 #endif
Cache object: f1eedaa68dc7e489e6320da7937fce78
|