xref: /netbsd/sys/dev/eisa/if_ep_eisa.c (revision bf9ec67e)
1 /*	$NetBSD: if_ep_eisa.c,v 1.24 2001/11/13 12:47:33 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org>
42  * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
43  * All rights reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  * 1. Redistributions of source code must retain the above copyright
49  *    notice, this list of conditions and the following disclaimer.
50  * 2. Redistributions in binary form must reproduce the above copyright
51  *    notice, this list of conditions and the following disclaimer in the
52  *    documentation and/or other materials provided with the distribution.
53  * 3. All advertising materials mentioning features or use of this software
54  *    must display the following acknowledgement:
55  *      This product includes software developed by Herb Peyerl.
56  *      This product includes software developed by Jonathan Stone.
57  * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse
58  *    or promote products derived from this software without specific
59  *    prior written permission.
60  *
61  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
62  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
64  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
65  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
66  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
67  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
68  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
69  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
70  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71  */
72 
73 #include <sys/cdefs.h>
74 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.24 2001/11/13 12:47:33 lukem Exp $");
75 
76 #include "opt_inet.h"
77 #include "opt_ns.h"
78 #include "bpfilter.h"
79 
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/mbuf.h>
83 #include <sys/socket.h>
84 #include <sys/ioctl.h>
85 #include <sys/errno.h>
86 #include <sys/syslog.h>
87 #include <sys/select.h>
88 #include <sys/device.h>
89 
90 #include <net/if.h>
91 #include <net/if_dl.h>
92 #include <net/if_ether.h>
93 #include <net/if_media.h>
94 
95 #ifdef INET
96 #include <netinet/in.h>
97 #include <netinet/in_systm.h>
98 #include <netinet/in_var.h>
99 #include <netinet/ip.h>
100 #include <netinet/if_inarp.h>
101 #endif
102 
103 #ifdef NS
104 #include <netns/ns.h>
105 #include <netns/ns_if.h>
106 #endif
107 
108 #if NBPFILTER > 0
109 #include <net/bpf.h>
110 #include <net/bpfdesc.h>
111 #endif
112 
113 #include <machine/cpu.h>
114 #include <machine/bus.h>
115 #include <machine/intr.h>
116 
117 #include <dev/mii/miivar.h>
118 
119 #include <dev/ic/elink3var.h>
120 #include <dev/ic/elink3reg.h>
121 
122 #include <dev/eisa/eisareg.h>
123 #include <dev/eisa/eisavar.h>
124 #include <dev/eisa/eisadevs.h>
125 
126 int ep_eisa_match __P((struct device *, struct cfdata *, void *));
127 void ep_eisa_attach __P((struct device *, struct device *, void *));
128 
129 struct cfattach ep_eisa_ca = {
130 	sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
131 };
132 
133 /* XXX move these somewhere else */
134 /* While attaching we need a few special EISA registers of the card,
135    these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */
136 #define EP_EISA_CFG_BASE	0x0c80
137 #define	EP_EISA_CFG_CONTROL	0x0004	/* 1 byte */
138 #define	EP_EISA_CFG_RESOURCE	0x0008	/* 2 byte */
139 #define	EP_EISA_CFG_SIZE	0x000a
140 
141 /* The generic driver backend only needs access to the standard ports,
142    mapped at the beginning of the eisa slot space */
143 #define	EP_IOPORT_OFFSET	0x0000
144 #define	EP_IOPORT_SIZE		0x0020
145 
146 /* Bits for the eisa control register */
147 #define EISA_RESET	0x04
148 #define EISA_ERROR	0x02
149 #define EISA_ENABLE	0x01
150 
151 struct ep_eisa_product {
152 	const char	*eep_eisaid;	/* EISA ID */
153 	u_short		eep_chipset;	/* 3Com chipset used */
154 	int		eep_flags;	/* initial softc flags */
155 	const char	*eep_name;	/* device name */
156 } ep_eisa_products[] = {
157 	{ "TCM5091",			ELINK_CHIPSET_3C509,
158 	  0,				EISA_PRODUCT_TCM5091 },
159 
160 	{ "TCM5092",			ELINK_CHIPSET_3C509,
161 	  0,				EISA_PRODUCT_TCM5092 },
162 	{ "TCM5093",			ELINK_CHIPSET_3C509,
163 	  0,				EISA_PRODUCT_TCM5093 },
164 	{ "TCM5094",			ELINK_CHIPSET_3C509,
165 	  0,				EISA_PRODUCT_TCM5094 },
166 	{ "TCM5095",			ELINK_CHIPSET_3C509,
167 	  0,				EISA_PRODUCT_TCM5095 },
168 	{ "TCM5098",			ELINK_CHIPSET_3C509,
169 	  0,				EISA_PRODUCT_TCM5098 },
170 
171 	/*
172 	 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
173 	 * MII connector for an external PHY.  We treat it as
174 	 * `manual' in the core driver.
175 	 */
176 	{ "TCM5920",			ELINK_CHIPSET_VORTEX,
177 	  0,				EISA_PRODUCT_TCM5920 },
178 	{ "TCM5970",			ELINK_CHIPSET_VORTEX,
179 	  0,				EISA_PRODUCT_TCM5970 },
180 	{ "TCM5971",			ELINK_CHIPSET_VORTEX,
181 	  0,				EISA_PRODUCT_TCM5971 },
182 	{ "TCM5972",			ELINK_CHIPSET_VORTEX,
183 	  0,				EISA_PRODUCT_TCM5972 },
184 
185 	{ NULL,				0,
186 	  0,				NULL },
187 };
188 
189 struct ep_eisa_product *ep_eisa_lookup __P((struct eisa_attach_args *));
190 
191 struct ep_eisa_product *
192 ep_eisa_lookup(ea)
193 	struct eisa_attach_args *ea;
194 {
195 	struct ep_eisa_product *eep;
196 
197 	for (eep = ep_eisa_products; eep->eep_name != NULL; eep++)
198 		if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0)
199 			return (eep);
200 
201 	return (NULL);
202 }
203 
204 int
205 ep_eisa_match(parent, match, aux)
206 	struct device *parent;
207 	struct cfdata *match;
208 	void *aux;
209 {
210 	struct eisa_attach_args *ea = aux;
211 
212 	/* must match one of our known ID strings */
213 	if (ep_eisa_lookup(ea) != NULL)
214 		return (1);
215 
216 	return (0);
217 }
218 
219 void
220 ep_eisa_attach(parent, self, aux)
221 	struct device *parent, *self;
222 	void *aux;
223 {
224 	struct ep_softc *sc = (void *)self;
225 	struct eisa_attach_args *ea = aux;
226 	bus_space_tag_t iot = ea->ea_iot;
227 	bus_space_handle_t ioh, ioh_cfg;
228 	eisa_chipset_tag_t ec = ea->ea_ec;
229 	eisa_intr_handle_t ih;
230 	const char *intrstr;
231 	struct ep_eisa_product *eep;
232 	u_int irq;
233 
234 	/* Map i/o space. */
235 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_EISA_CFG_BASE,
236 	    EP_EISA_CFG_SIZE, 0, &ioh_cfg)) {
237 		printf("\n");
238 		panic("ep_eisa_attach: can't map eisa cfg i/o space");
239 	}
240 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_IOPORT_OFFSET,
241 	    EP_IOPORT_SIZE, 0, &ioh)) {
242 		printf("\n");
243 		panic("ep_eisa_attach: can't map i/o space");
244 	}
245 
246 	sc->sc_ioh = ioh;
247 	sc->sc_iot = iot;
248 
249 	/* Reset card. */
250 	bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL,
251 	    EISA_ENABLE | EISA_RESET);
252 	delay(4000);
253 	bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL, EISA_ENABLE);
254 	/* Wait for reset? */
255 	delay(1000);
256 
257 	/* Read the IRQ from the card. */
258 	irq = bus_space_read_2(iot, ioh_cfg, EP_EISA_CFG_RESOURCE) >> 12;
259 
260 	eep = ep_eisa_lookup(ea);
261 	if (eep == NULL) {
262 		printf("\n");
263 		panic("ep_eisa_attach: impossible");
264 	}
265 
266 	/* we don't need access to the config registers any more, but
267 	   noone else should be able to map this space, so keep it
268 	   reserved? */
269 #if 0
270 	bus_space_unmap(iot, ioh_cfg, EP_EISA_CFG_SIZE);
271 #endif
272 
273 	printf(": %s\n", eep->eep_name);
274 
275 	sc->enable = NULL;
276 	sc->disable = NULL;
277 	sc->enabled = 1;
278 
279 	sc->bustype = ELINK_BUS_EISA;
280 	sc->ep_flags = eep->eep_flags;
281 
282 	if (eisa_intr_map(ec, irq, &ih)) {
283 		printf("%s: couldn't map interrupt (%u)\n",
284 		    sc->sc_dev.dv_xname, irq);
285 		return;
286 	}
287 	intrstr = eisa_intr_string(ec, ih);
288 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
289 	    epintr, sc);
290 	if (sc->sc_ih == NULL) {
291 		printf("%s: couldn't establish interrupt",
292 		    sc->sc_dev.dv_xname);
293 		if (intrstr != NULL)
294 			printf(" at %s", intrstr);
295 		printf("\n");
296 		return;
297 	}
298 	if (intrstr != NULL)
299 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
300 		    intrstr);
301 
302 	epconfig(sc, eep->eep_chipset, NULL);
303 }
304