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