if_tra_mca.c revision 1.2.2.2 1 1.2.2.2 kent /* $NetBSD: if_tra_mca.c,v 1.2.2.2 2005/04/29 11:28:56 kent Exp $ */
2 1.2.2.2 kent
3 1.2.2.2 kent /*-
4 1.2.2.2 kent * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 1.2.2.2 kent * All rights reserved.
6 1.2.2.2 kent *
7 1.2.2.2 kent * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 kent * by Jaromir Dolecek.
9 1.2.2.2 kent *
10 1.2.2.2 kent * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 kent * modification, are permitted provided that the following conditions
12 1.2.2.2 kent * are met:
13 1.2.2.2 kent * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 kent * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 kent * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 kent * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 kent * documentation and/or other materials provided with the distribution.
18 1.2.2.2 kent * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 kent * must display the following acknowledgement:
20 1.2.2.2 kent * This product includes software developed by the NetBSD
21 1.2.2.2 kent * Foundation, Inc. and its contributors.
22 1.2.2.2 kent * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 kent * contributors may be used to endorse or promote products derived
24 1.2.2.2 kent * from this software without specific prior written permission.
25 1.2.2.2 kent *
26 1.2.2.2 kent * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 kent * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 kent * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 kent * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 kent * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 kent * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 kent * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 kent * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 kent * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 kent * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 kent * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 kent */
38 1.2.2.2 kent
39 1.2.2.2 kent /*
40 1.2.2.2 kent * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c
41 1.2.2.2 kent * by Dave J. Barnes 2004.
42 1.2.2.2 kent */
43 1.2.2.2 kent
44 1.2.2.2 kent #include <sys/cdefs.h>
45 1.2.2.2 kent __KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.2.2.2 2005/04/29 11:28:56 kent Exp $");
46 1.2.2.2 kent
47 1.2.2.2 kent #include <sys/param.h>
48 1.2.2.2 kent #include <sys/systm.h>
49 1.2.2.2 kent #include <sys/device.h>
50 1.2.2.2 kent #include <sys/socket.h>
51 1.2.2.2 kent #include <sys/syslog.h>
52 1.2.2.2 kent
53 1.2.2.2 kent #include <net/if.h>
54 1.2.2.2 kent #include <net/if_ether.h>
55 1.2.2.2 kent #include <net/if_media.h>
56 1.2.2.2 kent
57 1.2.2.2 kent #include <machine/bus.h>
58 1.2.2.2 kent #include <machine/intr.h>
59 1.2.2.2 kent
60 1.2.2.2 kent #include <dev/ic/mb86950reg.h>
61 1.2.2.2 kent #include <dev/ic/mb86950var.h>
62 1.2.2.2 kent
63 1.2.2.2 kent #include <dev/mca/mcavar.h>
64 1.2.2.2 kent #include <dev/mca/mcadevs.h>
65 1.2.2.2 kent
66 1.2.2.2 kent int tiara_mca_match __P((struct device *, struct cfdata *, void *));
67 1.2.2.2 kent void tiara_mca_attach __P((struct device *, struct device *, void *));
68 1.2.2.2 kent
69 1.2.2.2 kent #define TIARA_NPORTS 0x20 /* 32 */
70 1.2.2.2 kent #define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */
71 1.2.2.2 kent
72 1.2.2.2 kent struct tiara_softc {
73 1.2.2.2 kent struct mb86950_softc sc_mb86950; /* real "mb86950" softc */
74 1.2.2.2 kent
75 1.2.2.2 kent /* MCA-specific goo. */
76 1.2.2.2 kent void *sc_ih; /* interrupt cookie */
77 1.2.2.2 kent };
78 1.2.2.2 kent
79 1.2.2.2 kent CFATTACH_DECL(tra_mca, sizeof(struct tiara_softc),
80 1.2.2.2 kent tiara_mca_match, tiara_mca_attach, NULL, NULL);
81 1.2.2.2 kent
82 1.2.2.2 kent static const struct tiara_mca_product {
83 1.2.2.2 kent u_int32_t tra_prodid; /* MCA product ID */
84 1.2.2.2 kent const char *tra_name; /* device name */
85 1.2.2.2 kent } tiara_mca_products[] = {
86 1.2.2.2 kent { MCA_PRODUCT_TIARA, "Tiara LANCard/E2"},
87 1.2.2.2 kent { MCA_PRODUCT_TIARA_TP, "Tiara LANCard/E2 TP"},
88 1.2.2.2 kent { MCA_PRODUCT_SMC3016, "SMC 3016/MC"},
89 1.2.2.2 kent { 0 }
90 1.2.2.2 kent };
91 1.2.2.2 kent
92 1.2.2.2 kent static const struct tiara_mca_product *tiara_mca_lookup __P((u_int32_t));
93 1.2.2.2 kent
94 1.2.2.2 kent static const struct tiara_mca_product *
95 1.2.2.2 kent tiara_mca_lookup(id)
96 1.2.2.2 kent u_int32_t id;
97 1.2.2.2 kent {
98 1.2.2.2 kent const struct tiara_mca_product *tra_p;
99 1.2.2.2 kent
100 1.2.2.2 kent for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
101 1.2.2.2 kent if (id == tra_p->tra_prodid)
102 1.2.2.2 kent return (tra_p);
103 1.2.2.2 kent
104 1.2.2.2 kent return (NULL);
105 1.2.2.2 kent }
106 1.2.2.2 kent
107 1.2.2.2 kent int
108 1.2.2.2 kent tiara_mca_match(parent, match, aux)
109 1.2.2.2 kent struct device *parent;
110 1.2.2.2 kent struct cfdata *match;
111 1.2.2.2 kent void *aux;
112 1.2.2.2 kent {
113 1.2.2.2 kent struct mca_attach_args *ma = (struct mca_attach_args *) aux;
114 1.2.2.2 kent
115 1.2.2.2 kent if (tiara_mca_lookup(ma->ma_id) != NULL)
116 1.2.2.2 kent return (1);
117 1.2.2.2 kent
118 1.2.2.2 kent return (0);
119 1.2.2.2 kent }
120 1.2.2.2 kent
121 1.2.2.2 kent /* see POS diagrams below for explanation */
122 1.2.2.2 kent static const int tiara_irq[] = {
123 1.2.2.2 kent 3, 4, 7, 9
124 1.2.2.2 kent };
125 1.2.2.2 kent static const int smc_iobase[] = {
126 1.2.2.2 kent 0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
127 1.2.2.2 kent };
128 1.2.2.2 kent static const int smc_irq[] = {
129 1.2.2.2 kent 9, 10, 11, 15, 3, 5, 7, 4
130 1.2.2.2 kent };
131 1.2.2.2 kent
132 1.2.2.2 kent void
133 1.2.2.2 kent tiara_mca_attach(parent, self, aux)
134 1.2.2.2 kent struct device *parent, *self;
135 1.2.2.2 kent void *aux;
136 1.2.2.2 kent {
137 1.2.2.2 kent struct tiara_softc *isc = (struct tiara_softc *)self;
138 1.2.2.2 kent struct mb86950_softc *sc = &isc->sc_mb86950;
139 1.2.2.2 kent struct mca_attach_args *ma = aux;
140 1.2.2.2 kent bus_space_tag_t iot = ma->ma_iot;
141 1.2.2.2 kent bus_space_handle_t ioh;
142 1.2.2.2 kent u_int8_t myea[ETHER_ADDR_LEN];
143 1.2.2.2 kent int pos2;
144 1.2.2.2 kent int iobase = 0, irq = 0;
145 1.2.2.2 kent const struct tiara_mca_product *tra_p;
146 1.2.2.2 kent
147 1.2.2.2 kent pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
148 1.2.2.2 kent
149 1.2.2.2 kent tra_p = tiara_mca_lookup(ma->ma_id);
150 1.2.2.2 kent
151 1.2.2.2 kent switch (tra_p->tra_prodid) {
152 1.2.2.2 kent
153 1.2.2.2 kent case MCA_PRODUCT_TIARA:
154 1.2.2.2 kent case MCA_PRODUCT_TIARA_TP:
155 1.2.2.2 kent /*
156 1.2.2.2 kent * POS register 2: (adf pos0)
157 1.2.2.2 kent * 7 6 5 4 3 2 1 0
158 1.2.2.2 kent * \_____/ \_/ \ \__ enable: 0=disabled, 1=enabled
159 1.2.2.2 kent * \ \ \___ boot rom: 0=disabled, 1=enabled
160 1.2.2.2 kent * \ \______ IRQ 00=3 01=4 10=7 11=9
161 1.2.2.2 kent * \_________ Base I/O Port
162 1.2.2.2 kent * 0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
163 1.2.2.2 kent *
164 1.2.2.2 kent * POS register 3: (adf pos1) not used
165 1.2.2.2 kent * POS register 4: (adf pos2) not used
166 1.2.2.2 kent *
167 1.2.2.2 kent * POS register 5: (adf pos3) ignored
168 1.2.2.2 kent *
169 1.2.2.2 kent * 7 6 5 4 3 2 1 0
170 1.2.2.2 kent * 1 1 0 X \____/
171 1.2.2.2 kent * \____EPROM Address
172 1.2.2.2 kent */
173 1.2.2.2 kent iobase = 0x1200 + ((pos2 & 0xf0) << 1);
174 1.2.2.2 kent irq = tiara_irq[((pos2 & 0x0c) >> 2)];
175 1.2.2.2 kent
176 1.2.2.2 kent /* XXX SWAG for number pkts. */
177 1.2.2.2 kent /* My Tiara LANCard has 128K memory ?!? */
178 1.2.2.2 kent sc->txb_num_pkt = 4;
179 1.2.2.2 kent sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
180 1.2.2.2 kent /* XXX */
181 1.2.2.2 kent
182 1.2.2.2 kent break;
183 1.2.2.2 kent
184 1.2.2.2 kent case MCA_PRODUCT_SMC3016:
185 1.2.2.2 kent /*
186 1.2.2.2 kent * POS register 2: (adf pos0)
187 1.2.2.2 kent * 7 6 5 4 3 2 1 0
188 1.2.2.2 kent * \_____/ \___/ \__ enable: 0=disabled, 1=enabled
189 1.2.2.2 kent * \ \_____ I/O Address (see ioaddr table)
190 1.2.2.2 kent * \__________ IRQ (see irq table)
191 1.2.2.2 kent *
192 1.2.2.2 kent * POS register 3: (adf pos1) ignored
193 1.2.2.2 kent * 7 6 5 4 3 2 1 0
194 1.2.2.2 kent * X X X X \____/
195 1.2.2.2 kent * \____EPROM Address (0000 = not used)
196 1.2.2.2 kent */
197 1.2.2.2 kent iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
198 1.2.2.2 kent if ((pos2 & 0x80) != 0)
199 1.2.2.2 kent irq = smc_irq[((pos2 & 0x70) >> 4)];
200 1.2.2.2 kent else {
201 1.2.2.2 kent printf("%s: unsupported irq selected\n",
202 1.2.2.2 kent sc->sc_dev.dv_xname);
203 1.2.2.2 kent return;
204 1.2.2.2 kent }
205 1.2.2.2 kent
206 1.2.2.2 kent /* XXX SWAG for number pkts. */
207 1.2.2.2 kent /* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
208 1.2.2.2 kent sc->txb_num_pkt = 2;
209 1.2.2.2 kent sc->rxb_num_pkt = (12288 - 4) / 64;
210 1.2.2.2 kent /* XXX */
211 1.2.2.2 kent
212 1.2.2.2 kent break;
213 1.2.2.2 kent }
214 1.2.2.2 kent
215 1.2.2.2 kent
216 1.2.2.2 kent #ifdef DIAGNOSTIC
217 1.2.2.2 kent tra_p = tiara_mca_lookup(ma->ma_id);
218 1.2.2.2 kent if (tra_p == NULL) {
219 1.2.2.2 kent printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
220 1.2.2.2 kent return;
221 1.2.2.2 kent }
222 1.2.2.2 kent #endif
223 1.2.2.2 kent
224 1.2.2.2 kent printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);
225 1.2.2.2 kent
226 1.2.2.2 kent /* Map i/o space. */
227 1.2.2.2 kent if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
228 1.2.2.2 kent printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
229 1.2.2.2 kent return;
230 1.2.2.2 kent }
231 1.2.2.2 kent
232 1.2.2.2 kent sc->sc_bst = iot;
233 1.2.2.2 kent sc->sc_bsh = ioh;
234 1.2.2.2 kent
235 1.2.2.2 kent /* Get ethernet address from PROM */
236 1.2.2.2 kent bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);
237 1.2.2.2 kent
238 1.2.2.2 kent /* This interface is always enabled. */
239 1.2.2.2 kent /* XXX
240 1.2.2.2 kent sc->sc_stat |= NIC_STAT_ENABLED;
241 1.2.2.2 kent */
242 1.2.2.2 kent
243 1.2.2.2 kent /*
244 1.2.2.2 kent * Do generic MB86950 attach.
245 1.2.2.2 kent */
246 1.2.2.2 kent mb86950_attach(sc, myea);
247 1.2.2.2 kent
248 1.2.2.2 kent
249 1.2.2.2 kent mb86950_config(sc, NULL, 0, 0);
250 1.2.2.2 kent
251 1.2.2.2 kent /* Establish the interrupt handler. */
252 1.2.2.2 kent isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
253 1.2.2.2 kent mb86950_intr, sc);
254 1.2.2.2 kent if (isc->sc_ih == NULL) {
255 1.2.2.2 kent printf("%s: couldn't establish interrupt handler\n",
256 1.2.2.2 kent sc->sc_dev.dv_xname);
257 1.2.2.2 kent return;
258 1.2.2.2 kent }
259 1.2.2.2 kent }
260