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