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