if_sn_nubus.c revision 1.24 1 /* $NetBSD: if_sn_nubus.c,v 1.24 2005/01/15 16:00:59 chs 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.24 2005/01/15 16:00:59 chs Exp $");
35
36 #include "opt_inet.h"
37
38 #include <sys/param.h>
39 #include <sys/device.h>
40 #include <sys/errno.h>
41 #include <sys/ioctl.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
44 #include <sys/systm.h>
45
46 #include <net/if.h>
47 #include <net/if_ether.h>
48
49 #if 0 /* XXX this shouldn't be necessary; else reinsert */
50 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/if_inarp.h>
53 #endif
54 #endif
55
56 #include <machine/bus.h>
57 #include <machine/viareg.h>
58
59 #include <mac68k/nubus/nubus.h>
60 #include <mac68k/dev/if_snreg.h>
61 #include <mac68k/dev/if_snvar.h>
62
63 static int sn_nubus_match(struct device *, struct cfdata *, void *);
64 static void sn_nubus_attach(struct device *, struct device *, void *);
65 static int sn_nb_card_vendor(bus_space_tag_t, bus_space_handle_t,
66 struct nubus_attach_args *);
67
68 CFATTACH_DECL(sn_nubus, sizeof(struct sn_softc),
69 sn_nubus_match, sn_nubus_attach, NULL, NULL);
70
71
72 static int
73 sn_nubus_match(struct device *parent, struct cfdata *cf, void *aux)
74 {
75 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
76 bus_space_handle_t bsh;
77 int rv;
78
79 if (bus_space_map(na->na_tag,
80 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
81 return (0);
82
83 rv = 0;
84
85 if (na->category == NUBUS_CATEGORY_NETWORK &&
86 na->type == NUBUS_TYPE_ETHERNET) {
87 switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
88 default:
89 break;
90
91 case SN_VENDOR_APPLE:
92 case SN_VENDOR_APPLE16:
93 case SN_VENDOR_ASANTELC:
94 case SN_VENDOR_DAYNA:
95 rv = 1;
96 break;
97 }
98 }
99
100 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
101
102 return rv;
103 }
104
105 /*
106 * Install interface into kernel networking data structures
107 */
108 static void
109 sn_nubus_attach(struct device *parent, struct device *self, void *aux)
110 {
111 struct sn_softc *sc = (void *)self;
112 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
113 int i, success, offset;
114 bus_space_tag_t bst;
115 bus_space_handle_t bsh, tmp_bsh;
116 u_int8_t myaddr[ETHER_ADDR_LEN];
117 char *cardtype;
118
119 (void)(&offset); /* Work around lame gcc initialization bug */
120
121 bst = na->na_tag;
122 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
123 printf(": failed to map memory space.\n");
124 return;
125 }
126
127 sc->sc_regt = bst;
128
129 cardtype = nubus_get_card_name(bst, bsh, na->fmt);
130
131 success = 0;
132
133 sc->slotno = na->slot;
134
135 switch (sn_nb_card_vendor(bst, bsh, na)) {
136 case SN_VENDOR_DAYNA:
137 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
138 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
139 sc->snr_dcr2 = 0;
140 sc->bitmode = 1; /* 32 bit card */
141
142 if (bus_space_subregion(bst, bsh,
143 0x00180000, SN_REGSIZE, &sc->sc_regh)) {
144 printf(": failed to map register space.\n");
145 break;
146 }
147
148 if (bus_space_subregion(bst, bsh,
149 0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
150 printf(": failed to map ROM space.\n");
151 break;
152 }
153
154 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
155
156 offset = 2;
157 success = 1;
158 break;
159
160 case SN_VENDOR_APPLE:
161 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
162 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
163 sc->snr_dcr2 = 0;
164 sc->bitmode = 1; /* 32 bit card */
165
166 if (bus_space_subregion(bst, bsh,
167 0x0, SN_REGSIZE, &sc->sc_regh)) {
168 printf(": failed to map register space.\n");
169 break;
170 }
171
172 if (bus_space_subregion(bst, bsh,
173 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
174 printf(": failed to map ROM space.\n");
175 break;
176 }
177
178 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
179
180 offset = 0;
181 success = 1;
182 break;
183
184 case SN_VENDOR_APPLE16:
185 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
186 DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
187 sc->snr_dcr2 = 0;
188 sc->bitmode = 0; /* 16 bit card */
189
190 if (bus_space_subregion(bst, bsh,
191 0x0, SN_REGSIZE, &sc->sc_regh)) {
192 printf(": failed to map register space.\n");
193 break;
194 }
195
196 if (bus_space_subregion(bst, bsh,
197 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
198 printf(": failed to map ROM space.\n");
199 break;
200 }
201
202 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
203
204 offset = 0;
205 success = 1;
206 break;
207
208 case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
209 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
210 DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
211 sc->snr_dcr2 = 0;
212 sc->bitmode = 0; /* 16 bit card */
213
214 if (bus_space_subregion(bst, bsh,
215 0x0, SN_REGSIZE, &sc->sc_regh)) {
216 printf(": failed to map register space.\n");
217 break;
218 }
219
220 if (bus_space_subregion(bst, bsh,
221 0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
222 printf(": failed to map ROM space.\n");
223 break;
224 }
225
226 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
227
228 offset = 0;
229 success = 1;
230 break;
231
232 default:
233 /*
234 * You can't actually get this default, the snmatch
235 * will fail for unknown hardware. If you're adding support
236 * for a new card, the following defaults are a
237 * good starting point.
238 */
239 sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
240 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
241 sc->snr_dcr2 = 0;
242 success = 0;
243 printf(": unknown card: attachment incomplete.\n");
244 }
245
246 if (!success) {
247 bus_space_unmap(bst, bsh, NBMEMSIZE);
248 return;
249 }
250
251 /* Regs are addressed as words, big endian. */
252 for (i = 0; i < SN_NREGS; i++) {
253 sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
254 }
255
256 printf(": %s\n", cardtype);
257
258 /* snsetup returns 1 if something fails */
259 if (snsetup(sc, myaddr)) {
260 bus_space_unmap(bst, bsh, NBMEMSIZE);
261 return;
262 }
263
264 add_nubus_intr(sc->slotno, snintr, (void *)sc);
265
266 return;
267 }
268
269 static int
270 sn_nb_card_vendor(bus_space_tag_t bst, bus_space_handle_t bsh,
271 struct nubus_attach_args *na)
272 {
273 int vendor = SN_VENDOR_UNKNOWN;
274
275 switch (na->drsw) {
276 case NUBUS_DRSW_3COM:
277 if (na->drhw == NUBUS_DRHW_APPLE_SNT)
278 vendor = SN_VENDOR_APPLE;
279 else if (na->drhw == NUBUS_DRHW_APPLE_SN)
280 vendor = SN_VENDOR_APPLE16;
281 break;
282 case NUBUS_DRSW_APPLE:
283 if (na->drhw == NUBUS_DRHW_ASANTE_LC)
284 vendor = SN_VENDOR_ASANTELC;
285 else
286 vendor = SN_VENDOR_APPLE;
287 break;
288 case NUBUS_DRSW_TECHWORKS:
289 vendor = SN_VENDOR_APPLE;
290 break;
291 case NUBUS_DRSW_GATOR:
292 if (na->drhw == NUBUS_DRHW_KINETICS &&
293 strncmp(nubus_get_card_name(bst, bsh, na->fmt),
294 "EtherPort", 9) != 0)
295 vendor = SN_VENDOR_DAYNA;
296 break;
297 case NUBUS_DRSW_DAYNA:
298 vendor = SN_VENDOR_DAYNA;
299 break;
300 }
301
302 return vendor;
303 }
304