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