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