if_tlp_eisa.c revision 1.5
1/*	$NetBSD: if_tlp_eisa.c,v 1.5 2000/03/15 18:39:52 thorpej Exp $	*/
2
3/*-
4 * Copyright (c) 1999 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 * EISA bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
42 * Ethernet controller family driver.
43 */
44
45#include "opt_inet.h"
46#include "opt_ns.h"
47#include "bpfilter.h"
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/mbuf.h>
52#include <sys/malloc.h>
53#include <sys/kernel.h>
54#include <sys/socket.h>
55#include <sys/ioctl.h>
56#include <sys/errno.h>
57#include <sys/device.h>
58
59#include <machine/endian.h>
60
61#include <net/if.h>
62#include <net/if_dl.h>
63#include <net/if_media.h>
64#include <net/if_ether.h>
65
66#if NBPFILTER > 0
67#include <net/bpf.h>
68#endif
69
70#ifdef INET
71#include <netinet/in.h>
72#include <netinet/if_inarp.h>
73#endif
74
75#ifdef NS
76#include <netns/ns.h>
77#include <netns/ns_if.h>
78#endif
79
80#include <machine/bus.h>
81#include <machine/intr.h>
82
83#include <dev/mii/miivar.h>
84#include <dev/mii/mii_bitbang.h>
85
86#include <dev/ic/tulipreg.h>
87#include <dev/ic/tulipvar.h>
88
89#include <dev/eisa/eisareg.h>
90#include <dev/eisa/eisavar.h>
91#include <dev/eisa/eisadevs.h>
92
93#include <dev/pci/pcireg.h>
94
95/*
96 * DE425 configuration registers; literal offsets from CSR base.
97 * This is effectively the 21040 PCI configuration space interleaved
98 * into the CSR space (CSRs are space 16 bytes on the DE425).
99 *
100 * What a cool address decoder hack they must have on that board...
101 */
102#define	DE425_CFID		0x08	/* Configuration ID */
103#define	DE425_CFCS		0x0c	/* Configuration Command-Status */
104#define	DE425_CFRV		0x18	/* Configuration Revision */
105#define	DE425_CFLT		0x1c	/* Configuration Latency Timer */
106#define	DE425_CBIO		0x28	/* Configuration Base I/O Address */
107#define	DE425_CFDA		0x2c	/* Configuration Driver Area */
108#define	DE425_ENETROM		0xc90	/* Offset in I/O space for ENETROM */
109#define	DE425_CFG0		0xc88	/* IRQ Configuration Register */
110
111struct tulip_eisa_softc {
112	struct tulip_softc sc_tulip;	/* real Tulip softc */
113
114	/* EISA-specific goo. */
115	void	*sc_ih;			/* interrupt handle */
116};
117
118int	tlp_eisa_match __P((struct device *, struct cfdata *, void *));
119void	tlp_eisa_attach __P((struct device *, struct device *, void *));
120
121struct cfattach tlp_eisa_ca = {
122	sizeof(struct tulip_eisa_softc), tlp_eisa_match, tlp_eisa_attach,
123};
124
125const int tlp_eisa_irqs[] = { 5, 9, 10, 11 };
126
127const struct tulip_eisa_product {
128	const char	*tep_eisaid;	/* EISA ID */
129	const char	*tep_name;	/* device name */
130	tulip_chip_t	tep_chip;	/* base Tulip chip type */
131} tlp_eisa_products[] = {
132	{ "DEC4250",			"DEC DE425",
133	  TULIP_CHIP_DE425 },
134
135	{ NULL,				NULL,
136	  TULIP_CHIP_INVALID },
137};
138
139const struct tulip_eisa_product *tlp_eisa_lookup
140    __P((const struct eisa_attach_args *));
141
142const struct tulip_eisa_product *
143tlp_eisa_lookup(ea)
144	const struct eisa_attach_args *ea;
145{
146	const struct tulip_eisa_product *tep;
147
148	for (tep = tlp_eisa_products;
149	     tep->tep_chip != TULIP_CHIP_INVALID; tep++)
150		if (strcmp(ea->ea_idstring, tep->tep_eisaid) == 0)
151			return (tep);
152	return (NULL);
153}
154
155int
156tlp_eisa_match(parent, match, aux)
157	struct device *parent;
158	struct cfdata *match;
159	void *aux;
160{
161	struct eisa_attach_args *ea = aux;
162
163	if (tlp_eisa_lookup(ea) != NULL)
164		return (1);
165
166	return (0);
167}
168
169void
170tlp_eisa_attach(parent, self, aux)
171	struct device *parent, *self;
172	void *aux;
173{
174	static const u_int8_t testpat[] =
175	    { 0xff, 0, 0x55, 0xaa, 0xff, 0, 0x55, 0xaa };
176	struct tulip_eisa_softc *esc = (void *) self;
177	struct tulip_softc *sc = &esc->sc_tulip;
178	struct eisa_attach_args *ea = aux;
179	eisa_chipset_tag_t ec = ea->ea_ec;
180	eisa_intr_handle_t ih;
181	bus_space_tag_t iot = ea->ea_iot;
182	bus_space_handle_t ioh;
183	const char *intrstr;
184	const struct tulip_eisa_product *tep;
185	u_int8_t enaddr[ETHER_ADDR_LEN], tmpbuf[sizeof(testpat)];
186	u_int32_t val;
187	int irq, i, cnt;
188
189	/*
190	 * Map the device.
191	 */
192	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
193	    EISA_SLOT_SIZE, 0, &ioh)) {
194		printf(": unable to map I/O space\n");
195		return;
196	}
197
198	sc->sc_st = iot;
199	sc->sc_sh = ioh;
200
201	tep = tlp_eisa_lookup(ea);
202	if (tep == NULL) {
203		printf("\n");
204		panic("tlp_eisa_attach: impossible");
205	}
206	sc->sc_chip = tep->tep_chip;
207
208	/*
209	 * DE425's registers are 16 bytes long; the PCI configuration
210	 * space registers are interleaved in the I/O space.
211	 */
212	sc->sc_regshift = 4;
213
214	/*
215	 * No power management hooks.
216	 */
217	sc->sc_flags |= TULIPF_ENABLED;
218
219	/*
220	 * CBIO must map the EISA slot, and I/O access and Bus Mastering
221	 * must be enabled.
222	 */
223	bus_space_write_4(iot, ioh, DE425_CBIO, EISA_SLOT_ADDR(ea->ea_slot));
224	bus_space_write_4(iot, ioh, DE425_CFCS,
225	    bus_space_read_4(iot, ioh, DE425_CFCS) |
226	    PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE);
227
228	/*
229	 * Get revision info.
230	 */
231	sc->sc_rev = bus_space_read_4(iot, ioh, DE425_CFRV) & 0xff;
232
233	printf(": %s Ethernet, pass %d.%d\n",
234	    tep->tep_name, (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
235
236	sc->sc_dmat = ea->ea_dmat;
237
238	/*
239	 * EISA doesn't have a cache line register.
240	 */
241	sc->sc_cacheline = 0;
242
243	/*
244	 * Find the beginning of the Ethernet Address ROM.
245	 */
246	for (i = 0, cnt = 0; i < sizeof(testpat) && cnt < 32; cnt++) {
247		tmpbuf[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
248		if (tmpbuf[i] == testpat[i])
249			i++;
250		else
251			i = 0;
252	}
253
254	/*
255	 * ...and now read the contents of the Ethernet Address ROM.
256	 */
257	memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
258	for (i = 0; i < 32; i++)
259		sc->sc_srom[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
260
261	/*
262	 * None of the DE425 boards have the new-style SROMs.
263	 */
264	if (tlp_parse_old_srom(sc, enaddr) == 0) {
265		printf("%s: unable to decode old-style SROM\n",
266		    sc->sc_dev.dv_xname);
267		return;
268	}
269
270	/*
271	 * All DE425 boards use the 21040 media switch.
272	 */
273	sc->sc_mediasw = &tlp_21040_mediasw;
274
275	/*
276	 * Figure out which IRQ we want to use, and determine of it's
277	 * edge- or level-triggered.
278	 */
279	val = bus_space_read_4(iot, ioh, DE425_CFG0);
280	irq = tlp_eisa_irqs[(val >> 1) & 0x03];
281
282	/*
283	 * Map and establish our interrupt.
284	 */
285	if (eisa_intr_map(ec, irq, &ih)) {
286		printf("%s: unable to map interrupt (%u)\n",
287		    sc->sc_dev.dv_xname, irq);
288		return;
289	}
290	intrstr = eisa_intr_string(ec, ih);
291	esc->sc_ih = eisa_intr_establish(ec, ih,
292	    (val & 0x01) ? IST_EDGE : IST_LEVEL, IPL_NET, tlp_intr, sc);
293	if (esc->sc_ih == NULL) {
294		printf("%s: unable to establish interrupt",
295		    sc->sc_dev.dv_xname);
296		if (intrstr != NULL)
297			printf(" at %s", intrstr);
298		printf("\n");
299		return;
300	}
301	if (intrstr != NULL)
302		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
303		    intrstr);
304
305	/*
306	 * Finish off the attach.
307	 */
308	tlp_attach(sc, enaddr);
309}
310