1 /* $NetBSD: if_lc_isa.c,v 1.16 2002/10/02 03:10:48 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1994, 1995, 1997 Matt Thomas <matt@3am-software.com>
5 * 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. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*
28 * DEC EtherWORKS 3 Ethernet Controllers
29 *
30 * Written by Matt Thomas
31 *
32 * This driver supports the LEMAC (DE203, DE204, and DE205) cards.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.16 2002/10/02 03:10:48 thorpej Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/mbuf.h>
41 #include <sys/socket.h>
42 #include <sys/ioctl.h>
43 #include <sys/errno.h>
44 #include <sys/syslog.h>
45 #include <sys/select.h>
46 #include <sys/device.h>
47 #include <sys/queue.h>
48
49 #include <net/if.h>
50 #include <net/if_dl.h>
51 #include <net/if_ether.h>
52 #include <net/if_media.h>
53
54 #include <machine/cpu.h>
55 #include <machine/bus.h>
56 #include <machine/intr.h>
57
58 #include <dev/ic/lemacreg.h>
59 #include <dev/ic/lemacvar.h>
60
61 #include <dev/isa/isavar.h>
62
63 extern struct cfdriver lc_cd;
64
65 static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *,
66 int));
67 static int lemac_isa_probe __P((struct device *, struct cfdata *, void *));
68 static void lemac_isa_attach __P((struct device *, struct device *, void *));
69
70 CFATTACH_DECL(lc_isa, sizeof(lemac_softc_t),
71 lemac_isa_probe, lemac_isa_attach, NULL, NULL);
72
73 static int
74 lemac_isa_find(sc, ia, attach)
75 lemac_softc_t *sc;
76 struct isa_attach_args *ia;
77 int attach;
78 {
79 bus_addr_t maddr;
80 bus_addr_t msize;
81 int rv = 0, irq;
82
83 if (ia->ia_nio < 1)
84 return (0);
85 if (ia->ia_niomem < 1)
86 return (0);
87 if (ia->ia_nirq < 1)
88 return (0);
89
90 if (ISA_DIRECT_CONFIG(ia))
91 return (0);
92
93 /*
94 * Disallow wildcarded i/o addresses.
95 */
96 if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
97 return 0;
98
99 /*
100 * Make sure this is a valid LEMAC address.
101 */
102 if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1))
103 return 0;
104
105 sc->sc_iot = ia->ia_iot;
106
107 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0,
108 &sc->sc_ioh)) {
109 if (attach)
110 printf(": can't map i/o space\n");
111 return 0;
112 }
113
114 /*
115 * Read the Ethernet address from the EEPROM.
116 * It must start with one of the DEC OUIs and pass the
117 * DEC ethernet checksum test.
118 */
119 if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
120 goto outio;
121
122 /*
123 * Get information about memory space and attempt to map it.
124 */
125 lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq);
126
127 if (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT &&
128 ia->ia_iomem[0].ir_addr != maddr)
129 goto outio;
130
131 sc->sc_memt = ia->ia_memt;
132 if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) {
133 if (attach)
134 printf(": can't map mem space\n");
135 goto outio;
136 }
137
138
139 /*
140 * Double-check IRQ configuration.
141 */
142 if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
143 ia->ia_irq[0].ir_irq != irq)
144 printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname,
145 ia->ia_irq[0].ir_irq, irq);
146
147 if (attach) {
148 sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
149 if (sc->sc_ats == NULL)
150 printf("\n%s: warning: can't establish shutdown hook\n",
151 sc->sc_dv.dv_xname);
152
153 lemac_ifattach(sc);
154
155 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
156 IPL_NET, lemac_intr, sc);
157 }
158
159 /*
160 * I guess we've found one.
161 */
162 rv = 1;
163
164 ia->ia_nio = 1;
165 ia->ia_io[0].ir_size = LEMAC_IOSIZE;
166
167 ia->ia_niomem = 1;
168 ia->ia_iomem[0].ir_addr = maddr;
169 ia->ia_iomem[0].ir_size = msize;
170
171 ia->ia_nirq = 1;
172 ia->ia_irq[0].ir_irq = irq;
173
174 ia->ia_ndrq = 0;
175
176 if (rv == 0 || !attach)
177 bus_space_unmap(sc->sc_memt, sc->sc_memh, msize);
178 outio:
179 if (rv == 0 || !attach)
180 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
181 return rv;
182 }
183
184 static int
185 lemac_isa_probe(parent, match, aux)
186 struct device *parent;
187 struct cfdata *match;
188 void *aux;
189 {
190 struct isa_attach_args *ia = aux;
191 struct cfdata *cf = match;
192 lemac_softc_t sc;
193 (void)sprintf(sc.sc_dv.dv_xname, "%s%d", lc_cd.cd_name, cf->cf_unit);
194
195 return lemac_isa_find(&sc, ia, 0);
196 }
197
198 static void
199 lemac_isa_attach(parent, self, aux)
200 struct device *parent;
201 struct device *self;
202 void *aux;
203 {
204 lemac_softc_t *sc = (void *)self;
205 struct isa_attach_args *ia = aux;
206
207 (void) lemac_isa_find(sc, ia, 1);
208 }
Cache object: 50416b4b03e19bae39710d155662ddbe
|