if_ep_isa.c revision 1.1 1 /* $NetBSD: if_ep_isa.c,v 1.1 1996/04/25 02:15:47 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) novatel.ca>
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/mbuf.h>
37 #include <sys/socket.h>
38 #include <sys/ioctl.h>
39 #include <sys/errno.h>
40 #include <sys/syslog.h>
41 #include <sys/select.h>
42 #include <sys/device.h>
43
44 #include <net/if.h>
45 #include <net/if_dl.h>
46 #include <net/if_types.h>
47 #include <net/netisr.h>
48
49 #ifdef INET
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/in_var.h>
53 #include <netinet/ip.h>
54 #include <netinet/if_ether.h>
55 #endif
56
57 #ifdef NS
58 #include <netns/ns.h>
59 #include <netns/ns_if.h>
60 #endif
61
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #include <net/bpfdesc.h>
65 #endif
66
67 #include <machine/cpu.h>
68 #include <machine/pio.h>
69
70 #include <dev/ic/elink3var.h>
71 #include <dev/ic/elink3reg.h>
72
73 #include <dev/isa/isavar.h>
74 #include <dev/isa/elink.h>
75
76 int ep_isa_probe __P((struct device *, void *, void *));
77 void ep_isa_attach __P((struct device *, struct device *, void *));
78
79 struct cfattach ep_isa_ca = {
80 sizeof(struct ep_softc), ep_isa_probe, ep_isa_attach
81 };
82
83 static void epaddcard __P((int, int));
84
85 #define MAXEPCARDS 10 /* 10 ISA slots */
86
87 static struct epcard {
88 int iobase;
89 int irq;
90 char available;
91 } epcards[MAXEPCARDS];
92 static int nepcards;
93
94 static void
95 epaddcard(iobase, irq)
96 int iobase;
97 int irq;
98 {
99
100 if (nepcards >= MAXEPCARDS)
101 return;
102 epcards[nepcards].iobase = iobase;
103 epcards[nepcards].irq = (irq == 2) ? 9 : irq;
104 epcards[nepcards].available = 1;
105 nepcards++;
106 }
107
108 /*
109 * 3c509 cards on the ISA bus are probed in ethernet address order.
110 * The probe sequence requires careful orchestration, and we'd like
111 * like to allow the irq and base address to be wildcarded. So, we
112 * probe all the cards the first time epprobe() is called. On subsequent
113 * calls we look for matching cards.
114 */
115 int
116 ep_isa_probe(parent, match, aux)
117 struct device *parent;
118 void *match, *aux;
119 {
120 struct isa_attach_args *ia = aux;
121 static int probed;
122 int slot, iobase, irq, i;
123 u_short vendor, model;
124
125 if (!probed) {
126 probed = 1;
127
128 for (slot = 0; slot < MAXEPCARDS; slot++) {
129 elink_reset();
130 elink_idseq(ELINK_509_POLY);
131
132 /* Untag all the adapters so they will talk to us. */
133 if (slot == 0)
134 outb(ELINK_ID_PORT, TAG_ADAPTER + 0);
135
136 vendor =
137 htons(epreadeeprom(ELINK_ID_PORT, EEPROM_MFG_ID));
138 if (vendor != MFG_ID)
139 continue;
140
141 model =
142 htons(epreadeeprom(ELINK_ID_PORT, EEPROM_PROD_ID));
143 if ((model & 0xfff0) != PROD_ID) {
144 #ifndef trusted
145 printf(
146 "ep_isa_probe: ignoring model %04x\n", model);
147 #endif
148 continue;
149 }
150
151 iobase = epreadeeprom(ELINK_ID_PORT, EEPROM_ADDR_CFG);
152 iobase = (iobase & 0x1f) * 0x10 + 0x200;
153
154 irq = epreadeeprom(ELINK_ID_PORT, EEPROM_RESOURCE_CFG);
155 irq >>= 12;
156 epaddcard(iobase, irq);
157
158 /* so card will not respond to contention again */
159 outb(ELINK_ID_PORT, TAG_ADAPTER + 1);
160
161 /*
162 * XXX: this should probably not be done here
163 * because it enables the drq/irq lines from
164 * the board. Perhaps it should be done after
165 * we have checked for irq/drq collisions?
166 */
167 outb(ELINK_ID_PORT, ACTIVATE_ADAPTER_TO_CONFIG);
168 }
169 /* XXX should we sort by ethernet address? */
170 }
171
172 for (i = 0; i < nepcards; i++) {
173 if (epcards[i].available == 0)
174 continue;
175 if (ia->ia_iobase != IOBASEUNK &&
176 ia->ia_iobase != epcards[i].iobase)
177 continue;
178 if (ia->ia_irq != IRQUNK &&
179 ia->ia_irq != epcards[i].irq)
180 continue;
181 goto good;
182 }
183 return 0;
184
185 good:
186 epcards[i].available = 0;
187 ia->ia_iobase = epcards[i].iobase;
188 ia->ia_irq = epcards[i].irq;
189 ia->ia_iosize = 0x10;
190 ia->ia_msize = 0;
191 return 1;
192 }
193
194 void
195 ep_isa_attach(parent, self, aux)
196 struct device *parent, *self;
197 void *aux;
198 {
199 struct ep_softc *sc = (void *)self;
200 struct isa_attach_args *ia = aux;
201 u_short conn = 0;
202 int iobase;
203
204 sc->ep_iobase = iobase = ia->ia_iobase;
205 sc->bustype = EP_BUS_ISA;
206
207 GO_WINDOW(0);
208 conn = inw(iobase + EP_W0_CONFIG_CTRL);
209
210 printf(": 3Com 3C509 Ethernet\n");
211
212 epconfig(sc, conn);
213
214 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
215 IPL_NET, epintr, sc);
216 }
217