if_lc_isa.c revision 1.6 1 1.6 christos /* $NetBSD: if_lc_isa.c,v 1.6 1997/11/30 20:03:15 christos 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.1 matt * derived from this software withough 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.1 matt
35 1.1 matt #include "bpfilter.h"
36 1.1 matt
37 1.1 matt #include <sys/param.h>
38 1.1 matt #include <sys/systm.h>
39 1.1 matt #include <sys/mbuf.h>
40 1.1 matt #include <sys/socket.h>
41 1.1 matt #include <sys/ioctl.h>
42 1.1 matt #include <sys/errno.h>
43 1.1 matt #include <sys/syslog.h>
44 1.1 matt #include <sys/select.h>
45 1.1 matt #include <sys/device.h>
46 1.1 matt #include <sys/queue.h>
47 1.1 matt
48 1.1 matt #include <net/if.h>
49 1.1 matt #include <net/if_dl.h>
50 1.1 matt #include <net/if_ether.h>
51 1.1 matt #include <net/if_media.h>
52 1.1 matt
53 1.1 matt
54 1.1 matt #ifdef INET
55 1.1 matt #include <netinet/in.h>
56 1.1 matt #include <netinet/in_systm.h>
57 1.1 matt #include <netinet/in_var.h>
58 1.1 matt #include <netinet/ip.h>
59 1.1 matt #include <netinet/if_inarp.h>
60 1.1 matt #endif
61 1.1 matt
62 1.1 matt #ifdef NS
63 1.1 matt #include <netns/ns.h>
64 1.1 matt #include <netns/ns_if.h>
65 1.1 matt #endif
66 1.1 matt
67 1.1 matt #if NBPFILTER > 0
68 1.1 matt #include <net/bpf.h>
69 1.1 matt #include <net/bpfdesc.h>
70 1.1 matt #endif
71 1.1 matt
72 1.1 matt #include <machine/cpu.h>
73 1.1 matt #include <machine/bus.h>
74 1.1 matt #include <machine/intr.h>
75 1.1 matt
76 1.1 matt #include <dev/ic/lemacreg.h>
77 1.1 matt #include <dev/ic/lemacvar.h>
78 1.1 matt
79 1.1 matt #include <dev/isa/isavar.h>
80 1.1 matt
81 1.5 thorpej extern struct cfdriver lc_cd;
82 1.5 thorpej
83 1.6 christos static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *,
84 1.6 christos int));
85 1.6 christos #ifdef __BROKEN_INDIRECT_CONFIG
86 1.6 christos static int lemac_isa_probe __P((struct device *, void *, void *));
87 1.6 christos #else
88 1.6 christos static int lemac_isa_probe __P((struct device *, struct cfdata *, void *));
89 1.6 christos #endif
90 1.6 christos static void lemac_isa_attach __P((struct device *, struct device *, void *));
91 1.6 christos
92 1.6 christos struct cfattach lc_isa_ca = {
93 1.6 christos sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach
94 1.6 christos };
95 1.6 christos
96 1.6 christos static int
97 1.6 christos lemac_isa_find(sc, ia, attach)
98 1.6 christos lemac_softc_t *sc;
99 1.6 christos struct isa_attach_args *ia;
100 1.6 christos int attach;
101 1.6 christos {
102 1.6 christos bus_addr_t maddr;
103 1.6 christos bus_addr_t msize;
104 1.6 christos int rv = 0, irq;
105 1.6 christos
106 1.6 christos /*
107 1.6 christos * Disallow wildcarded i/o addresses.
108 1.6 christos */
109 1.6 christos if (ia->ia_iobase == IOBASEUNK)
110 1.6 christos return 0;
111 1.6 christos
112 1.6 christos /*
113 1.6 christos * Make sure this is a valid LEMAC address.
114 1.6 christos */
115 1.6 christos if (ia->ia_iobase & (LEMAC_IOSIZE - 1))
116 1.6 christos return 0;
117 1.6 christos
118 1.6 christos sc->sc_iot = ia->ia_iot;
119 1.6 christos
120 1.6 christos /*
121 1.6 christos * Map the LEMAC's port space for the probe sequence.
122 1.6 christos */
123 1.6 christos ia->ia_iosize = LEMAC_IOSIZE;
124 1.6 christos
125 1.6 christos if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0,
126 1.6 christos &sc->sc_ioh)) {
127 1.6 christos if (attach)
128 1.6 christos printf(": can't map i/o space\n");
129 1.6 christos return 0;
130 1.6 christos }
131 1.6 christos
132 1.6 christos /*
133 1.6 christos * Read the Ethernet address from the EEPROM.
134 1.6 christos * It must start with one of the DEC OUIs and pass the
135 1.6 christos * DEC ethernet checksum test.
136 1.6 christos */
137 1.6 christos if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
138 1.6 christos goto outio;
139 1.6 christos
140 1.6 christos /*
141 1.6 christos * Get information about memory space and attempt to map it.
142 1.6 christos */
143 1.6 christos lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq);
144 1.6 christos
145 1.6 christos if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK)
146 1.6 christos goto outio;
147 1.6 christos
148 1.6 christos sc->sc_memt = ia->ia_memt;
149 1.6 christos if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) {
150 1.6 christos if (attach)
151 1.6 christos printf(": can't map mem space\n");
152 1.6 christos goto outio;
153 1.6 christos }
154 1.6 christos
155 1.6 christos
156 1.6 christos /*
157 1.6 christos * Double-check IRQ configuration.
158 1.6 christos */
159 1.6 christos if (ia->ia_irq != irq && ia->ia_irq != IRQUNK)
160 1.6 christos printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname,
161 1.6 christos ia->ia_irq, irq);
162 1.6 christos
163 1.6 christos if (attach) {
164 1.6 christos sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
165 1.6 christos if (sc->sc_ats == NULL)
166 1.6 christos printf("\n%s: warning: can't establish shutdown hook\n",
167 1.6 christos sc->sc_dv.dv_xname);
168 1.6 christos
169 1.6 christos lemac_ifattach(sc);
170 1.6 christos
171 1.6 christos sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
172 1.6 christos IPL_NET, lemac_intr, sc);
173 1.6 christos }
174 1.6 christos
175 1.6 christos /*
176 1.6 christos * I guess we've found one.
177 1.6 christos */
178 1.6 christos rv = 1;
179 1.6 christos
180 1.6 christos ia->ia_maddr = maddr;
181 1.6 christos ia->ia_msize = msize;
182 1.6 christos ia->ia_irq = irq;
183 1.6 christos
184 1.6 christos if (rv == 0 || !attach)
185 1.6 christos bus_space_unmap(sc->sc_memt, sc->sc_memh, msize);
186 1.6 christos outio:
187 1.6 christos if (rv == 0 || !attach)
188 1.6 christos bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
189 1.6 christos return rv;
190 1.6 christos }
191 1.6 christos
192 1.1 matt static int
193 1.6 christos lemac_isa_probe(parent, match, aux)
194 1.6 christos struct device *parent;
195 1.1 matt #ifdef __BROKEN_INDIRECT_CONFIG
196 1.6 christos void *match;
197 1.1 matt #else
198 1.6 christos struct cfdata *match;
199 1.1 matt #endif
200 1.6 christos void *aux;
201 1.1 matt {
202 1.6 christos struct isa_attach_args *ia = aux;
203 1.5 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
204 1.6 christos struct cfdata *cf = ((struct device *)match)->dv_cfdata;
205 1.5 thorpej #else
206 1.6 christos struct cfdata *cf = match;
207 1.5 thorpej #endif
208 1.6 christos lemac_softc_t sc;
209 1.6 christos (void)sprintf(sc.sc_dv.dv_xname, "%s%d", lc_cd.cd_name, cf->cf_unit);
210 1.6 christos
211 1.6 christos return lemac_isa_find(&sc, ia, 0);
212 1.1 matt }
213 1.1 matt
214 1.1 matt static void
215 1.6 christos lemac_isa_attach(parent, self, aux)
216 1.6 christos struct device *parent;
217 1.6 christos struct device *self;
218 1.6 christos void *aux;
219 1.1 matt {
220 1.6 christos lemac_softc_t *sc = (void *)self;
221 1.6 christos struct isa_attach_args *ia = aux;
222 1.1 matt
223 1.6 christos (void) lemac_isa_find(sc, ia, 1);
224 1.1 matt }
225