if_sn_nubus.c revision 1.19 1 /* $NetBSD: if_sn_nubus.c,v 1.19 1998/07/05 00:51:10 jonathan 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 "opt_inet.h"
34
35 #include <sys/param.h>
36 #include <sys/device.h>
37 #include <sys/errno.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <sys/syslog.h>
41 #include <sys/systm.h>
42
43 #include <net/if.h>
44 #include <net/if_ether.h>
45
46 #if 0 /* XXX this shouldn't be necessary; else reinsert */
47 #ifdef INET
48 #include <netinet/in.h>
49 #include <netinet/if_inarp.h>
50 #endif
51 #endif
52
53 #include <machine/bus.h>
54 #include <machine/viareg.h>
55
56 #include <mac68k/nubus/nubus.h>
57 #include <mac68k/dev/if_snreg.h>
58 #include <mac68k/dev/if_snvar.h>
59
60 static int sn_nubus_match __P((struct device *, struct cfdata *, void *));
61 static void sn_nubus_attach __P((struct device *, struct device *, void *));
62 static int sn_nb_card_vendor __P((bus_space_tag_t, bus_space_handle_t,
63 struct nubus_attach_args *));
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,
81 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 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->na_tag, bsh, na)) {
89 default:
90 break;
91
92 case SN_VENDOR_APPLE:
93 case SN_VENDOR_APPLE16:
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(parent, self, aux)
110 struct device *parent, *self;
111 void *aux;
112 {
113 struct sn_softc *sc = (void *)self;
114 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
115 int i, success, offset;
116 bus_space_tag_t bst;
117 bus_space_handle_t bsh, tmp_bsh;
118 u_int8_t myaddr[ETHER_ADDR_LEN];
119
120 (void)(&offset); /* Work around lame gcc initialization bug */
121
122 bst = na->na_tag;
123 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
124 printf(": failed to map memory space.\n");
125 return;
126 }
127
128 sc->sc_regt = bst;
129
130 success = 0;
131
132 sc->slotno = na->slot;
133
134 switch (sn_nb_card_vendor(bst, bsh, na)) {
135 case SN_VENDOR_DAYNA:
136 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
137 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
138 sc->snr_dcr2 = 0;
139 sc->bitmode = 1; /* 32 bit card */
140
141 if (bus_space_subregion(bst, bsh,
142 0x00180000, SN_REGSIZE, &sc->sc_regh)) {
143 printf(": failed to map register space.\n");
144 break;
145 }
146
147 if (bus_space_subregion(bst, bsh,
148 0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
149 printf(": failed to map ROM space.\n");
150 break;
151 }
152
153 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
154
155 offset = 2;
156 success = 1;
157 break;
158
159 case SN_VENDOR_APPLE:
160 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
161 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
162 sc->snr_dcr2 = 0;
163 sc->bitmode = 1; /* 32 bit card */
164
165 if (bus_space_subregion(bst, bsh,
166 0x0, SN_REGSIZE, &sc->sc_regh)) {
167 printf(": failed to map register space.\n");
168 break;
169 }
170
171 if (bus_space_subregion(bst, bsh,
172 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
173 printf(": failed to map ROM space.\n");
174 break;
175 }
176
177 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
178
179 offset = 0;
180 success = 1;
181 break;
182
183 case SN_VENDOR_APPLE16:
184 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
185 DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
186 sc->snr_dcr2 = 0;
187 sc->bitmode = 0; /* 16 bit card */
188
189 if (bus_space_subregion(bst, bsh,
190 0x0, SN_REGSIZE, &sc->sc_regh)) {
191 printf(": failed to map register space.\n");
192 break;
193 }
194
195 if (bus_space_subregion(bst, bsh,
196 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
197 printf(": failed to map ROM space.\n");
198 break;
199 }
200
201 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
202
203 offset = 0;
204 success = 1;
205 break;
206
207 default:
208 /*
209 * You can't actually get this default, the snmatch
210 * will fail for unknown hardware. If you're adding support
211 * for a new card, the following defaults are a
212 * good starting point.
213 */
214 sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
215 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
216 sc->snr_dcr2 = 0;
217 success = 0;
218 printf(": unknown card: attachment incomplete.\n");
219 }
220
221 if (!success) {
222 bus_space_unmap(bst, bsh, NBMEMSIZE);
223 return;
224 }
225
226 /* Regs are addressed as words, big endian. */
227 for (i = 0; i < SN_NREGS; i++) {
228 sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
229 }
230
231 /* snsetup returns 1 if something fails */
232 if (snsetup(sc, myaddr)) {
233 bus_space_unmap(bst, bsh, NBMEMSIZE);
234 return;
235 }
236
237 add_nubus_intr(sc->slotno, snintr, (void *)sc);
238
239 return;
240 }
241
242 static int
243 sn_nb_card_vendor(bst, bsh, na)
244 bus_space_tag_t bst;
245 bus_space_handle_t bsh;
246 struct nubus_attach_args *na;
247 {
248 int vendor = SN_VENDOR_UNKNOWN;
249
250 switch (na->drsw) {
251 case NUBUS_DRSW_3COM:
252 if (na->drhw == NUBUS_DRHW_APPLE_SNT)
253 vendor = SN_VENDOR_APPLE;
254 else if (na->drhw == NUBUS_DRHW_APPLE_SN)
255 vendor = SN_VENDOR_APPLE16;
256 break;
257 case NUBUS_DRSW_APPLE:
258 case NUBUS_DRSW_TECHWORKS:
259 vendor = SN_VENDOR_APPLE;
260 break;
261 case NUBUS_DRSW_GATOR:
262 if (na->drhw == NUBUS_DRHW_KINETICS &&
263 strncmp(nubus_get_card_name(bst, bsh, na->fmt),
264 "EtherPort", 9) != 0)
265 vendor = SN_VENDOR_DAYNA;
266 break;
267 case NUBUS_DRSW_DAYNA:
268 vendor = SN_VENDOR_DAYNA;
269 break;
270 }
271
272 return vendor;
273 }
274