if_sn_nubus.c revision 1.4 1 /* $NetBSD: if_sn_nubus.c,v 1.4 1997/04/10 03:22:47 briggs 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/param.h>
34 #include <sys/device.h>
35 #include <sys/errno.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
38 #include <sys/syslog.h>
39 #include <sys/systm.h>
40
41 #include <net/if.h>
42 #include <net/if_ether.h>
43
44 #if 0 /* XXX this shouldn't be necessary; else reinsert */
45 #ifdef INET
46 #include <netinet/in.h>
47 #include <netinet/if_inarp.h>
48 #endif
49 #endif
50
51 #include <machine/bus.h>
52 #include <machine/viareg.h>
53
54 #include "nubus.h"
55 #include "if_aereg.h" /* For AE_VENDOR values */
56 #include "if_snreg.h"
57 #include "if_snvar.h"
58
59 static int sn_nubus_match __P((struct device *, struct cfdata *, void *));
60 static void sn_nubus_attach __P((struct device *, struct device *, void *));
61 static int sn_nb_card_vendor __P((struct nubus_attach_args *));
62 static int sn_nb_get_enaddr __P((struct nubus_attach_args *,
63 u_int8_t *, int));
64
65 struct cfattach sn_nubus_ca = {
66 sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
67 };
68
69
70 static int
71 sn_nubus_match(parent, cf, aux)
72 struct device *parent;
73 struct cfdata *cf;
74 void *aux;
75 {
76 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
77 bus_space_handle_t bsh;
78 int rv;
79
80 if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
81 0, &bsh))
82 return (0);
83
84 rv = 0;
85
86 if (na->category == NUBUS_CATEGORY_NETWORK &&
87 na->type == NUBUS_TYPE_ETHERNET) {
88 switch (sn_nb_card_vendor(na)) {
89 default:
90 break;
91
92 case AE_VENDOR_APPLE:
93 case AE_VENDOR_DAYNA:
94 rv = 1;
95 break;
96 }
97 }
98
99 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
100
101 return rv;
102 }
103
104 /*
105 * Install interface into kernel networking data structures
106 */
107 static void
108 sn_nubus_attach(parent, self, aux)
109 struct device *parent, *self;
110 void *aux;
111 {
112 struct sn_softc *sc = (void *)self;
113 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
114 int i, success;
115 bus_space_tag_t bst;
116 bus_space_handle_t bsh, tmp_bsh;
117 u_int8_t myaddr[ETHER_ADDR_LEN];
118
119 bst = na->na_tag;
120 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
121 printf(": failed to map memory space.\n");
122 return;
123 }
124
125 sc->sc_regt = bst;
126 sc->bitmode = 1;
127
128 success = 0;
129
130 sc->bitmode = 1; /* 32-bit card */
131 sc->slotno = na->slot;
132
133 switch (sn_nb_card_vendor(na)) {
134 case AE_VENDOR_DAYNA:
135 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
136 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
137 sc->snr_dcr2 = 0;
138
139 if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
140 &sc->sc_regh)) {
141 printf(": failed to map register space.\n");
142 break;
143 }
144
145 if (bus_space_subregion(bst, bsh, 0x00ffe004, ETHER_ADDR_LEN,
146 &tmp_bsh)) {
147 printf(": failed to map ROM space.\n");
148 break;
149 }
150
151 /*
152 * Copy out the ethernet address from the card's ROM
153 *
154 * See if_sn_obio.c for a discussion of bit reversal
155 * in Apple's MAC address PROMs. As far as I can tell
156 * Dayna stores their Mac address in ethernet format,
157 * not Token Ring.
158 */
159 for (i = 0; i < ETHER_ADDR_LEN; ++i)
160 myaddr[i] = bus_space_read_1(bst, tmp_bsh, i);
161
162 success = 1;
163 break;
164
165 case AE_VENDOR_APPLE:
166 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
167 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
168 sc->snr_dcr2 = 0;
169
170 if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
171 &sc->sc_regh)) {
172 printf(": failed to map register space.\n");
173 break;
174 }
175
176 if (sn_nb_get_enaddr(na, myaddr, 0x8) == 0)
177 success = 1;
178
179 break;
180
181 default:
182 /*
183 * You can't actually get this default, the snmatch
184 * will fail for unknown hardware. If you're adding support
185 * for a new card, the following defaults are a
186 * good starting point.
187 */
188 sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
189 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
190 sc->snr_dcr2 = 0;
191 printf(": attachment incomplete.\n");
192 return;
193 }
194
195 if (!success) {
196 bus_space_unmap(bst, bsh, NBMEMSIZE);
197 return;
198 }
199
200 /* Regs are addressed as words, big endian. */
201 for (i = 0; i < SN_NREGS; i++) {
202 sc->sc_reg_map[i] = (bus_size_t)((i * 4) + 2);
203 }
204
205 /* snsetup returns 1 if something fails */
206 if (snsetup(sc, myaddr)) {
207 bus_space_unmap(bst, bsh, NBMEMSIZE);
208 return;
209 }
210
211 add_nubus_intr(sc->slotno, snintr, (void *)sc);
212
213 return;
214 }
215
216 static int
217 sn_nb_card_vendor(na)
218 struct nubus_attach_args *na;
219 {
220 int vendor;
221
222 switch (na->drsw) {
223 case NUBUS_DRSW_3COM:
224 switch (na->drhw) {
225 case NUBUS_DRHW_APPLE_SN:
226 vendor = AE_VENDOR_APPLE;
227 break;
228 default:
229 vendor = AE_VENDOR_UNKNOWN;
230 break;
231 }
232 break;
233 case NUBUS_DRSW_APPLE:
234 case NUBUS_DRSW_TECHWORKS:
235 vendor = AE_VENDOR_APPLE;
236 break;
237 case NUBUS_DRSW_ASANTE:
238 vendor = AE_VENDOR_ASANTE;
239 break;
240 case NUBUS_DRSW_FARALLON:
241 vendor = AE_VENDOR_FARALLON;
242 break;
243 case NUBUS_DRSW_FOCUS:
244 vendor = AE_VENDOR_FOCUS;
245 break;
246 case NUBUS_DRSW_GATOR:
247 switch (na->drhw) {
248 default:
249 case NUBUS_DRHW_INTERLAN:
250 vendor = AE_VENDOR_INTERLAN;
251 break;
252 case NUBUS_DRHW_KINETICS:
253 if (strncmp(
254 nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
255 vendor = AE_VENDOR_KINETICS;
256 else
257 vendor = AE_VENDOR_DAYNA;
258 break;
259 }
260 break;
261 case NUBUS_DRSW_DAYNA:
262 vendor = AE_VENDOR_DAYNA;
263 break;
264 default:
265 #ifdef DIAGNOSTIC
266 printf("Unknown ethernet drsw: %x\n", na->drsw);
267 #endif
268 vendor = AE_VENDOR_UNKNOWN;
269 }
270 return vendor;
271 }
272
273 static int
274 sn_nb_get_enaddr(na, ep, rsrc1)
275 struct nubus_attach_args *na;
276 u_int8_t *ep;
277 int rsrc1;
278 {
279 nubus_dir dir;
280 nubus_dirent dirent;
281
282 nubus_get_main_dir(na->fmt, &dir);
283 if (nubus_find_rsrc(na->fmt, &dir, na->rsrcid, &dirent) <= 0)
284 return 1;
285 nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
286 if (nubus_find_rsrc(na->fmt, &dir, rsrc1, &dirent) <= 0)
287 return 1;
288 if (nubus_get_ind_data(na->fmt, &dirent, ep, ETHER_ADDR_LEN) <= 0)
289 return 1;
290
291 return 0;
292 }
293
294