if_lc_isa.c revision 1.34 1 1.34 chs /* $NetBSD: if_lc_isa.c,v 1.34 2012/10/27 17:18:24 chs 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.34 chs __KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.34 2012/10/27 17:18:24 chs 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.28 ad #include <sys/cpu.h>
55 1.28 ad #include <sys/bus.h>
56 1.28 ad #include <sys/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.34 chs static int lemac_isa_find(lemac_softc_t *, const char *, struct isa_attach_args *, int);
66 1.33 cegger static int lemac_isa_probe(device_t, cfdata_t, void *);
67 1.33 cegger static void lemac_isa_attach(device_t, device_t, void *);
68 1.6 christos
69 1.34 chs CFATTACH_DECL_NEW(lc_isa, sizeof(lemac_softc_t),
70 1.16 thorpej lemac_isa_probe, lemac_isa_attach, NULL, NULL);
71 1.6 christos
72 1.6 christos static int
73 1.34 chs lemac_isa_find(lemac_softc_t *sc, const char *xname, struct isa_attach_args *ia, int attach)
74 1.6 christos {
75 1.6 christos bus_addr_t maddr;
76 1.30 bouyer bus_size_t msiz;
77 1.6 christos int rv = 0, irq;
78 1.6 christos
79 1.13 thorpej if (ia->ia_nio < 1)
80 1.13 thorpej return (0);
81 1.13 thorpej if (ia->ia_niomem < 1)
82 1.13 thorpej return (0);
83 1.13 thorpej if (ia->ia_nirq < 1)
84 1.13 thorpej return (0);
85 1.13 thorpej
86 1.13 thorpej if (ISA_DIRECT_CONFIG(ia))
87 1.13 thorpej return (0);
88 1.13 thorpej
89 1.6 christos /*
90 1.6 christos * Disallow wildcarded i/o addresses.
91 1.6 christos */
92 1.19 drochner if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
93 1.6 christos return 0;
94 1.6 christos
95 1.6 christos /*
96 1.6 christos * Make sure this is a valid LEMAC address.
97 1.6 christos */
98 1.13 thorpej if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1))
99 1.6 christos return 0;
100 1.6 christos
101 1.6 christos sc->sc_iot = ia->ia_iot;
102 1.6 christos
103 1.13 thorpej if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0,
104 1.6 christos &sc->sc_ioh)) {
105 1.6 christos if (attach)
106 1.6 christos printf(": can't map i/o space\n");
107 1.6 christos return 0;
108 1.6 christos }
109 1.6 christos
110 1.6 christos /*
111 1.6 christos * Read the Ethernet address from the EEPROM.
112 1.6 christos * It must start with one of the DEC OUIs and pass the
113 1.6 christos * DEC ethernet checksum test.
114 1.6 christos */
115 1.6 christos if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
116 1.6 christos goto outio;
117 1.6 christos
118 1.6 christos /*
119 1.6 christos * Get information about memory space and attempt to map it.
120 1.6 christos */
121 1.22 christos lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msiz, &irq);
122 1.6 christos
123 1.19 drochner if (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM &&
124 1.13 thorpej ia->ia_iomem[0].ir_addr != maddr)
125 1.6 christos goto outio;
126 1.6 christos
127 1.18 mycroft if (attach) {
128 1.22 christos if (msiz == 0) {
129 1.18 mycroft printf(": memory configuration is invalid\n");
130 1.18 mycroft goto outio;
131 1.18 mycroft }
132 1.18 mycroft
133 1.18 mycroft sc->sc_memt = ia->ia_memt;
134 1.22 christos if (bus_space_map(ia->ia_memt, maddr, msiz, 0, &sc->sc_memh)) {
135 1.6 christos printf(": can't map mem space\n");
136 1.18 mycroft goto outio;
137 1.18 mycroft }
138 1.6 christos }
139 1.6 christos
140 1.6 christos /*
141 1.6 christos * Double-check IRQ configuration.
142 1.6 christos */
143 1.19 drochner if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
144 1.13 thorpej ia->ia_irq[0].ir_irq != irq)
145 1.34 chs printf("%s: overriding IRQ %d to %d\n", xname,
146 1.13 thorpej ia->ia_irq[0].ir_irq, irq);
147 1.6 christos
148 1.6 christos if (attach) {
149 1.6 christos sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
150 1.29 cegger if (sc->sc_ats == NULL) {
151 1.29 cegger aprint_normal("\n");
152 1.34 chs aprint_error("%s: warning: can't establish shutdown hook\n", xname);
153 1.29 cegger }
154 1.6 christos
155 1.6 christos lemac_ifattach(sc);
156 1.6 christos
157 1.6 christos sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
158 1.6 christos IPL_NET, lemac_intr, sc);
159 1.6 christos }
160 1.6 christos
161 1.6 christos /*
162 1.6 christos * I guess we've found one.
163 1.6 christos */
164 1.6 christos rv = 1;
165 1.6 christos
166 1.13 thorpej ia->ia_nio = 1;
167 1.13 thorpej ia->ia_io[0].ir_size = LEMAC_IOSIZE;
168 1.13 thorpej
169 1.13 thorpej ia->ia_niomem = 1;
170 1.13 thorpej ia->ia_iomem[0].ir_addr = maddr;
171 1.22 christos ia->ia_iomem[0].ir_size = msiz;
172 1.13 thorpej
173 1.13 thorpej ia->ia_nirq = 1;
174 1.13 thorpej ia->ia_irq[0].ir_irq = irq;
175 1.13 thorpej
176 1.13 thorpej ia->ia_ndrq = 0;
177 1.6 christos
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.33 cegger lemac_isa_probe(device_t parent, cfdata_t match, void *aux)
186 1.1 matt {
187 1.6 christos struct isa_attach_args *ia = aux;
188 1.32 cegger cfdata_t cf = match;
189 1.6 christos lemac_softc_t sc;
190 1.34 chs char xname[16];
191 1.21 perry
192 1.34 chs snprintf(xname, sizeof(xname), "%s%d", lc_cd.cd_name, cf->cf_unit);
193 1.34 chs
194 1.34 chs return lemac_isa_find(&sc, xname, ia, 0);
195 1.1 matt }
196 1.1 matt
197 1.1 matt static void
198 1.33 cegger lemac_isa_attach(device_t parent, device_t self, void *aux)
199 1.1 matt {
200 1.34 chs lemac_softc_t *sc = device_private(self);
201 1.6 christos struct isa_attach_args *ia = aux;
202 1.1 matt
203 1.34 chs sc->sc_dev = self;
204 1.34 chs (void) lemac_isa_find(sc, device_xname(self), ia, 1);
205 1.1 matt }
206