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