if_sn_nubus.c revision 1.4 1 1.4 briggs /* $NetBSD: if_sn_nubus.c,v 1.4 1997/04/10 03:22:47 briggs Exp $ */
2 1.1 briggs
3 1.1 briggs /*
4 1.1 briggs * Copyright (C) 1997 Allen Briggs
5 1.1 briggs * All rights reserved.
6 1.1 briggs *
7 1.1 briggs * Redistribution and use in source and binary forms, with or without
8 1.1 briggs * modification, are permitted provided that the following conditions
9 1.1 briggs * are met:
10 1.1 briggs * 1. Redistributions of source code must retain the above copyright
11 1.1 briggs * notice, this list of conditions and the following disclaimer.
12 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 briggs * notice, this list of conditions and the following disclaimer in the
14 1.1 briggs * documentation and/or other materials provided with the distribution.
15 1.1 briggs * 3. All advertising materials mentioning features or use of this software
16 1.1 briggs * must display the following acknowledgement:
17 1.1 briggs * This product includes software developed by Allen Briggs
18 1.1 briggs * 4. The name of the author may not be used to endorse or promote products
19 1.1 briggs * derived from this software without specific prior written permission.
20 1.1 briggs *
21 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 briggs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 briggs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 briggs */
32 1.1 briggs
33 1.1 briggs #include <sys/param.h>
34 1.1 briggs #include <sys/device.h>
35 1.1 briggs #include <sys/errno.h>
36 1.1 briggs #include <sys/ioctl.h>
37 1.1 briggs #include <sys/socket.h>
38 1.1 briggs #include <sys/syslog.h>
39 1.1 briggs #include <sys/systm.h>
40 1.1 briggs
41 1.1 briggs #include <net/if.h>
42 1.2 is #include <net/if_ether.h>
43 1.1 briggs
44 1.2 is #if 0 /* XXX this shouldn't be necessary; else reinsert */
45 1.1 briggs #ifdef INET
46 1.1 briggs #include <netinet/in.h>
47 1.2 is #include <netinet/if_inarp.h>
48 1.2 is #endif
49 1.1 briggs #endif
50 1.1 briggs
51 1.1 briggs #include <machine/bus.h>
52 1.1 briggs #include <machine/viareg.h>
53 1.1 briggs
54 1.1 briggs #include "nubus.h"
55 1.1 briggs #include "if_aereg.h" /* For AE_VENDOR values */
56 1.1 briggs #include "if_snreg.h"
57 1.1 briggs #include "if_snvar.h"
58 1.1 briggs
59 1.1 briggs static int sn_nubus_match __P((struct device *, struct cfdata *, void *));
60 1.1 briggs static void sn_nubus_attach __P((struct device *, struct device *, void *));
61 1.1 briggs static int sn_nb_card_vendor __P((struct nubus_attach_args *));
62 1.4 briggs static int sn_nb_get_enaddr __P((struct nubus_attach_args *,
63 1.4 briggs u_int8_t *, int));
64 1.1 briggs
65 1.1 briggs struct cfattach sn_nubus_ca = {
66 1.1 briggs sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
67 1.1 briggs };
68 1.1 briggs
69 1.2 is
70 1.1 briggs static int
71 1.1 briggs sn_nubus_match(parent, cf, aux)
72 1.1 briggs struct device *parent;
73 1.1 briggs struct cfdata *cf;
74 1.1 briggs void *aux;
75 1.1 briggs {
76 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
77 1.1 briggs bus_space_handle_t bsh;
78 1.1 briggs int rv;
79 1.1 briggs
80 1.1 briggs if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
81 1.1 briggs 0, &bsh))
82 1.1 briggs return (0);
83 1.1 briggs
84 1.1 briggs rv = 0;
85 1.1 briggs
86 1.1 briggs if (na->category == NUBUS_CATEGORY_NETWORK &&
87 1.1 briggs na->type == NUBUS_TYPE_ETHERNET) {
88 1.1 briggs switch (sn_nb_card_vendor(na)) {
89 1.1 briggs default:
90 1.1 briggs break;
91 1.1 briggs
92 1.4 briggs case AE_VENDOR_APPLE:
93 1.1 briggs case AE_VENDOR_DAYNA:
94 1.1 briggs rv = 1;
95 1.1 briggs break;
96 1.1 briggs }
97 1.1 briggs }
98 1.1 briggs
99 1.1 briggs bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
100 1.1 briggs
101 1.1 briggs return rv;
102 1.1 briggs }
103 1.1 briggs
104 1.1 briggs /*
105 1.1 briggs * Install interface into kernel networking data structures
106 1.1 briggs */
107 1.1 briggs static void
108 1.1 briggs sn_nubus_attach(parent, self, aux)
109 1.1 briggs struct device *parent, *self;
110 1.1 briggs void *aux;
111 1.1 briggs {
112 1.1 briggs struct sn_softc *sc = (void *)self;
113 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
114 1.1 briggs int i, success;
115 1.1 briggs bus_space_tag_t bst;
116 1.1 briggs bus_space_handle_t bsh, tmp_bsh;
117 1.2 is u_int8_t myaddr[ETHER_ADDR_LEN];
118 1.1 briggs
119 1.1 briggs bst = na->na_tag;
120 1.1 briggs if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
121 1.1 briggs printf(": failed to map memory space.\n");
122 1.1 briggs return;
123 1.1 briggs }
124 1.1 briggs
125 1.1 briggs sc->sc_regt = bst;
126 1.1 briggs sc->bitmode = 1;
127 1.1 briggs
128 1.1 briggs success = 0;
129 1.1 briggs
130 1.1 briggs sc->bitmode = 1; /* 32-bit card */
131 1.1 briggs sc->slotno = na->slot;
132 1.1 briggs
133 1.1 briggs switch (sn_nb_card_vendor(na)) {
134 1.1 briggs case AE_VENDOR_DAYNA:
135 1.3 briggs sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
136 1.3 briggs DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
137 1.3 briggs sc->snr_dcr2 = 0;
138 1.1 briggs
139 1.1 briggs if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
140 1.1 briggs &sc->sc_regh)) {
141 1.1 briggs printf(": failed to map register space.\n");
142 1.1 briggs break;
143 1.1 briggs }
144 1.1 briggs
145 1.1 briggs if (bus_space_subregion(bst, bsh, 0x00ffe004, ETHER_ADDR_LEN,
146 1.1 briggs &tmp_bsh)) {
147 1.1 briggs printf(": failed to map ROM space.\n");
148 1.1 briggs break;
149 1.1 briggs }
150 1.1 briggs
151 1.1 briggs /*
152 1.1 briggs * Copy out the ethernet address from the card's ROM
153 1.3 briggs *
154 1.3 briggs * See if_sn_obio.c for a discussion of bit reversal
155 1.3 briggs * in Apple's MAC address PROMs. As far as I can tell
156 1.3 briggs * Dayna stores their Mac address in ethernet format,
157 1.3 briggs * not Token Ring.
158 1.1 briggs */
159 1.1 briggs for (i = 0; i < ETHER_ADDR_LEN; ++i)
160 1.2 is myaddr[i] = bus_space_read_1(bst, tmp_bsh, i);
161 1.1 briggs
162 1.1 briggs success = 1;
163 1.1 briggs break;
164 1.1 briggs
165 1.4 briggs case AE_VENDOR_APPLE:
166 1.4 briggs sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
167 1.4 briggs DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
168 1.4 briggs sc->snr_dcr2 = 0;
169 1.4 briggs
170 1.4 briggs if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
171 1.4 briggs &sc->sc_regh)) {
172 1.4 briggs printf(": failed to map register space.\n");
173 1.4 briggs break;
174 1.4 briggs }
175 1.4 briggs
176 1.4 briggs if (sn_nb_get_enaddr(na, myaddr, 0x8) == 0)
177 1.4 briggs success = 1;
178 1.4 briggs
179 1.4 briggs break;
180 1.4 briggs
181 1.1 briggs default:
182 1.1 briggs /*
183 1.1 briggs * You can't actually get this default, the snmatch
184 1.1 briggs * will fail for unknown hardware. If you're adding support
185 1.1 briggs * for a new card, the following defaults are a
186 1.1 briggs * good starting point.
187 1.1 briggs */
188 1.3 briggs sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
189 1.3 briggs DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
190 1.3 briggs sc->snr_dcr2 = 0;
191 1.4 briggs printf(": attachment incomplete.\n");
192 1.1 briggs return;
193 1.1 briggs }
194 1.1 briggs
195 1.1 briggs if (!success) {
196 1.1 briggs bus_space_unmap(bst, bsh, NBMEMSIZE);
197 1.1 briggs return;
198 1.1 briggs }
199 1.1 briggs
200 1.3 briggs /* Regs are addressed as words, big endian. */
201 1.3 briggs for (i = 0; i < SN_NREGS; i++) {
202 1.3 briggs sc->sc_reg_map[i] = (bus_size_t)((i * 4) + 2);
203 1.3 briggs }
204 1.3 briggs
205 1.3 briggs /* snsetup returns 1 if something fails */
206 1.3 briggs if (snsetup(sc, myaddr)) {
207 1.3 briggs bus_space_unmap(bst, bsh, NBMEMSIZE);
208 1.3 briggs return;
209 1.3 briggs }
210 1.3 briggs
211 1.3 briggs add_nubus_intr(sc->slotno, snintr, (void *)sc);
212 1.3 briggs
213 1.3 briggs return;
214 1.1 briggs }
215 1.1 briggs
216 1.1 briggs static int
217 1.1 briggs sn_nb_card_vendor(na)
218 1.1 briggs struct nubus_attach_args *na;
219 1.1 briggs {
220 1.1 briggs int vendor;
221 1.1 briggs
222 1.1 briggs switch (na->drsw) {
223 1.1 briggs case NUBUS_DRSW_3COM:
224 1.4 briggs switch (na->drhw) {
225 1.4 briggs case NUBUS_DRHW_APPLE_SN:
226 1.4 briggs vendor = AE_VENDOR_APPLE;
227 1.4 briggs break;
228 1.4 briggs default:
229 1.4 briggs vendor = AE_VENDOR_UNKNOWN;
230 1.4 briggs break;
231 1.4 briggs }
232 1.4 briggs break;
233 1.1 briggs case NUBUS_DRSW_APPLE:
234 1.1 briggs case NUBUS_DRSW_TECHWORKS:
235 1.1 briggs vendor = AE_VENDOR_APPLE;
236 1.1 briggs break;
237 1.1 briggs case NUBUS_DRSW_ASANTE:
238 1.1 briggs vendor = AE_VENDOR_ASANTE;
239 1.1 briggs break;
240 1.1 briggs case NUBUS_DRSW_FARALLON:
241 1.1 briggs vendor = AE_VENDOR_FARALLON;
242 1.1 briggs break;
243 1.1 briggs case NUBUS_DRSW_FOCUS:
244 1.1 briggs vendor = AE_VENDOR_FOCUS;
245 1.1 briggs break;
246 1.1 briggs case NUBUS_DRSW_GATOR:
247 1.1 briggs switch (na->drhw) {
248 1.1 briggs default:
249 1.1 briggs case NUBUS_DRHW_INTERLAN:
250 1.1 briggs vendor = AE_VENDOR_INTERLAN;
251 1.1 briggs break;
252 1.1 briggs case NUBUS_DRHW_KINETICS:
253 1.1 briggs if (strncmp(
254 1.1 briggs nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
255 1.1 briggs vendor = AE_VENDOR_KINETICS;
256 1.1 briggs else
257 1.1 briggs vendor = AE_VENDOR_DAYNA;
258 1.1 briggs break;
259 1.1 briggs }
260 1.3 briggs break;
261 1.3 briggs case NUBUS_DRSW_DAYNA:
262 1.3 briggs vendor = AE_VENDOR_DAYNA;
263 1.1 briggs break;
264 1.1 briggs default:
265 1.1 briggs #ifdef DIAGNOSTIC
266 1.1 briggs printf("Unknown ethernet drsw: %x\n", na->drsw);
267 1.1 briggs #endif
268 1.1 briggs vendor = AE_VENDOR_UNKNOWN;
269 1.1 briggs }
270 1.1 briggs return vendor;
271 1.1 briggs }
272 1.4 briggs
273 1.4 briggs static int
274 1.4 briggs sn_nb_get_enaddr(na, ep, rsrc1)
275 1.4 briggs struct nubus_attach_args *na;
276 1.4 briggs u_int8_t *ep;
277 1.4 briggs int rsrc1;
278 1.4 briggs {
279 1.4 briggs nubus_dir dir;
280 1.4 briggs nubus_dirent dirent;
281 1.4 briggs
282 1.4 briggs nubus_get_main_dir(na->fmt, &dir);
283 1.4 briggs if (nubus_find_rsrc(na->fmt, &dir, na->rsrcid, &dirent) <= 0)
284 1.4 briggs return 1;
285 1.4 briggs nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
286 1.4 briggs if (nubus_find_rsrc(na->fmt, &dir, rsrc1, &dirent) <= 0)
287 1.4 briggs return 1;
288 1.4 briggs if (nubus_get_ind_data(na->fmt, &dirent, ep, ETHER_ADDR_LEN) <= 0)
289 1.4 briggs return 1;
290 1.4 briggs
291 1.4 briggs return 0;
292 1.4 briggs }
293 1.4 briggs
294