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