if_ep_eisa.c revision 1.7 1 /* $NetBSD: if_ep_eisa.c,v 1.7 1996/10/10 19:54:13 christos 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 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #include <netinet/if_ether.h>
56 #endif
57
58 #ifdef NS
59 #include <netns/ns.h>
60 #include <netns/ns_if.h>
61 #endif
62
63 #if NBPFILTER > 0
64 #include <net/bpf.h>
65 #include <net/bpfdesc.h>
66 #endif
67
68 #include <machine/cpu.h>
69 #include <machine/bus.h>
70 #include <machine/intr.h>
71
72 #include <dev/ic/elink3var.h>
73 #include <dev/ic/elink3reg.h>
74
75 #include <dev/eisa/eisareg.h>
76 #include <dev/eisa/eisavar.h>
77 #include <dev/eisa/eisadevs.h>
78
79 int ep_eisa_match __P((struct device *, void *, void *));
80 void ep_eisa_attach __P((struct device *, struct device *, void *));
81
82 struct cfattach ep_eisa_ca = {
83 sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
84 };
85
86 /* XXX move these somewhere else */
87 #define EISA_CONTROL 0x0c84
88 #define EISA_RESET 0x04
89 #define EISA_ERROR 0x02
90 #define EISA_ENABLE 0x01
91
92 int
93 ep_eisa_match(parent, match, aux)
94 struct device *parent;
95 void *match, *aux;
96 {
97 struct eisa_attach_args *ea = aux;
98
99 /* must match one of our known ID strings */
100 if (strcmp(ea->ea_idstring, "TCM5091") &&
101 strcmp(ea->ea_idstring, "TCM5092") &&
102 strcmp(ea->ea_idstring, "TCM5093"))
103 return (0);
104
105 return (1);
106 }
107
108 void
109 ep_eisa_attach(parent, self, aux)
110 struct device *parent, *self;
111 void *aux;
112 {
113 struct ep_softc *sc = (void *)self;
114 struct eisa_attach_args *ea = aux;
115 bus_chipset_tag_t bc = ea->ea_bc;
116 bus_io_handle_t ioh;
117 u_int16_t k, conn = 0;
118 eisa_chipset_tag_t ec = ea->ea_ec;
119 eisa_intr_handle_t ih;
120 const char *model, *intrstr;
121 u_int irq;
122
123 /* Map i/o space. */
124 if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &ioh))
125 panic("ep_eisa_attach: can't map i/o space");
126
127 sc->bustype = EP_BUS_EISA;
128 sc->sc_ioh = ioh;
129 sc->sc_bc = bc;
130
131 /* Reset card. */
132 bus_io_write_1(bc, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
133 delay(10);
134 bus_io_write_1(bc, ioh, EISA_CONTROL, EISA_ENABLE);
135 /* Wait for reset? */
136 delay(1000);
137
138 /* XXX What is this doing?! Reading the i/o address? */
139 k = bus_io_read_2(bc, ioh, EP_W0_ADDRESS_CFG);
140 k = (k & 0x1f) * 0x10 + 0x200;
141
142 /* Read the IRQ from the card. */
143 irq = bus_io_read_2(bc, ioh, EP_W0_RESOURCE_CFG) >> 12;
144
145 GO_WINDOW(0);
146 conn = bus_io_read_2(bc, ioh, EP_W0_CONFIG_CTRL);
147
148 if (strcmp(ea->ea_idstring, "TCM5091") == 0)
149 model = EISA_PRODUCT_TCM5091;
150 else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
151 model = EISA_PRODUCT_TCM5092;
152 else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
153 model = EISA_PRODUCT_TCM5093;
154 else
155 model = "unknown model!";
156 kprintf(": %s\n", model);
157
158 if (eisa_intr_map(ec, irq, &ih)) {
159 kprintf("%s: couldn't map interrupt (%u)\n",
160 sc->sc_dev.dv_xname, irq);
161 return;
162 }
163 intrstr = eisa_intr_string(ec, ih);
164 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
165 epintr, sc);
166 if (sc->sc_ih == NULL) {
167 kprintf("%s: couldn't establish interrupt",
168 sc->sc_dev.dv_xname);
169 if (intrstr != NULL)
170 kprintf(" at %s", intrstr);
171 kprintf("\n");
172 return;
173 }
174 if (intrstr != NULL)
175 kprintf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
176 intrstr);
177
178 epconfig(sc, conn);
179 }
180