if_lc_isa.c revision 1.5 1 1.5 thorpej /* $NetBSD: if_lc_isa.c,v 1.5 1997/11/17 03:34:24 thorpej 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.1 matt static int
84 1.1 matt lemac_isa_probe(
85 1.1 matt struct device *parent,
86 1.1 matt #ifdef __BROKEN_INDIRECT_CONFIG
87 1.1 matt void *match,
88 1.1 matt #else
89 1.1 matt struct cfdata *match,
90 1.1 matt #endif
91 1.1 matt void *aux)
92 1.1 matt {
93 1.1 matt struct isa_attach_args * const ia = aux;
94 1.5 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
95 1.5 thorpej struct cfdata *cf = ((struct device *)match)->dv_cfdata;
96 1.5 thorpej #else
97 1.5 thorpej struct cfdata *cf = match;
98 1.5 thorpej #endif
99 1.5 thorpej int irq, rv = 0;
100 1.2 matt bus_addr_t maddr;
101 1.2 matt bus_addr_t msize;
102 1.2 matt bus_space_handle_t memh;
103 1.2 matt bus_space_handle_t ioh;
104 1.1 matt
105 1.1 matt /*
106 1.5 thorpej * Disallow wildcarded i/o addresses.
107 1.5 thorpej */
108 1.5 thorpej if (ia->ia_iobase == IOBASEUNK)
109 1.5 thorpej return 0;
110 1.5 thorpej
111 1.5 thorpej /*
112 1.5 thorpej * Make sure this is a valid LEMAC address.
113 1.5 thorpej */
114 1.5 thorpej if (ia->ia_iobase & (LEMAC_IOSIZE - 1))
115 1.5 thorpej return 0;
116 1.5 thorpej
117 1.5 thorpej /*
118 1.5 thorpej * Map the LEMAC's port space for the probe sequence.
119 1.1 matt */
120 1.5 thorpej if (bus_space_map(ia->ia_iot, ia->ia_iobase, LEMAC_IOSIZE, 0, &ioh))
121 1.2 matt return 0;
122 1.1 matt
123 1.5 thorpej /*
124 1.5 thorpej * Read the Ethernet address from the EEPROM.
125 1.5 thorpej * It must start with one of the DEC OUIs and pass the
126 1.5 thorpej * DEC ethernet checksum test.
127 1.5 thorpej */
128 1.5 thorpej if (lemac_port_check(ia->ia_iot, ioh) == 0)
129 1.5 thorpej goto out;
130 1.5 thorpej
131 1.5 thorpej /*
132 1.5 thorpej * Get information about memory space and attempt to map it.
133 1.5 thorpej */
134 1.5 thorpej lemac_info_get(ia->ia_iot, ioh, &maddr, &msize, &irq);
135 1.5 thorpej if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK)
136 1.5 thorpej goto out;
137 1.5 thorpej if (bus_space_map(ia->ia_memt, maddr, msize, 0, &memh))
138 1.5 thorpej goto out;
139 1.5 thorpej bus_space_unmap(ia->ia_memt, memh, msize);
140 1.5 thorpej
141 1.5 thorpej /*
142 1.5 thorpej * Double-check IRQ configuration.
143 1.5 thorpej */
144 1.5 thorpej if (ia->ia_irq != irq && ia->ia_irq != IRQUNK)
145 1.5 thorpej printf("%s%d: overriding IRQ %d to %d\n", lc_cd.cd_name, cf->cf_unit,
146 1.5 thorpej ia->ia_irq, irq);
147 1.5 thorpej ia->ia_irq = irq;
148 1.5 thorpej
149 1.5 thorpej /*
150 1.5 thorpej * I guess we've found one.
151 1.5 thorpej */
152 1.5 thorpej rv = 1;
153 1.1 matt
154 1.5 thorpej out:
155 1.5 thorpej bus_space_unmap(ia->ia_iot, ioh, LEMAC_IOSIZE);
156 1.5 thorpej return rv;
157 1.1 matt }
158 1.1 matt
159 1.1 matt static void
160 1.1 matt lemac_isa_attach(
161 1.1 matt struct device *parent,
162 1.1 matt struct device *self,
163 1.1 matt void *aux)
164 1.1 matt {
165 1.1 matt lemac_softc_t *sc = (void *)self;
166 1.1 matt struct isa_attach_args *ia = aux;
167 1.1 matt
168 1.1 matt /* Map i/o space. */
169 1.1 matt sc->sc_iot = ia->ia_iot;
170 1.4 thorpej if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0,
171 1.4 thorpej &sc->sc_ioh)) {
172 1.4 thorpej printf(": can't map i/o space\n");
173 1.4 thorpej return;
174 1.4 thorpej }
175 1.1 matt
176 1.1 matt if (ia->ia_msize && ia->ia_maddr) {
177 1.1 matt sc->sc_memt = ia->ia_memt;
178 1.1 matt /* Map memory space. */
179 1.4 thorpej if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize, 0,
180 1.4 thorpej &sc->sc_memh)) {
181 1.4 thorpej printf(": can't map mem space\n");
182 1.4 thorpej return;
183 1.4 thorpej }
184 1.1 matt }
185 1.1 matt
186 1.1 matt sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
187 1.1 matt if (sc->sc_ats == NULL)
188 1.1 matt printf("\n%s: warning: couldn't establish shutdown hook\n",
189 1.1 matt sc->sc_dv.dv_xname);
190 1.1 matt
191 1.1 matt lemac_ifattach(sc);
192 1.1 matt
193 1.1 matt sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
194 1.1 matt IPL_NET, lemac_intr, sc);
195 1.1 matt }
196 1.1 matt
197 1.1 matt struct cfattach lc_isa_ca = {
198 1.1 matt sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach
199 1.1 matt };
200