if_tlp_eisa.c revision 1.26
1/*	$NetBSD: if_tlp_eisa.c,v 1.26 2014/10/17 17:09:44 snj Exp $	*/
2
3/*-
4 * Copyright (c) 1999, 2000 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * EISA bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
35 * Ethernet controller family driver.
36 */
37
38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: if_tlp_eisa.c,v 1.26 2014/10/17 17:09:44 snj Exp $");
40
41#include "opt_inet.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/mbuf.h>
46#include <sys/malloc.h>
47#include <sys/kernel.h>
48#include <sys/socket.h>
49#include <sys/ioctl.h>
50#include <sys/errno.h>
51#include <sys/device.h>
52
53#include <machine/endian.h>
54
55#include <net/if.h>
56#include <net/if_dl.h>
57#include <net/if_media.h>
58#include <net/if_ether.h>
59
60#ifdef INET
61#include <netinet/in.h>
62#include <netinet/if_inarp.h>
63#endif
64
65
66#include <sys/bus.h>
67#include <sys/intr.h>
68
69#include <dev/mii/miivar.h>
70#include <dev/mii/mii_bitbang.h>
71
72#include <dev/ic/tulipreg.h>
73#include <dev/ic/tulipvar.h>
74
75#include <dev/eisa/eisareg.h>
76#include <dev/eisa/eisavar.h>
77#include <dev/eisa/eisadevs.h>
78
79#include <dev/pci/pcireg.h>
80
81/*
82 * DE425 configuration registers; literal offsets from CSR base.
83 * This is effectively the 21040 PCI configuration space interleaved
84 * into the CSR space (CSRs are space 16 bytes on the DE425).
85 *
86 * What a cool address decoder hack they must have on that board...
87 */
88#define	DE425_CFID		0x08	/* Configuration ID */
89#define	DE425_CFCS		0x0c	/* Configuration Command-Status */
90#define	DE425_CFRV		0x18	/* Configuration Revision */
91#define	DE425_CFLT		0x1c	/* Configuration Latency Timer */
92#define	DE425_CBIO		0x28	/* Configuration Base I/O Address */
93#define	DE425_CFDA		0x2c	/* Configuration Driver Area */
94#define	DE425_ENETROM		0xc90	/* Offset in I/O space for ENETROM */
95#define	DE425_CFG0		0xc88	/* IRQ Configuration Register */
96
97struct tulip_eisa_softc {
98	struct tulip_softc sc_tulip;	/* real Tulip softc */
99
100	/* EISA-specific goo. */
101	void	*sc_ih;			/* interrupt handle */
102};
103
104static int	tlp_eisa_match(device_t, cfdata_t, void *);
105static void	tlp_eisa_attach(device_t, device_t, void *);
106
107CFATTACH_DECL_NEW(tlp_eisa, sizeof(struct tulip_eisa_softc),
108    tlp_eisa_match, tlp_eisa_attach, NULL, NULL);
109
110static const int tlp_eisa_irqs[] = { 5, 9, 10, 11 };
111
112static const struct tulip_eisa_product {
113	const char	*tep_eisaid;	/* EISA ID */
114	const char	*tep_name;	/* device name */
115	tulip_chip_t	tep_chip;	/* base Tulip chip type */
116} tlp_eisa_products[] = {
117	{ "DEC4250",			"DEC DE425",
118	  TULIP_CHIP_DE425 },
119
120	{ NULL,				NULL,
121	  TULIP_CHIP_INVALID },
122};
123
124static const struct tulip_eisa_product *
125tlp_eisa_lookup(const struct eisa_attach_args *ea)
126{
127	const struct tulip_eisa_product *tep;
128
129	for (tep = tlp_eisa_products;
130	     tep->tep_chip != TULIP_CHIP_INVALID; tep++)
131		if (strcmp(ea->ea_idstring, tep->tep_eisaid) == 0)
132			return (tep);
133	return (NULL);
134}
135
136static int
137tlp_eisa_match(device_t parent, cfdata_t match,
138    void *aux)
139{
140	struct eisa_attach_args *ea = aux;
141
142	if (tlp_eisa_lookup(ea) != NULL)
143		return (1);
144
145	return (0);
146}
147
148static void
149tlp_eisa_attach(device_t parent, device_t self, void *aux)
150{
151	static const u_int8_t testpat[] =
152	    { 0xff, 0, 0x55, 0xaa, 0xff, 0, 0x55, 0xaa };
153	struct tulip_eisa_softc *esc = device_private(self);
154	struct tulip_softc *sc = &esc->sc_tulip;
155	struct eisa_attach_args *ea = aux;
156	eisa_chipset_tag_t ec = ea->ea_ec;
157	eisa_intr_handle_t ih;
158	bus_space_tag_t iot = ea->ea_iot;
159	bus_space_handle_t ioh;
160	const char *intrstr;
161	const struct tulip_eisa_product *tep;
162	u_int8_t enaddr[ETHER_ADDR_LEN], tmpbuf[sizeof(testpat)];
163	u_int32_t val;
164	int irq, i, cnt;
165	char intrbuf[EISA_INTRSTR_LEN];
166
167	/*
168	 * Map the device.
169	 */
170	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
171	    EISA_SLOT_SIZE, 0, &ioh)) {
172		printf(": unable to map I/O space\n");
173		return;
174	}
175
176	sc->sc_dev = self;
177	sc->sc_st = iot;
178	sc->sc_sh = ioh;
179
180	tep = tlp_eisa_lookup(ea);
181	if (tep == NULL) {
182		printf("\n");
183		panic("tlp_eisa_attach: impossible");
184	}
185	sc->sc_chip = tep->tep_chip;
186
187	/*
188	 * DE425's registers are 16 bytes long; the PCI configuration
189	 * space registers are interleaved in the I/O space.
190	 */
191	sc->sc_regshift = 4;
192
193	/*
194	 * No power management hooks.
195	 */
196	sc->sc_flags |= TULIPF_ENABLED;
197
198	/*
199	 * CBIO must map the EISA slot, and I/O access and Bus Mastering
200	 * must be enabled.
201	 */
202	bus_space_write_4(iot, ioh, DE425_CBIO, EISA_SLOT_ADDR(ea->ea_slot));
203	bus_space_write_4(iot, ioh, DE425_CFCS,
204	    bus_space_read_4(iot, ioh, DE425_CFCS) |
205	    PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE);
206
207	/*
208	 * Get revision info.
209	 */
210	sc->sc_rev = bus_space_read_4(iot, ioh, DE425_CFRV) & 0xff;
211
212	printf(": %s Ethernet, pass %d.%d\n",
213	    tep->tep_name, (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
214
215	sc->sc_dmat = ea->ea_dmat;
216
217	/*
218	 * EISA doesn't have a cache line register.
219	 */
220	sc->sc_cacheline = 0;
221
222	/*
223	 * Find the beginning of the Ethernet Address ROM.
224	 */
225	for (i = 0, cnt = 0; i < sizeof(testpat) && cnt < 32; cnt++) {
226		tmpbuf[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
227		if (tmpbuf[i] == testpat[i])
228			i++;
229		else
230			i = 0;
231	}
232
233	/*
234	 * ...and now read the contents of the Ethernet Address ROM.
235	 */
236	sc->sc_srom = malloc(32, M_DEVBUF, M_WAITOK|M_ZERO);
237	for (i = 0; i < 32; i++)
238		sc->sc_srom[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
239
240	/*
241	 * None of the DE425 boards have the new-style SROMs.
242	 */
243	if (tlp_parse_old_srom(sc, enaddr) == 0) {
244		aprint_error_dev(self, "unable to decode old-style SROM\n");
245		return;
246	}
247
248	/*
249	 * All DE425 boards use the 21040 media switch.
250	 */
251	sc->sc_mediasw = &tlp_21040_mediasw;
252
253	/*
254	 * Figure out which IRQ we want to use, and determine if it's
255	 * edge- or level-triggered.
256	 */
257	val = bus_space_read_4(iot, ioh, DE425_CFG0);
258	irq = tlp_eisa_irqs[(val >> 1) & 0x03];
259
260	/*
261	 * Map and establish our interrupt.
262	 */
263	if (eisa_intr_map(ec, irq, &ih)) {
264		aprint_error_dev(self, "unable to map interrupt (%u)\n",
265		    irq);
266		return;
267	}
268	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
269	esc->sc_ih = eisa_intr_establish(ec, ih,
270	    (val & 0x01) ? IST_EDGE : IST_LEVEL, IPL_NET, tlp_intr, sc);
271	if (esc->sc_ih == NULL) {
272		aprint_error_dev(self, "unable to establish interrupt");
273		if (intrstr != NULL)
274			aprint_error(" at %s", intrstr);
275		aprint_error("\n");
276		return;
277	}
278	if (intrstr != NULL)
279		aprint_normal_dev(self, "interrupting at %s\n", intrstr);
280
281	/*
282	 * Finish off the attach.
283	 */
284	tlp_attach(sc, enaddr);
285}
286