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