1 /* $NetBSD: if_ep_mca.c,v 1.11 2003/10/25 18:37:03 christos 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@NetBSD.org>
41 * Copyright (c) 1994 Herb Peyerl <hpeyerl@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 * If you encouter sucky performance, try kernel without DEBUG/DIAGNOSTIC.
74 * This helped on my test machine to change the performance of the card
75 * from like 5KB/s to like 800 KB/s.
76 */
77
78 #include <sys/cdefs.h>
79 __KERNEL_RCSID(0, "$NetBSD: if_ep_mca.c,v 1.11 2003/10/25 18:37:03 christos Exp $");
80
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/mbuf.h>
84 #include <sys/socket.h>
85 #include <sys/ioctl.h>
86 #include <sys/errno.h>
87 #include <sys/device.h>
88
89 #include <net/if.h>
90 #include <net/if_ether.h>
91 #include <net/if_media.h>
92
93 #include <machine/bus.h>
94
95 #include <dev/mii/miivar.h>
96
97 #include <dev/ic/elink3var.h>
98 #include <dev/ic/elink3reg.h>
99
100 #include <dev/mca/mcavar.h>
101 #include <dev/mca/mcadevs.h>
102
103 /*
104 * MCA constants.
105 */
106 #define MCA_CBIO 0x200 /* Configuration Base IO Address */
107 #define MCA_IOSZ 0x10 /* I/O space size */
108
109 int ep_mca_match __P((struct device *, struct cfdata *, void *));
110 void ep_mca_attach __P((struct device *, struct device *, void *));
111
112 CFATTACH_DECL(ep_mca, sizeof(struct ep_softc),
113 ep_mca_match, ep_mca_attach, NULL, NULL);
114
115 const struct ep_mca_product {
116 u_int32_t epp_prodid; /* MCA product ID */
117 const char *epp_name; /* device name */
118 } ep_mca_products[] = {
119 { MCA_PRODUCT_3C529, "3C529 Ethernet Adapter" },
120 { MCA_PRODUCT_3C529_TP, "3c529-TP Ethernet Adapter" },
121 { MCA_PRODUCT_3C529_TM, "3c529 Ethernet Adapter (test mode)" },
122 { MCA_PRODUCT_3C529_2T, "3c529 Ethernet Adapter (10base2/T)" },
123 { MCA_PRODUCT_3C529_T, "3c529 Ethernet Adapter (10baseT)" },
124
125 { 0, NULL },
126 };
127
128 static const struct ep_mca_product *ep_mca_lookup
129 __P((const struct mca_attach_args *));
130
131 static const struct ep_mca_product *
132 ep_mca_lookup(ma)
133 const struct mca_attach_args *ma;
134 {
135 const struct ep_mca_product *epp;
136
137 for (epp = ep_mca_products; epp->epp_name != NULL; epp++)
138 if (ma->ma_id == epp->epp_prodid)
139 return (epp);
140
141 return (NULL);
142 }
143
144 int
145 ep_mca_match(parent, match, aux)
146 struct device *parent;
147 struct cfdata *match;
148 void *aux;
149 {
150 struct mca_attach_args *ma = (struct mca_attach_args *) aux;
151
152 if (ep_mca_lookup(ma) != NULL)
153 return (1);
154
155 return (0);
156 }
157
158 void
159 ep_mca_attach(parent, self, aux)
160 struct device *parent, *self;
161 void *aux;
162 {
163 struct ep_softc *sc = (void *)self;
164 struct mca_attach_args *ma = aux;
165 bus_space_handle_t ioh;
166 int pos4, pos5, iobase, irq, media;
167 const struct ep_mca_product *epp;
168
169 pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
170 pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
171
172 /*
173 * POS register 2: (adf pos0)
174 * 7 6 5 4 3 2 1 0
175 * \__ enable: 0=adapter disabled, 1=adapter enabled
176 *
177 * POS register 3: (adf pos1)
178 *
179 * 7 6 5 4 3 2 1 0
180 * \________/
181 * \_______ Boot ROM Address Range: 0=disabled
182 * X=0xc2000-0xc3fff + (x * 0x2000)
183 *
184 * POS register 4: (adf pos2)
185 *
186 * 7 6 5 4 3 2 1 0
187 * \________/ \_/
188 * \ \__ Transceiver Type: 00=on-board (RJ45), 01=ext(AUI)
189 * \______ I/O Address Range: 0x200-0x20f + ((x>>2) * 0x400)
190 *
191 * POS register 5: (adf pos3)
192 *
193 * 7 6 5 4 3 2 1 0
194 * \____/
195 * \__ Interrupt level
196 */
197
198 iobase = MCA_CBIO + (((pos4 & 0xfc) >> 2) * 0x400);
199 irq = (pos5 & 0x0f);
200
201 /* map the pio registers */
202 if (bus_space_map(ma->ma_iot, iobase, MCA_IOSZ, 0, &ioh)) {
203 printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
204 return;
205 }
206
207 sc->sc_iot = ma->ma_iot;
208 sc->sc_ioh = ioh;
209
210 epp = ep_mca_lookup(ma);
211 if (epp == NULL) {
212 printf("\n");
213 panic("ep_mca_attach: impossible");
214 }
215
216 printf(" slot %d irq %d: 3Com %s\n", ma->ma_slot + 1,
217 irq, epp->epp_name);
218
219 sc->enable = NULL;
220 sc->disable = NULL;
221 sc->enabled = 1;
222
223 sc->bustype = ELINK_BUS_MCA;
224 sc->ep_flags = 0;
225
226 if (epconfig(sc, ELINK_CHIPSET_3C509, NULL))
227 return;
228
229 /* Map and establish the interrupt. */
230 sc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, epintr, sc);
231 if (sc->sc_ih == NULL) {
232 printf("%s: couldn't establish interrupt handler\n",
233 sc->sc_dev.dv_xname);
234 return;
235 }
236
237 /*
238 * Set default media to be same as the one selected in POS.
239 */
240 switch (pos4 & 0x03) {
241 case 0x00:
242 /* on-board RJ-45 */
243 media = IFM_10_T;
244 break;
245 case 0x01:
246 /* external AUI */
247 media = IFM_10_5;
248 break;
249 case 0x02:
250 /* undefined, should never be set */
251 media = IFM_NONE;
252 break;
253 case 0x03:
254 /* BNC */
255 media = IFM_10_2;
256 break;
257 default:
258 printf("%s: cannot determine media\n",
259 sc->sc_dev.dv_xname);
260 return;
261 }
262 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|media);
263 }
Cache object: f7a10e3b9652d1614741e4fdcdd488f8
|