if_cs_isa.c revision 1.3 1 /* $NetBSD: if_cs_isa.c,v 1.3 2000/12/26 09:42:21 mycroft 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/param.h>
37 #include <sys/systm.h>
38 #include <sys/socket.h>
39 #include <sys/device.h>
40
41 #include "rnd.h"
42 #if NRND > 0
43 #include <sys/rnd.h>
44 #endif
45
46 #include <net/if.h>
47 #include <net/if_ether.h>
48 #include <net/if_media.h>
49
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52
53 #include <dev/isa/isareg.h>
54 #include <dev/isa/isavar.h>
55 #include <dev/isa/isadmavar.h>
56
57 #include <dev/isa/cs89x0reg.h>
58 #include <dev/isa/cs89x0var.h>
59
60 int cs_isa_probe __P((struct device *, struct cfdata *, void *));
61 void cs_isa_attach __P((struct device *, struct device *, void *));
62
63 struct cfattach cs_isa_ca = {
64 sizeof(struct cs_softc), cs_isa_probe, cs_isa_attach
65 };
66
67 int
68 cs_isa_probe(parent, cf, aux)
69 struct device *parent;
70 struct cfdata *cf;
71 void *aux;
72 {
73 struct isa_attach_args *ia = aux;
74 bus_space_tag_t iot = ia->ia_iot;
75 bus_space_tag_t memt = ia->ia_memt;
76 bus_space_handle_t ioh, memh;
77 int rv = 0, have_io = 0, have_mem = 0;
78 u_int16_t isa_cfg, isa_membase;
79 bus_addr_t maddr = ia->ia_maddr;
80 int irq = ia->ia_irq;
81
82 /*
83 * Disallow wildcarded I/O base.
84 */
85 if (ia->ia_iobase == ISACF_PORT_DEFAULT)
86 return (0);
87
88 /*
89 * Map the I/O space.
90 */
91 if (bus_space_map(ia->ia_iot, ia->ia_iobase, CS8900_IOSIZE, 0, &ioh))
92 goto out;
93 have_io = 1;
94
95 /* Verify that it's a Crystal product. */
96 if (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_EISA_NUM) !=
97 EISA_NUM_CRYSTAL)
98 goto out;
99
100 /*
101 * Verify that it's a supported chip.
102 */
103 switch (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_PRODUCT_ID) &
104 PROD_ID_MASK) {
105 case PROD_ID_CS8900:
106 #ifdef notyet
107 case PROD_ID_CS8920:
108 case PROD_ID_CS8920M:
109 #endif
110 rv = 1;
111 }
112
113 /*
114 * If the IRQ or memory address were not specified, read the
115 * ISA_CFG EEPROM location.
116 */
117 if (maddr == ISACF_IOMEM_DEFAULT || irq == ISACF_IRQ_DEFAULT) {
118 if (cs_verify_eeprom(iot, ioh) == CS_ERROR) {
119 printf("cs_isa_probe: EEPROM bad or missing\n");
120 goto out;
121 }
122 if (cs_read_eeprom(iot, ioh, EEPROM_ISA_CFG, &isa_cfg)
123 == CS_ERROR) {
124 printf("cs_isa_probe: unable to read ISA_CFG\n");
125 goto out;
126 }
127 }
128
129 /*
130 * If the IRQ wasn't specified, get it from the EEPROM.
131 */
132 if (irq == ISACF_IRQ_DEFAULT) {
133 irq = isa_cfg & ISA_CFG_IRQ_MASK;
134 if (irq == 3)
135 irq = 5;
136 else
137 irq += 10;
138 }
139
140 /*
141 * If the memory address wasn't specified, get it from the EEPROM.
142 */
143 if (maddr == ISACF_IOMEM_DEFAULT) {
144 if ((isa_cfg & ISA_CFG_MEM_MODE) == 0) {
145 /* EEPROM says don't use memory mode. */
146 goto out;
147 }
148 if (cs_read_eeprom(iot, ioh, EEPROM_MEM_BASE, &isa_membase)
149 == CS_ERROR) {
150 printf("cs_isa_probe: unable to read MEM_BASE\n");
151 goto out;
152 }
153
154 isa_membase &= MEM_BASE_MASK;
155 maddr = (int)isa_membase << 8;
156 }
157
158 /*
159 * We now have a valid mem address; attempt to map it.
160 */
161 if (bus_space_map(ia->ia_memt, maddr, CS8900_MEMSIZE, 0, &memh)) {
162 /* Can't map it; fall back on i/o-only mode. */
163 printf("cs_isa_probe: unable to map memory space\n");
164 maddr = ISACF_IOMEM_DEFAULT;
165 } else
166 have_mem = 1;
167
168 out:
169 if (have_io)
170 bus_space_unmap(iot, ioh, CS8900_IOSIZE);
171 if (have_mem)
172 bus_space_unmap(memt, memh, CS8900_MEMSIZE);
173
174 if (rv) {
175 ia->ia_iosize = CS8900_IOSIZE;
176 ia->ia_maddr = maddr;
177 ia->ia_irq = irq;
178 if (ia->ia_maddr != ISACF_IOMEM_DEFAULT)
179 ia->ia_msize = CS8900_MEMSIZE;
180 }
181 return (rv);
182 }
183
184 void
185 cs_isa_attach(parent, self, aux)
186 struct device *parent, *self;
187 void *aux;
188 {
189 struct cs_softc *sc = (struct cs_softc *) self;
190 struct isa_attach_args *ia = aux;
191
192 sc->sc_ic = ia->ia_ic;
193 sc->sc_iot = ia->ia_iot;
194 sc->sc_memt = ia->ia_memt;
195
196 sc->sc_drq = ia->ia_drq;
197 sc->sc_irq = ia->ia_irq;
198
199 printf("\n");
200
201 /*
202 * Map the device.
203 */
204 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize,
205 0, &sc->sc_ioh)) {
206 printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
207 return;
208 }
209
210 /*
211 * Validate IRQ.
212 */
213 if (CS8900_IRQ_ISVALID(sc->sc_irq) == 0) {
214 printf("%s: invalid IRQ %d\n", sc->sc_dev.dv_xname, sc->sc_irq);
215 return;
216 }
217
218 /*
219 * Map the memory space if it was specified. If we can do this,
220 * we set ourselves up to use memory mode forever. Otherwise,
221 * we fall back on I/O mode.
222 */
223 if (ia->ia_maddr != ISACF_IOMEM_DEFAULT &&
224 ia->ia_msize == CS8900_MEMSIZE &&
225 CS8900_MEMBASE_ISVALID(ia->ia_maddr)) {
226 if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize,
227 0, &sc->sc_memh)) {
228 printf("%s: unable to map memory space\n",
229 sc->sc_dev.dv_xname);
230 } else {
231 sc->sc_cfgflags |= CFGFLG_MEM_MODE;
232 sc->sc_pktpgaddr = ia->ia_maddr;
233 }
234 }
235
236 sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
237 IPL_NET, cs_intr, sc);
238 if (sc->sc_ih == NULL) {
239 printf("%s: unable to establish interrupt\n",
240 sc->sc_dev.dv_xname);
241 return;
242 }
243
244 cs_attach(sc, NULL, NULL, 0, 0);
245 }
246