if_ep_eisa.c revision 1.16 1 /* $NetBSD: if_ep_eisa.c,v 1.16 1998/07/05 00:51:17 jonathan Exp $ */
2
3 /*
4 * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
5 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Herb Peyerl.
19 * 4. The name of Herb Peyerl may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "opt_inet.h"
35 #include "bpfilter.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41 #include <sys/ioctl.h>
42 #include <sys/errno.h>
43 #include <sys/syslog.h>
44 #include <sys/select.h>
45 #include <sys/device.h>
46
47 #include <net/if.h>
48 #include <net/if_dl.h>
49 #include <net/if_ether.h>
50 #include <net/if_media.h>
51
52 #ifdef INET
53 #include <netinet/in.h>
54 #include <netinet/in_systm.h>
55 #include <netinet/in_var.h>
56 #include <netinet/ip.h>
57 #include <netinet/if_inarp.h>
58 #endif
59
60 #ifdef NS
61 #include <netns/ns.h>
62 #include <netns/ns_if.h>
63 #endif
64
65 #if NBPFILTER > 0
66 #include <net/bpf.h>
67 #include <net/bpfdesc.h>
68 #endif
69
70 #include <machine/cpu.h>
71 #include <machine/bus.h>
72 #include <machine/intr.h>
73
74 #include <dev/ic/elink3var.h>
75 #include <dev/ic/elink3reg.h>
76
77 #include <dev/eisa/eisareg.h>
78 #include <dev/eisa/eisavar.h>
79 #include <dev/eisa/eisadevs.h>
80
81 int ep_eisa_match __P((struct device *, struct cfdata *, void *));
82 void ep_eisa_attach __P((struct device *, struct device *, void *));
83
84 struct cfattach ep_eisa_ca = {
85 sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
86 };
87
88 /* XXX move these somewhere else */
89 #define EISA_CONTROL 0x0c84
90 #define EISA_RESET 0x04
91 #define EISA_ERROR 0x02
92 #define EISA_ENABLE 0x01
93
94 int
95 ep_eisa_match(parent, match, aux)
96 struct device *parent;
97 struct cfdata *match;
98 void *aux;
99 {
100 struct eisa_attach_args *ea = aux;
101
102 /* must match one of our known ID strings */
103 if (strcmp(ea->ea_idstring, "TCM5091") &&
104 strcmp(ea->ea_idstring, "TCM5092") &&
105 strcmp(ea->ea_idstring, "TCM5093") &&
106 strcmp(ea->ea_idstring, "TCM5920") &&
107 strcmp(ea->ea_idstring, "TCM5970") &&
108 strcmp(ea->ea_idstring, "TCM5971") &&
109 strcmp(ea->ea_idstring, "TCM5972"))
110 return (0);
111
112 return (1);
113 }
114
115 void
116 ep_eisa_attach(parent, self, aux)
117 struct device *parent, *self;
118 void *aux;
119 {
120 struct ep_softc *sc = (void *)self;
121 struct eisa_attach_args *ea = aux;
122 bus_space_tag_t iot = ea->ea_iot;
123 bus_space_handle_t ioh;
124 u_int16_t k;
125 eisa_chipset_tag_t ec = ea->ea_ec;
126 eisa_intr_handle_t ih;
127 const char *model, *intrstr;
128 int chipset;
129 u_int irq;
130
131 /* Map i/o space. */
132 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
133 EISA_SLOT_SIZE, 0, &ioh))
134 panic("ep_eisa_attach: can't map i/o space");
135
136 sc->bustype = EP_BUS_EISA;
137 sc->sc_ioh = ioh;
138 sc->sc_iot = iot;
139
140 /* Reset card. */
141 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
142 delay(10);
143 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
144 /* Wait for reset? */
145 delay(1000);
146
147 /* XXX What is this doing?! Reading the i/o address? */
148 k = bus_space_read_2(iot, ioh, EP_W0_ADDRESS_CFG);
149 k = (k & 0x1f) * 0x10 + 0x200;
150
151 /* Read the IRQ from the card. */
152 irq = bus_space_read_2(iot, ioh, EP_W0_RESOURCE_CFG) >> 12;
153
154 chipset = EP_CHIPSET_3C509; /* assume dumb chipset */
155 if (strcmp(ea->ea_idstring, "TCM5091") == 0)
156 model = EISA_PRODUCT_TCM5091;
157 else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
158 model = EISA_PRODUCT_TCM5092;
159 else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
160 model = EISA_PRODUCT_TCM5093;
161 else if (strcmp(ea->ea_idstring, "TCM5920") == 0) {
162 model = EISA_PRODUCT_TCM5920;
163 chipset = EP_CHIPSET_VORTEX;
164 }
165 else if (strcmp(ea->ea_idstring, "TCM5970") == 0) {
166 model = EISA_PRODUCT_TCM5970;
167 chipset = EP_CHIPSET_VORTEX;
168 }
169 else if (strcmp(ea->ea_idstring, "TCM5971") == 0) {
170 model = EISA_PRODUCT_TCM5971;
171 chipset = EP_CHIPSET_VORTEX;
172 }
173 else if (strcmp(ea->ea_idstring, "TCM5972") == 0) {
174 model = EISA_PRODUCT_TCM5972;
175 chipset = EP_CHIPSET_VORTEX;
176 }
177 else
178 model = "unknown model!";
179 printf(": %s\n", model);
180
181 if (eisa_intr_map(ec, irq, &ih)) {
182 printf("%s: couldn't map interrupt (%u)\n",
183 sc->sc_dev.dv_xname, irq);
184 return;
185 }
186 intrstr = eisa_intr_string(ec, ih);
187 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
188 epintr, sc);
189 if (sc->sc_ih == NULL) {
190 printf("%s: couldn't establish interrupt",
191 sc->sc_dev.dv_xname);
192 if (intrstr != NULL)
193 printf(" at %s", intrstr);
194 printf("\n");
195 return;
196 }
197 if (intrstr != NULL)
198 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
199 intrstr);
200
201 sc->enable = NULL;
202 sc->disable = NULL;
203 sc->enabled = 1;
204
205 epconfig(sc, chipset, NULL);
206 }
207