if_ep_mca.c revision 1.1.2.3 1 1.1.2.3 bouyer /* $NetBSD: if_ep_mca.c,v 1.1.2.3 2001/04/21 17:48:54 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.2 bouyer * All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 bouyer * by Jaromir Dolecek.
9 1.1.2.2 bouyer *
10 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.1.2.2 bouyer * are met:
13 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 bouyer * must display the following acknowledgement:
20 1.1.2.2 bouyer * This product includes software developed by the NetBSD
21 1.1.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.1.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.1.2.2 bouyer * from this software without specific prior written permission.
25 1.1.2.2 bouyer *
26 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 bouyer */
38 1.1.2.2 bouyer
39 1.1.2.2 bouyer /*
40 1.1.2.2 bouyer * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
41 1.1.2.2 bouyer * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
42 1.1.2.2 bouyer * All rights reserved.
43 1.1.2.2 bouyer *
44 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
45 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
46 1.1.2.2 bouyer * are met:
47 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
48 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
49 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
50 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
51 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
52 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
53 1.1.2.2 bouyer * must display the following acknowledgement:
54 1.1.2.2 bouyer * This product includes software developed by Herb Peyerl.
55 1.1.2.2 bouyer * 4. The name of Herb Peyerl may not be used to endorse or promote products
56 1.1.2.2 bouyer * derived from this software without specific prior written permission.
57 1.1.2.2 bouyer *
58 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 1.1.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.1.2.2 bouyer */
69 1.1.2.2 bouyer
70 1.1.2.2 bouyer /*
71 1.1.2.2 bouyer * Driver for 3Com 3c529 cards.
72 1.1.2.2 bouyer *
73 1.1.2.2 bouyer * Known issues:
74 1.1.2.2 bouyer * - on my 386DX, speed of network is like 100KB/s at best; for bigger
75 1.1.2.2 bouyer * files fetched e.g. via ftp, I get as low as 5KB/s, mostly due
76 1.1.2.2 bouyer * to excessive number of overrun packets. Configuring system to
77 1.1.2.2 bouyer * use smaller TCP window might help, though the performance is
78 1.1.2.2 bouyer * still expected to be very dependant on CPU speed, especially
79 1.1.2.2 bouyer * since ISA and PCI attachments are reported to work OK on pentium
80 1.1.2.2 bouyer * class systems.
81 1.1.2.2 bouyer * Changing ic/elink3.c to use RX Early might help here potentially.
82 1.1.2.2 bouyer */
83 1.1.2.2 bouyer
84 1.1.2.2 bouyer #include <sys/param.h>
85 1.1.2.2 bouyer #include <sys/systm.h>
86 1.1.2.2 bouyer #include <sys/mbuf.h>
87 1.1.2.2 bouyer #include <sys/socket.h>
88 1.1.2.2 bouyer #include <sys/ioctl.h>
89 1.1.2.2 bouyer #include <sys/errno.h>
90 1.1.2.2 bouyer #include <sys/device.h>
91 1.1.2.2 bouyer
92 1.1.2.2 bouyer #include <net/if.h>
93 1.1.2.2 bouyer #include <net/if_ether.h>
94 1.1.2.2 bouyer #include <net/if_media.h>
95 1.1.2.2 bouyer
96 1.1.2.2 bouyer #include <machine/bus.h>
97 1.1.2.2 bouyer
98 1.1.2.2 bouyer #include <dev/mii/miivar.h>
99 1.1.2.2 bouyer
100 1.1.2.2 bouyer #include <dev/ic/elink3var.h>
101 1.1.2.2 bouyer #include <dev/ic/elink3reg.h>
102 1.1.2.2 bouyer
103 1.1.2.2 bouyer #include <dev/mca/mcavar.h>
104 1.1.2.2 bouyer #include <dev/mca/mcadevs.h>
105 1.1.2.2 bouyer
106 1.1.2.2 bouyer /*
107 1.1.2.2 bouyer * MCA constants.
108 1.1.2.2 bouyer */
109 1.1.2.2 bouyer #define MCA_CBIO 0x200 /* Configuration Base IO Address */
110 1.1.2.2 bouyer #define MCA_IOSZ 0x10 /* I/O space size */
111 1.1.2.2 bouyer
112 1.1.2.2 bouyer int ep_mca_match __P((struct device *, struct cfdata *, void *));
113 1.1.2.2 bouyer void ep_mca_attach __P((struct device *, struct device *, void *));
114 1.1.2.2 bouyer
115 1.1.2.2 bouyer struct cfattach ep_mca_ca = {
116 1.1.2.2 bouyer sizeof(struct ep_softc), ep_mca_match, ep_mca_attach
117 1.1.2.2 bouyer };
118 1.1.2.2 bouyer
119 1.1.2.2 bouyer const struct ep_mca_product {
120 1.1.2.2 bouyer u_int32_t epp_prodid; /* MCA product ID */
121 1.1.2.2 bouyer const char *epp_name; /* device name */
122 1.1.2.2 bouyer } ep_mca_products[] = {
123 1.1.2.2 bouyer { MCA_PRODUCT_3C529_TP, "3c529-TP Ethernet Adapter" },
124 1.1.2.2 bouyer { MCA_PRODUCT_3C529_TM, "3c529 Ethernet Adapter (test mode)" },
125 1.1.2.2 bouyer { MCA_PRODUCT_3C529_2T, "3c529 Ethernet Adapter (10base2/T)" },
126 1.1.2.2 bouyer { MCA_PRODUCT_3C529_T, "3c529 Ethernet Adapter (10baseT)" },
127 1.1.2.2 bouyer
128 1.1.2.2 bouyer { 0, NULL },
129 1.1.2.2 bouyer };
130 1.1.2.2 bouyer
131 1.1.2.2 bouyer static const struct ep_mca_product *ep_mca_lookup
132 1.1.2.2 bouyer __P((const struct mca_attach_args *));
133 1.1.2.2 bouyer
134 1.1.2.2 bouyer static const struct ep_mca_product *
135 1.1.2.2 bouyer ep_mca_lookup(ma)
136 1.1.2.2 bouyer const struct mca_attach_args *ma;
137 1.1.2.2 bouyer {
138 1.1.2.2 bouyer const struct ep_mca_product *epp;
139 1.1.2.2 bouyer
140 1.1.2.2 bouyer for (epp = ep_mca_products; epp->epp_name != NULL; epp++)
141 1.1.2.2 bouyer if (ma->ma_id == epp->epp_prodid)
142 1.1.2.2 bouyer return (epp);
143 1.1.2.2 bouyer
144 1.1.2.2 bouyer return (NULL);
145 1.1.2.2 bouyer }
146 1.1.2.2 bouyer
147 1.1.2.2 bouyer int
148 1.1.2.2 bouyer ep_mca_match(parent, match, aux)
149 1.1.2.2 bouyer struct device *parent;
150 1.1.2.2 bouyer struct cfdata *match;
151 1.1.2.2 bouyer void *aux;
152 1.1.2.2 bouyer {
153 1.1.2.2 bouyer struct mca_attach_args *ma = (struct mca_attach_args *) aux;
154 1.1.2.2 bouyer
155 1.1.2.2 bouyer if (ep_mca_lookup(ma) != NULL)
156 1.1.2.2 bouyer return (1);
157 1.1.2.2 bouyer
158 1.1.2.2 bouyer return (0);
159 1.1.2.2 bouyer }
160 1.1.2.2 bouyer
161 1.1.2.2 bouyer void
162 1.1.2.2 bouyer ep_mca_attach(parent, self, aux)
163 1.1.2.2 bouyer struct device *parent, *self;
164 1.1.2.2 bouyer void *aux;
165 1.1.2.2 bouyer {
166 1.1.2.2 bouyer struct ep_softc *sc = (void *)self;
167 1.1.2.2 bouyer struct mca_attach_args *ma = aux;
168 1.1.2.2 bouyer bus_space_handle_t ioh;
169 1.1.2.2 bouyer int pos4, pos5, iobase, irq, media;
170 1.1.2.2 bouyer const struct ep_mca_product *epp;
171 1.1.2.2 bouyer
172 1.1.2.2 bouyer pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
173 1.1.2.2 bouyer pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
174 1.1.2.2 bouyer
175 1.1.2.2 bouyer /*
176 1.1.2.2 bouyer * POS register 2: (adf pos0)
177 1.1.2.2 bouyer * 7 6 5 4 3 2 1 0
178 1.1.2.2 bouyer * \__ enable: 0=adapter disabled, 1=adapter enabled
179 1.1.2.2 bouyer *
180 1.1.2.2 bouyer * POS register 3: (adf pos1)
181 1.1.2.2 bouyer *
182 1.1.2.2 bouyer * 7 6 5 4 3 2 1 0
183 1.1.2.2 bouyer * \________/
184 1.1.2.2 bouyer * \_______ Boot ROM Address Range: 0=disabled
185 1.1.2.2 bouyer * X=0xc2000-0xc3fff + (x * 0x2000)
186 1.1.2.2 bouyer *
187 1.1.2.2 bouyer * POS register 4: (adf pos2)
188 1.1.2.2 bouyer *
189 1.1.2.2 bouyer * 7 6 5 4 3 2 1 0
190 1.1.2.2 bouyer * \________/ \_/
191 1.1.2.2 bouyer * \ \__ Transceiver Type: 00=on-board (RJ45), 01=ext(AUI)
192 1.1.2.2 bouyer * \______ I/O Address Range: 0x200-0x20f + ((x>>2) * 0x400)
193 1.1.2.2 bouyer *
194 1.1.2.2 bouyer * POS register 5: (adf pos3)
195 1.1.2.2 bouyer *
196 1.1.2.2 bouyer * 7 6 5 4 3 2 1 0
197 1.1.2.2 bouyer * \____/
198 1.1.2.2 bouyer * \__ Interrupt level
199 1.1.2.2 bouyer */
200 1.1.2.2 bouyer
201 1.1.2.2 bouyer iobase = MCA_CBIO + (((pos4 & 0xfc) >> 2) * 0x400);
202 1.1.2.2 bouyer
203 1.1.2.2 bouyer /* map the pio registers */
204 1.1.2.2 bouyer if (bus_space_map(ma->ma_iot, iobase, MCA_IOSZ, 0, &ioh)) {
205 1.1.2.2 bouyer printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
206 1.1.2.2 bouyer return;
207 1.1.2.2 bouyer }
208 1.1.2.2 bouyer
209 1.1.2.2 bouyer sc->sc_iot = ma->ma_iot;
210 1.1.2.2 bouyer sc->sc_ioh = ioh;
211 1.1.2.2 bouyer
212 1.1.2.2 bouyer epp = ep_mca_lookup(ma);
213 1.1.2.2 bouyer if (epp == NULL) {
214 1.1.2.2 bouyer printf("\n");
215 1.1.2.2 bouyer panic("ep_mca_attach: impossible");
216 1.1.2.2 bouyer }
217 1.1.2.2 bouyer
218 1.1.2.2 bouyer printf(" slot %d: 3Com %s\n", ma->ma_slot + 1, epp->epp_name);
219 1.1.2.2 bouyer
220 1.1.2.2 bouyer sc->enable = NULL;
221 1.1.2.2 bouyer sc->disable = NULL;
222 1.1.2.2 bouyer sc->enabled = 1;
223 1.1.2.2 bouyer
224 1.1.2.2 bouyer sc->bustype = ELINK_BUS_MCA;
225 1.1.2.2 bouyer sc->ep_flags = 0;
226 1.1.2.2 bouyer
227 1.1.2.2 bouyer if (epconfig(sc, ELINK_CHIPSET_3C509, NULL))
228 1.1.2.2 bouyer return;
229 1.1.2.2 bouyer
230 1.1.2.2 bouyer /* Map and establish the interrupt. */
231 1.1.2.2 bouyer irq = (pos5 & 0x0f);
232 1.1.2.2 bouyer sc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, epintr, sc);
233 1.1.2.2 bouyer if (sc->sc_ih == NULL) {
234 1.1.2.2 bouyer printf("%s: couldn't establish interrupt handler\n",
235 1.1.2.2 bouyer sc->sc_dev.dv_xname);
236 1.1.2.2 bouyer return;
237 1.1.2.2 bouyer }
238 1.1.2.2 bouyer printf("%s: interrupting at irq %d\n", sc->sc_dev.dv_xname, irq);
239 1.1.2.2 bouyer
240 1.1.2.2 bouyer /*
241 1.1.2.2 bouyer * Set default media to be same as the one selected in POS.
242 1.1.2.2 bouyer */
243 1.1.2.2 bouyer switch (pos4 & 0x03) {
244 1.1.2.2 bouyer case 0x00:
245 1.1.2.2 bouyer /* on-board RJ-45 */
246 1.1.2.2 bouyer media = IFM_10_T;
247 1.1.2.2 bouyer break;
248 1.1.2.2 bouyer case 0x01:
249 1.1.2.2 bouyer /* external AUI */
250 1.1.2.2 bouyer media = IFM_10_5;
251 1.1.2.2 bouyer break;
252 1.1.2.2 bouyer case 0x02:
253 1.1.2.2 bouyer /* undefined, should never be set */
254 1.1.2.2 bouyer media = IFM_NONE;
255 1.1.2.2 bouyer break;
256 1.1.2.2 bouyer case 0x03:
257 1.1.2.2 bouyer /* BNC */
258 1.1.2.2 bouyer media = IFM_10_2;
259 1.1.2.2 bouyer break;
260 1.1.2.2 bouyer }
261 1.1.2.2 bouyer ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|media);
262 1.1.2.2 bouyer }
263