if_tra_mca.c revision 1.6 1 /* $NetBSD: if_tra_mca.c,v 1.6 2006/10/12 01:31:25 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2004 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 * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c
41 * by Dave J. Barnes 2004.
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.6 2006/10/12 01:31:25 christos Exp $");
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 #include <sys/socket.h>
51 #include <sys/syslog.h>
52
53 #include <net/if.h>
54 #include <net/if_ether.h>
55 #include <net/if_media.h>
56
57 #include <machine/bus.h>
58 #include <machine/intr.h>
59
60 #include <dev/ic/mb86950reg.h>
61 #include <dev/ic/mb86950var.h>
62
63 #include <dev/mca/mcavar.h>
64 #include <dev/mca/mcadevs.h>
65
66 int tiara_mca_match __P((struct device *, struct cfdata *, void *));
67 void tiara_mca_attach __P((struct device *, struct device *, void *));
68
69 #define TIARA_NPORTS 0x20 /* 32 */
70 #define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */
71
72 struct tiara_softc {
73 struct mb86950_softc sc_mb86950; /* real "mb86950" softc */
74
75 /* MCA-specific goo. */
76 void *sc_ih; /* interrupt cookie */
77 };
78
79 CFATTACH_DECL(tra_mca, sizeof(struct tiara_softc),
80 tiara_mca_match, tiara_mca_attach, NULL, NULL);
81
82 static const struct tiara_mca_product {
83 u_int32_t tra_prodid; /* MCA product ID */
84 const char *tra_name; /* device name */
85 } tiara_mca_products[] = {
86 { MCA_PRODUCT_TIARA, "Tiara LANCard/E2"},
87 { MCA_PRODUCT_TIARA_TP, "Tiara LANCard/E2 TP"},
88 { MCA_PRODUCT_SMC3016, "SMC 3016/MC"},
89 { 0, NULL },
90 };
91
92 static const struct tiara_mca_product *tiara_mca_lookup __P((u_int32_t));
93
94 static const struct tiara_mca_product *
95 tiara_mca_lookup(id)
96 u_int32_t id;
97 {
98 const struct tiara_mca_product *tra_p;
99
100 for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
101 if (id == tra_p->tra_prodid)
102 return (tra_p);
103
104 return (NULL);
105 }
106
107 int
108 tiara_mca_match(struct device *parent __unused, struct cfdata *match __unused,
109 void *aux)
110 {
111 struct mca_attach_args *ma = (struct mca_attach_args *) aux;
112
113 if (tiara_mca_lookup(ma->ma_id) != NULL)
114 return (1);
115
116 return (0);
117 }
118
119 /* see POS diagrams below for explanation */
120 static const int tiara_irq[] = {
121 3, 4, 7, 9
122 };
123 static const int smc_iobase[] = {
124 0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
125 };
126 static const int smc_irq[] = {
127 9, 10, 11, 15, 3, 5, 7, 4
128 };
129
130 void
131 tiara_mca_attach(struct device *parent __unused, struct device *self, void *aux)
132 {
133 struct tiara_softc *isc = device_private(self);
134 struct mb86950_softc *sc = &isc->sc_mb86950;
135 struct mca_attach_args *ma = aux;
136 bus_space_tag_t iot = ma->ma_iot;
137 bus_space_handle_t ioh;
138 u_int8_t myea[ETHER_ADDR_LEN];
139 int pos2;
140 int iobase = 0, irq = 0;
141 const struct tiara_mca_product *tra_p;
142
143 pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
144
145 tra_p = tiara_mca_lookup(ma->ma_id);
146
147 switch (tra_p->tra_prodid) {
148
149 case MCA_PRODUCT_TIARA:
150 case MCA_PRODUCT_TIARA_TP:
151 /*
152 * POS register 2: (adf pos0)
153 * 7 6 5 4 3 2 1 0
154 * \_____/ \_/ \ \__ enable: 0=disabled, 1=enabled
155 * \ \ \___ boot rom: 0=disabled, 1=enabled
156 * \ \______ IRQ 00=3 01=4 10=7 11=9
157 * \_________ Base I/O Port
158 * 0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
159 *
160 * POS register 3: (adf pos1) not used
161 * POS register 4: (adf pos2) not used
162 *
163 * POS register 5: (adf pos3) ignored
164 *
165 * 7 6 5 4 3 2 1 0
166 * 1 1 0 X \____/
167 * \____EPROM Address
168 */
169 iobase = 0x1200 + ((pos2 & 0xf0) << 1);
170 irq = tiara_irq[((pos2 & 0x0c) >> 2)];
171
172 /* XXX SWAG for number pkts. */
173 /* My Tiara LANCard has 128K memory ?!? */
174 sc->txb_num_pkt = 4;
175 sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
176 /* XXX */
177
178 break;
179
180 case MCA_PRODUCT_SMC3016:
181 /*
182 * POS register 2: (adf pos0)
183 * 7 6 5 4 3 2 1 0
184 * \_____/ \___/ \__ enable: 0=disabled, 1=enabled
185 * \ \_____ I/O Address (see ioaddr table)
186 * \__________ IRQ (see irq table)
187 *
188 * POS register 3: (adf pos1) ignored
189 * 7 6 5 4 3 2 1 0
190 * X X X X \____/
191 * \____EPROM Address (0000 = not used)
192 */
193 iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
194 if ((pos2 & 0x80) != 0)
195 irq = smc_irq[((pos2 & 0x70) >> 4)];
196 else {
197 printf("%s: unsupported irq selected\n",
198 sc->sc_dev.dv_xname);
199 return;
200 }
201
202 /* XXX SWAG for number pkts. */
203 /* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
204 sc->txb_num_pkt = 2;
205 sc->rxb_num_pkt = (12288 - 4) / 64;
206 /* XXX */
207
208 break;
209 }
210
211
212 #ifdef DIAGNOSTIC
213 tra_p = tiara_mca_lookup(ma->ma_id);
214 if (tra_p == NULL) {
215 printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
216 return;
217 }
218 #endif
219
220 printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);
221
222 /* Map i/o space. */
223 if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
224 printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
225 return;
226 }
227
228 sc->sc_bst = iot;
229 sc->sc_bsh = ioh;
230
231 /* Get ethernet address from PROM */
232 bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);
233
234 /* This interface is always enabled. */
235 /* XXX
236 sc->sc_stat |= NIC_STAT_ENABLED;
237 */
238
239 /*
240 * Do generic MB86950 attach.
241 */
242 mb86950_attach(sc, myea);
243
244
245 mb86950_config(sc, NULL, 0, 0);
246
247 /* Establish the interrupt handler. */
248 isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
249 mb86950_intr, sc);
250 if (isc->sc_ih == NULL) {
251 printf("%s: couldn't establish interrupt handler\n",
252 sc->sc_dev.dv_xname);
253 return;
254 }
255 }
256