if_sn_nubus.c revision 1.27 1 /* $NetBSD: if_sn_nubus.c,v 1.27 2007/06/10 05:59:43 tsutsui Exp $ */
2
3 /*
4 * Copyright (C) 1997 Allen Briggs
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Allen Briggs
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: if_sn_nubus.c,v 1.27 2007/06/10 05:59:43 tsutsui Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/ioctl.h>
40
41 #include <net/if.h>
42 #include <net/if_ether.h>
43
44 #include <machine/bus.h>
45 #include <machine/viareg.h>
46
47 #include <dev/ic/dp83932reg.h>
48 #include <dev/ic/dp83932var.h>
49
50 #include <mac68k/nubus/nubus.h>
51 #include <mac68k/dev/if_snvar.h>
52
53 static int sn_nubus_match(struct device *, struct cfdata *, void *);
54 static void sn_nubus_attach(struct device *, struct device *, void *);
55 static int sn_nb_card_vendor(bus_space_tag_t, bus_space_handle_t,
56 struct nubus_attach_args *);
57
58 CFATTACH_DECL(sn_nubus, sizeof(struct sonic_softc),
59 sn_nubus_match, sn_nubus_attach, NULL, NULL);
60
61
62 static int
63 sn_nubus_match(struct device *parent, struct cfdata *cf, void *aux)
64 {
65 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
66 bus_space_handle_t bsh;
67 int rv;
68
69 if (bus_space_map(na->na_tag,
70 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
71 return (0);
72
73 rv = 0;
74
75 if (na->category == NUBUS_CATEGORY_NETWORK &&
76 na->type == NUBUS_TYPE_ETHERNET) {
77 switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
78 default:
79 break;
80
81 case SN_VENDOR_APPLE:
82 case SN_VENDOR_APPLE16:
83 case SN_VENDOR_ASANTELC:
84 case SN_VENDOR_DAYNA:
85 rv = 1;
86 break;
87 }
88 }
89
90 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
91
92 return rv;
93 }
94
95 /*
96 * Install interface into kernel networking data structures
97 */
98 static void
99 sn_nubus_attach(struct device *parent, struct device *self, void *aux)
100 {
101 struct sonic_softc *sc = (void *)self;
102 struct nubus_attach_args *na = aux;
103 int i, success, offset;
104 bus_space_tag_t bst;
105 bus_space_handle_t bsh, tmp_bsh;
106 uint8_t myaddr[ETHER_ADDR_LEN];
107 const char *cardtype;
108
109 bst = na->na_tag;
110 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
111 printf(": failed to map memory space.\n");
112 return;
113 }
114
115 sc->sc_st = bst;
116 sc->sc_dmat = na->na_dmat;
117
118 cardtype = nubus_get_card_name(bst, bsh, na->fmt);
119
120 success = 0;
121 offset = 0;
122
123 switch (sn_nb_card_vendor(bst, bsh, na)) {
124 case SN_VENDOR_DAYNA:
125 sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0;
126 sc->sc_dcr2 = 0;
127 sc->sc_32bit = 1; /* 32 bit card */
128
129 if (bus_space_subregion(bst, bsh,
130 0x00180000, SONIC_NREGS * 4, &sc->sc_sh)) {
131 printf(": failed to map register space.\n");
132 break;
133 }
134
135 if (bus_space_subregion(bst, bsh,
136 0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
137 printf(": failed to map ROM space.\n");
138 break;
139 }
140
141 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
142
143 offset = 2;
144 success = 1;
145 break;
146
147 case SN_VENDOR_APPLE:
148 sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0;
149 sc->sc_dcr2 = 0;
150 sc->sc_32bit = 1; /* 32 bit card */
151
152 if (bus_space_subregion(bst, bsh,
153 0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
154 printf(": failed to map register space.\n");
155 break;
156 }
157
158 if (bus_space_subregion(bst, bsh,
159 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
160 printf(": failed to map ROM space.\n");
161 break;
162 }
163
164 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
165
166 offset = 0;
167 success = 1;
168 break;
169
170 case SN_VENDOR_APPLE16:
171 sc->sc_dcr = DCR_EXBUS | DCR_BMS | DCR_PO1 |
172 DCR_RFT1 | DCR_TFT0;
173 sc->sc_dcr2 = 0;
174 sc->sc_32bit = 0; /* 16 bit card */
175
176 if (bus_space_subregion(bst, bsh,
177 0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
178 printf(": failed to map register space.\n");
179 break;
180 }
181
182 if (bus_space_subregion(bst, bsh,
183 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
184 printf(": failed to map ROM space.\n");
185 break;
186 }
187
188 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
189
190 offset = 0;
191 success = 1;
192 break;
193
194 case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
195 sc->sc_dcr = DCR_BMS | DCR_PO1 | DCR_RFT1 | DCR_TFT0;
196 sc->sc_dcr2 = 0;
197 sc->sc_32bit = 0; /* 16 bit card */
198
199 if (bus_space_subregion(bst, bsh,
200 0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
201 printf(": failed to map register space.\n");
202 break;
203 }
204
205 if (bus_space_subregion(bst, bsh,
206 0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
207 printf(": failed to map ROM space.\n");
208 break;
209 }
210
211 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
212
213 offset = 0;
214 success = 1;
215 break;
216
217 default:
218 /*
219 * You can't actually get this default, the snmatch
220 * will fail for unknown hardware. If you're adding support
221 * for a new card, the following defaults are a
222 * good starting point.
223 */
224 sc->sc_dcr = DCR_SBUS | DCR_BMS | DCR_RFT1 | DCR_TFT0;
225 sc->sc_dcr2 = 0;
226 sc->sc_32bit = 1;
227 success = 0;
228 printf(": unknown card: attachment incomplete.\n");
229 }
230
231 if (!success) {
232 bus_space_unmap(bst, bsh, NBMEMSIZE);
233 return;
234 }
235
236 /* Regs are addressed as words, big endian. */
237 for (i = 0; i < SONIC_NREGS; i++) {
238 sc->sc_regmap[i] = (bus_size_t)((i * 4) + offset);
239 }
240
241 sc->sc_bigendian = 1;
242
243 printf(": %s\n", cardtype);
244
245 add_nubus_intr(na->slot, (void (*)(void *))sonic_intr, (void *)sc);
246
247 sonic_attach(sc, myaddr);
248
249 return;
250 }
251
252 static int
253 sn_nb_card_vendor(bus_space_tag_t bst, bus_space_handle_t bsh,
254 struct nubus_attach_args *na)
255 {
256 int vendor = SN_VENDOR_UNKNOWN;
257
258 switch (na->drsw) {
259 case NUBUS_DRSW_3COM:
260 if (na->drhw == NUBUS_DRHW_APPLE_SNT)
261 vendor = SN_VENDOR_APPLE;
262 else if (na->drhw == NUBUS_DRHW_APPLE_SN)
263 vendor = SN_VENDOR_APPLE16;
264 break;
265 case NUBUS_DRSW_APPLE:
266 if (na->drhw == NUBUS_DRHW_ASANTE_LC)
267 vendor = SN_VENDOR_ASANTELC;
268 else
269 vendor = SN_VENDOR_APPLE;
270 break;
271 case NUBUS_DRSW_TECHWORKS:
272 vendor = SN_VENDOR_APPLE;
273 break;
274 case NUBUS_DRSW_GATOR:
275 if (na->drhw == NUBUS_DRHW_KINETICS &&
276 strncmp(nubus_get_card_name(bst, bsh, na->fmt),
277 "EtherPort", 9) != 0)
278 vendor = SN_VENDOR_DAYNA;
279 break;
280 case NUBUS_DRSW_DAYNA:
281 vendor = SN_VENDOR_DAYNA;
282 break;
283 }
284
285 return vendor;
286 }
287