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