if_ep_eisa.c revision 1.13.4.2 1 /* $NetBSD: if_ep_eisa.c,v 1.13.4.2 1997/09/27 02:00:08 marc 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 "bpfilter.h"
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/mbuf.h>
39 #include <sys/socket.h>
40 #include <sys/ioctl.h>
41 #include <sys/errno.h>
42 #include <sys/syslog.h>
43 #include <sys/select.h>
44 #include <sys/device.h>
45
46 #include <net/if.h>
47 #include <net/if_dl.h>
48 #include <net/if_ether.h>
49 #include <net/if_media.h>
50
51 #ifdef INET
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/in_var.h>
55 #include <netinet/ip.h>
56 #include <netinet/if_inarp.h>
57 #endif
58
59 #ifdef NS
60 #include <netns/ns.h>
61 #include <netns/ns_if.h>
62 #endif
63
64 #if NBPFILTER > 0
65 #include <net/bpf.h>
66 #include <net/bpfdesc.h>
67 #endif
68
69 #include <machine/cpu.h>
70 #include <machine/bus.h>
71 #include <machine/intr.h>
72
73 #include <dev/ic/elink3var.h>
74 #include <dev/ic/elink3reg.h>
75
76 #include <dev/eisa/eisareg.h>
77 #include <dev/eisa/eisavar.h>
78 #include <dev/eisa/eisadevs.h>
79
80 #ifdef __BROKEN_INDIRECT_CONFIG
81 int ep_eisa_match __P((struct device *, void *, void *));
82 #else
83 int ep_eisa_match __P((struct device *, struct cfdata *, void *));
84 #endif
85 void ep_eisa_attach __P((struct device *, struct device *, void *));
86
87 struct cfattach ep_eisa_ca = {
88 sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
89 };
90
91 /* XXX move these somewhere else */
92 #define EISA_CONTROL 0x0c84
93 #define EISA_RESET 0x04
94 #define EISA_ERROR 0x02
95 #define EISA_ENABLE 0x01
96
97 int
98 ep_eisa_match(parent, match, aux)
99 struct device *parent;
100 #ifdef __BROKEN_INDIRECT_CONFIG
101 void *match;
102 #else
103 struct cfdata *match;
104 #endif
105 void *aux;
106 {
107 struct eisa_attach_args *ea = aux;
108
109 /* must match one of our known ID strings */
110 if (strcmp(ea->ea_idstring, "TCM5091") &&
111 strcmp(ea->ea_idstring, "TCM5092") &&
112 strcmp(ea->ea_idstring, "TCM5093") &&
113 strcmp(ea->ea_idstring, "TCM5920") &&
114 strcmp(ea->ea_idstring, "TCM5970") &&
115 strcmp(ea->ea_idstring, "TCM5971") &&
116 strcmp(ea->ea_idstring, "TCM5972"))
117 return (0);
118
119 return (1);
120 }
121
122 void
123 ep_eisa_attach(parent, self, aux)
124 struct device *parent, *self;
125 void *aux;
126 {
127 struct ep_softc *sc = (void *)self;
128 struct eisa_attach_args *ea = aux;
129 bus_space_tag_t iot = ea->ea_iot;
130 bus_space_handle_t ioh;
131 u_int16_t k;
132 eisa_chipset_tag_t ec = ea->ea_ec;
133 eisa_intr_handle_t ih;
134 const char *model, *intrstr;
135 int chipset;
136 u_int irq;
137
138 /* Map i/o space. */
139 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
140 EISA_SLOT_SIZE, 0, &ioh))
141 panic("ep_eisa_attach: can't map i/o space");
142
143 sc->bustype = EP_BUS_EISA;
144 sc->sc_ioh = ioh;
145 sc->sc_iot = iot;
146
147 /* Reset card. */
148 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
149 delay(10);
150 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
151 /* Wait for reset? */
152 delay(1000);
153
154 /* XXX What is this doing?! Reading the i/o address? */
155 k = bus_space_read_2(iot, ioh, EP_W0_ADDRESS_CFG);
156 k = (k & 0x1f) * 0x10 + 0x200;
157
158 /* Read the IRQ from the card. */
159 irq = bus_space_read_2(iot, ioh, EP_W0_RESOURCE_CFG) >> 12;
160
161 chipset = EP_CHIPSET_3C509; /* assume dumb chipset */
162 if (strcmp(ea->ea_idstring, "TCM5091") == 0)
163 model = EISA_PRODUCT_TCM5091;
164 else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
165 model = EISA_PRODUCT_TCM5092;
166 else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
167 model = EISA_PRODUCT_TCM5093;
168 else if (strcmp(ea->ea_idstring, "TCM5920") == 0) {
169 model = EISA_PRODUCT_TCM5920;
170 chipset = EP_CHIPSET_VORTEX;
171 }
172 else if (strcmp(ea->ea_idstring, "TCM5970") == 0) {
173 model = EISA_PRODUCT_TCM5970;
174 chipset = EP_CHIPSET_VORTEX;
175 }
176 else if (strcmp(ea->ea_idstring, "TCM5971") == 0) {
177 model = EISA_PRODUCT_TCM5971;
178 chipset = EP_CHIPSET_VORTEX;
179 }
180 else if (strcmp(ea->ea_idstring, "TCM5972") == 0) {
181 model = EISA_PRODUCT_TCM5972;
182 chipset = EP_CHIPSET_VORTEX;
183 }
184 else
185 model = "unknown model!";
186 printf(": %s\n", model);
187
188 if (eisa_intr_map(ec, irq, &ih)) {
189 printf("%s: couldn't map interrupt (%u)\n",
190 sc->sc_dev.dv_xname, irq);
191 return;
192 }
193 intrstr = eisa_intr_string(ec, ih);
194 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
195 epintr, sc);
196 if (sc->sc_ih == NULL) {
197 printf("%s: couldn't establish interrupt",
198 sc->sc_dev.dv_xname);
199 if (intrstr != NULL)
200 printf(" at %s", intrstr);
201 printf("\n");
202 return;
203 }
204 if (intrstr != NULL)
205 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
206 intrstr);
207
208 sc->enable = NULL;
209 sc->disable = NULL;
210 sc->enabled = 1;
211
212 epconfig(sc, chipset, NULL);
213 }
214