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