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