if_cs_isa.c revision 1.4 1 /* $NetBSD: if_cs_isa.c,v 1.4 2001/11/13 08:01:16 lukem Exp $ */
2
3 /*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
23 *
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_cs_isa.c,v 1.4 2001/11/13 08:01:16 lukem Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/socket.h>
42 #include <sys/device.h>
43
44 #include "rnd.h"
45 #if NRND > 0
46 #include <sys/rnd.h>
47 #endif
48
49 #include <net/if.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
52
53 #include <machine/bus.h>
54 #include <machine/intr.h>
55
56 #include <dev/isa/isareg.h>
57 #include <dev/isa/isavar.h>
58 #include <dev/isa/isadmavar.h>
59
60 #include <dev/isa/cs89x0reg.h>
61 #include <dev/isa/cs89x0var.h>
62
63 int cs_isa_probe __P((struct device *, struct cfdata *, void *));
64 void cs_isa_attach __P((struct device *, struct device *, void *));
65
66 struct cfattach cs_isa_ca = {
67 sizeof(struct cs_softc), cs_isa_probe, cs_isa_attach
68 };
69
70 int
71 cs_isa_probe(parent, cf, aux)
72 struct device *parent;
73 struct cfdata *cf;
74 void *aux;
75 {
76 struct isa_attach_args *ia = aux;
77 bus_space_tag_t iot = ia->ia_iot;
78 bus_space_tag_t memt = ia->ia_memt;
79 bus_space_handle_t ioh, memh;
80 int rv = 0, have_io = 0, have_mem = 0;
81 u_int16_t isa_cfg, isa_membase;
82 bus_addr_t maddr = ia->ia_maddr;
83 int irq = ia->ia_irq;
84
85 /*
86 * Disallow wildcarded I/O base.
87 */
88 if (ia->ia_iobase == ISACF_PORT_DEFAULT)
89 return (0);
90
91 /*
92 * Map the I/O space.
93 */
94 if (bus_space_map(ia->ia_iot, ia->ia_iobase, CS8900_IOSIZE, 0, &ioh))
95 goto out;
96 have_io = 1;
97
98 /* Verify that it's a Crystal product. */
99 if (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_EISA_NUM) !=
100 EISA_NUM_CRYSTAL)
101 goto out;
102
103 /*
104 * Verify that it's a supported chip.
105 */
106 switch (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_PRODUCT_ID) &
107 PROD_ID_MASK) {
108 case PROD_ID_CS8900:
109 #ifdef notyet
110 case PROD_ID_CS8920:
111 case PROD_ID_CS8920M:
112 #endif
113 rv = 1;
114 }
115
116 /*
117 * If the IRQ or memory address were not specified, read the
118 * ISA_CFG EEPROM location.
119 */
120 if (maddr == ISACF_IOMEM_DEFAULT || irq == ISACF_IRQ_DEFAULT) {
121 if (cs_verify_eeprom(iot, ioh) == CS_ERROR) {
122 printf("cs_isa_probe: EEPROM bad or missing\n");
123 goto out;
124 }
125 if (cs_read_eeprom(iot, ioh, EEPROM_ISA_CFG, &isa_cfg)
126 == CS_ERROR) {
127 printf("cs_isa_probe: unable to read ISA_CFG\n");
128 goto out;
129 }
130 }
131
132 /*
133 * If the IRQ wasn't specified, get it from the EEPROM.
134 */
135 if (irq == ISACF_IRQ_DEFAULT) {
136 irq = isa_cfg & ISA_CFG_IRQ_MASK;
137 if (irq == 3)
138 irq = 5;
139 else
140 irq += 10;
141 }
142
143 /*
144 * If the memory address wasn't specified, get it from the EEPROM.
145 */
146 if (maddr == ISACF_IOMEM_DEFAULT) {
147 if ((isa_cfg & ISA_CFG_MEM_MODE) == 0) {
148 /* EEPROM says don't use memory mode. */
149 goto out;
150 }
151 if (cs_read_eeprom(iot, ioh, EEPROM_MEM_BASE, &isa_membase)
152 == CS_ERROR) {
153 printf("cs_isa_probe: unable to read MEM_BASE\n");
154 goto out;
155 }
156
157 isa_membase &= MEM_BASE_MASK;
158 maddr = (int)isa_membase << 8;
159 }
160
161 /*
162 * We now have a valid mem address; attempt to map it.
163 */
164 if (bus_space_map(ia->ia_memt, maddr, CS8900_MEMSIZE, 0, &memh)) {
165 /* Can't map it; fall back on i/o-only mode. */
166 printf("cs_isa_probe: unable to map memory space\n");
167 maddr = ISACF_IOMEM_DEFAULT;
168 } else
169 have_mem = 1;
170
171 out:
172 if (have_io)
173 bus_space_unmap(iot, ioh, CS8900_IOSIZE);
174 if (have_mem)
175 bus_space_unmap(memt, memh, CS8900_MEMSIZE);
176
177 if (rv) {
178 ia->ia_iosize = CS8900_IOSIZE;
179 ia->ia_maddr = maddr;
180 ia->ia_irq = irq;
181 if (ia->ia_maddr != ISACF_IOMEM_DEFAULT)
182 ia->ia_msize = CS8900_MEMSIZE;
183 }
184 return (rv);
185 }
186
187 void
188 cs_isa_attach(parent, self, aux)
189 struct device *parent, *self;
190 void *aux;
191 {
192 struct cs_softc *sc = (struct cs_softc *) self;
193 struct isa_attach_args *ia = aux;
194
195 sc->sc_ic = ia->ia_ic;
196 sc->sc_iot = ia->ia_iot;
197 sc->sc_memt = ia->ia_memt;
198
199 sc->sc_drq = ia->ia_drq;
200 sc->sc_irq = ia->ia_irq;
201
202 printf("\n");
203
204 /*
205 * Map the device.
206 */
207 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize,
208 0, &sc->sc_ioh)) {
209 printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
210 return;
211 }
212
213 /*
214 * Validate IRQ.
215 */
216 if (CS8900_IRQ_ISVALID(sc->sc_irq) == 0) {
217 printf("%s: invalid IRQ %d\n", sc->sc_dev.dv_xname, sc->sc_irq);
218 return;
219 }
220
221 /*
222 * Map the memory space if it was specified. If we can do this,
223 * we set ourselves up to use memory mode forever. Otherwise,
224 * we fall back on I/O mode.
225 */
226 if (ia->ia_maddr != ISACF_IOMEM_DEFAULT &&
227 ia->ia_msize == CS8900_MEMSIZE &&
228 CS8900_MEMBASE_ISVALID(ia->ia_maddr)) {
229 if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize,
230 0, &sc->sc_memh)) {
231 printf("%s: unable to map memory space\n",
232 sc->sc_dev.dv_xname);
233 } else {
234 sc->sc_cfgflags |= CFGFLG_MEM_MODE;
235 sc->sc_pktpgaddr = ia->ia_maddr;
236 }
237 }
238
239 sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
240 IPL_NET, cs_intr, sc);
241 if (sc->sc_ih == NULL) {
242 printf("%s: unable to establish interrupt\n",
243 sc->sc_dev.dv_xname);
244 return;
245 }
246
247 cs_attach(sc, NULL, NULL, 0, 0);
248 }
249