if_ep_eisa.c revision 1.21 1 /* $NetBSD: if_ep_eisa.c,v 1.21 1999/08/19 08:06:31 tron 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 (at) NetBSD.org>
42 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) 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 "opt_inet.h"
74 #include "opt_ns.h"
75 #include "bpfilter.h"
76
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/mbuf.h>
80 #include <sys/socket.h>
81 #include <sys/ioctl.h>
82 #include <sys/errno.h>
83 #include <sys/syslog.h>
84 #include <sys/select.h>
85 #include <sys/device.h>
86
87 #include <net/if.h>
88 #include <net/if_dl.h>
89 #include <net/if_ether.h>
90 #include <net/if_media.h>
91
92 #ifdef INET
93 #include <netinet/in.h>
94 #include <netinet/in_systm.h>
95 #include <netinet/in_var.h>
96 #include <netinet/ip.h>
97 #include <netinet/if_inarp.h>
98 #endif
99
100 #ifdef NS
101 #include <netns/ns.h>
102 #include <netns/ns_if.h>
103 #endif
104
105 #if NBPFILTER > 0
106 #include <net/bpf.h>
107 #include <net/bpfdesc.h>
108 #endif
109
110 #include <machine/cpu.h>
111 #include <machine/bus.h>
112 #include <machine/intr.h>
113
114 #include <dev/mii/miivar.h>
115
116 #include <dev/ic/elink3var.h>
117 #include <dev/ic/elink3reg.h>
118
119 #include <dev/eisa/eisareg.h>
120 #include <dev/eisa/eisavar.h>
121 #include <dev/eisa/eisadevs.h>
122
123 int ep_eisa_match __P((struct device *, struct cfdata *, void *));
124 void ep_eisa_attach __P((struct device *, struct device *, void *));
125
126 struct cfattach ep_eisa_ca = {
127 sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
128 };
129
130 /* XXX move these somewhere else */
131 #define EISA_CONTROL 0x0c84
132 #define EISA_RESET 0x04
133 #define EISA_ERROR 0x02
134 #define EISA_ENABLE 0x01
135
136 struct ep_eisa_product {
137 const char *eep_eisaid; /* EISA ID */
138 u_short eep_chipset; /* 3Com chipset used */
139 int eep_flags; /* initial softc flags */
140 const char *eep_name; /* device name */
141 } ep_eisa_products[] = {
142 { "TCM5091", ELINK_CHIPSET_3C509,
143 0, EISA_PRODUCT_TCM5091 },
144
145 { "TCM5092", ELINK_CHIPSET_3C509,
146 0, EISA_PRODUCT_TCM5092 },
147 { "TCM5093", ELINK_CHIPSET_3C509,
148 0, EISA_PRODUCT_TCM5093 },
149 { "TCM5094", ELINK_CHIPSET_3C509,
150 0, EISA_PRODUCT_TCM5094 },
151
152 /*
153 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
154 * MII connector for an external PHY. We treat it as
155 * `manual' in the core driver.
156 */
157 { "TCM5920", ELINK_CHIPSET_VORTEX,
158 0, EISA_PRODUCT_TCM5920 },
159 { "TCM5970", ELINK_CHIPSET_VORTEX,
160 0, EISA_PRODUCT_TCM5970 },
161 { "TCM5971", ELINK_CHIPSET_VORTEX,
162 0, EISA_PRODUCT_TCM5971 },
163 { "TCM5972", ELINK_CHIPSET_VORTEX,
164 0, EISA_PRODUCT_TCM5972 },
165
166 { NULL, 0,
167 0, NULL },
168 };
169
170 struct ep_eisa_product *ep_eisa_lookup __P((struct eisa_attach_args *));
171
172 struct ep_eisa_product *
173 ep_eisa_lookup(ea)
174 struct eisa_attach_args *ea;
175 {
176 struct ep_eisa_product *eep;
177
178 for (eep = ep_eisa_products; eep->eep_name != NULL; eep++)
179 if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0)
180 return (eep);
181
182 return (NULL);
183 }
184
185 int
186 ep_eisa_match(parent, match, aux)
187 struct device *parent;
188 struct cfdata *match;
189 void *aux;
190 {
191 struct eisa_attach_args *ea = aux;
192
193 /* must match one of our known ID strings */
194 if (ep_eisa_lookup(ea) != NULL)
195 return (1);
196
197 return (0);
198 }
199
200 void
201 ep_eisa_attach(parent, self, aux)
202 struct device *parent, *self;
203 void *aux;
204 {
205 struct ep_softc *sc = (void *)self;
206 struct eisa_attach_args *ea = aux;
207 bus_space_tag_t iot = ea->ea_iot;
208 bus_space_handle_t ioh;
209 eisa_chipset_tag_t ec = ea->ea_ec;
210 eisa_intr_handle_t ih;
211 const char *intrstr;
212 struct ep_eisa_product *eep;
213 u_int irq;
214
215 /* Map i/o space. */
216 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
217 EISA_SLOT_SIZE, 0, &ioh)) {
218 printf("\n");
219 panic("ep_eisa_attach: can't map i/o space");
220 }
221
222 sc->sc_ioh = ioh;
223 sc->sc_iot = iot;
224
225 /* Reset card. */
226 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
227 delay(10);
228 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
229 /* Wait for reset? */
230 delay(1000);
231
232 /* Read the IRQ from the card. */
233 irq = bus_space_read_2(iot, ioh, ELINK_W0_RESOURCE_CFG) >> 12;
234
235 eep = ep_eisa_lookup(ea);
236 if (eep == NULL) {
237 printf("\n");
238 panic("ep_eisa_attach: impossible");
239 }
240
241 printf(": %s\n", eep->eep_name);
242
243 sc->enable = NULL;
244 sc->disable = NULL;
245 sc->enabled = 1;
246
247 sc->bustype = ELINK_BUS_EISA;
248 sc->ep_flags = eep->eep_flags;
249
250 if (eisa_intr_map(ec, irq, &ih)) {
251 printf("%s: couldn't map interrupt (%u)\n",
252 sc->sc_dev.dv_xname, irq);
253 return;
254 }
255 intrstr = eisa_intr_string(ec, ih);
256 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
257 epintr, sc);
258 if (sc->sc_ih == NULL) {
259 printf("%s: couldn't establish interrupt",
260 sc->sc_dev.dv_xname);
261 if (intrstr != NULL)
262 printf(" at %s", intrstr);
263 printf("\n");
264 return;
265 }
266 if (intrstr != NULL)
267 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
268 intrstr);
269
270 epconfig(sc, eep->eep_chipset, NULL);
271 }
272