if_sn_nubus.c revision 1.1 1 1.1 briggs /* $NetBSD: if_sn_nubus.c,v 1.1 1997/03/15 20:26:37 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.1 briggs
43 1.1 briggs #ifdef INET
44 1.1 briggs #include <netinet/in.h>
45 1.1 briggs #include <netinet/if_ether.h>
46 1.1 briggs #endif
47 1.1 briggs
48 1.1 briggs #include <machine/bus.h>
49 1.1 briggs #include <machine/viareg.h>
50 1.1 briggs
51 1.1 briggs #include "nubus.h"
52 1.1 briggs #include "if_aereg.h" /* For AE_VENDOR values */
53 1.1 briggs #include "if_snreg.h"
54 1.1 briggs #include "if_snvar.h"
55 1.1 briggs
56 1.1 briggs static int sn_nubus_match __P((struct device *, struct cfdata *, void *));
57 1.1 briggs static void sn_nubus_attach __P((struct device *, struct device *, void *));
58 1.1 briggs static int sn_nb_card_vendor __P((struct nubus_attach_args *));
59 1.1 briggs
60 1.1 briggs void snsetup __P((struct sn_softc *));
61 1.1 briggs
62 1.1 briggs struct cfattach sn_nubus_ca = {
63 1.1 briggs sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
64 1.1 briggs };
65 1.1 briggs
66 1.1 briggs static int
67 1.1 briggs sn_nubus_match(parent, cf, aux)
68 1.1 briggs struct device *parent;
69 1.1 briggs struct cfdata *cf;
70 1.1 briggs void *aux;
71 1.1 briggs {
72 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
73 1.1 briggs bus_space_handle_t bsh;
74 1.1 briggs int rv;
75 1.1 briggs
76 1.1 briggs if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
77 1.1 briggs 0, &bsh))
78 1.1 briggs return (0);
79 1.1 briggs
80 1.1 briggs rv = 0;
81 1.1 briggs
82 1.1 briggs if (na->category == NUBUS_CATEGORY_NETWORK &&
83 1.1 briggs na->type == NUBUS_TYPE_ETHERNET) {
84 1.1 briggs switch (sn_nb_card_vendor(na)) {
85 1.1 briggs default:
86 1.1 briggs break;
87 1.1 briggs
88 1.1 briggs /* This is it for now... */
89 1.1 briggs case AE_VENDOR_DAYNA:
90 1.1 briggs rv = 1;
91 1.1 briggs break;
92 1.1 briggs }
93 1.1 briggs }
94 1.1 briggs
95 1.1 briggs bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
96 1.1 briggs
97 1.1 briggs return rv;
98 1.1 briggs }
99 1.1 briggs
100 1.1 briggs /*
101 1.1 briggs * Install interface into kernel networking data structures
102 1.1 briggs */
103 1.1 briggs static void
104 1.1 briggs sn_nubus_attach(parent, self, aux)
105 1.1 briggs struct device *parent, *self;
106 1.1 briggs void *aux;
107 1.1 briggs {
108 1.1 briggs struct sn_softc *sc = (void *)self;
109 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
110 1.1 briggs int i, success;
111 1.1 briggs bus_space_tag_t bst;
112 1.1 briggs bus_space_handle_t bsh, tmp_bsh;
113 1.1 briggs
114 1.1 briggs bst = na->na_tag;
115 1.1 briggs if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
116 1.1 briggs printf(": failed to map memory space.\n");
117 1.1 briggs return;
118 1.1 briggs }
119 1.1 briggs
120 1.1 briggs sc->sc_regt = bst;
121 1.1 briggs sc->bitmode = 1;
122 1.1 briggs
123 1.1 briggs success = 0;
124 1.1 briggs
125 1.1 briggs sc->bitmode = 1; /* 32-bit card */
126 1.1 briggs sc->slotno = na->slot;
127 1.1 briggs
128 1.1 briggs switch (sn_nb_card_vendor(na)) {
129 1.1 briggs case AE_VENDOR_DAYNA:
130 1.1 briggs sc->s_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_USR1 |
131 1.1 briggs DCR_DW32 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
132 1.1 briggs
133 1.1 briggs if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
134 1.1 briggs &sc->sc_regh)) {
135 1.1 briggs printf(": failed to map register space.\n");
136 1.1 briggs break;
137 1.1 briggs }
138 1.1 briggs
139 1.1 briggs if (bus_space_subregion(bst, bsh, 0x00ffe004, ETHER_ADDR_LEN,
140 1.1 briggs &tmp_bsh)) {
141 1.1 briggs printf(": failed to map ROM space.\n");
142 1.1 briggs break;
143 1.1 briggs }
144 1.1 briggs
145 1.1 briggs /*
146 1.1 briggs * Copy out the ethernet address from the card's ROM
147 1.1 briggs */
148 1.1 briggs for (i = 0; i < ETHER_ADDR_LEN; ++i)
149 1.1 briggs sc->sc_arpcom.ac_enaddr[i] =
150 1.1 briggs bus_space_read_1(bst, tmp_bsh, i);
151 1.1 briggs
152 1.1 briggs success = 1;
153 1.1 briggs break;
154 1.1 briggs
155 1.1 briggs default:
156 1.1 briggs /*
157 1.1 briggs * You can't actually get this default, the snmatch
158 1.1 briggs * will fail for unknown hardware. If you're adding support
159 1.1 briggs * for a new card, the following defaults are a
160 1.1 briggs * good starting point.
161 1.1 briggs */
162 1.1 briggs sc->s_dcr = DCR_LBR | DCR_SYNC | DCR_WAIT0 |
163 1.1 briggs DCR_DW32 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
164 1.1 briggs return;
165 1.1 briggs }
166 1.1 briggs
167 1.1 briggs if (!success) {
168 1.1 briggs bus_space_unmap(bst, bsh, NBMEMSIZE);
169 1.1 briggs return;
170 1.1 briggs }
171 1.1 briggs
172 1.1 briggs snsetup(sc);
173 1.1 briggs }
174 1.1 briggs
175 1.1 briggs static int
176 1.1 briggs sn_nb_card_vendor(na)
177 1.1 briggs struct nubus_attach_args *na;
178 1.1 briggs {
179 1.1 briggs int vendor;
180 1.1 briggs
181 1.1 briggs switch (na->drsw) {
182 1.1 briggs case NUBUS_DRSW_3COM:
183 1.1 briggs case NUBUS_DRSW_APPLE:
184 1.1 briggs case NUBUS_DRSW_TECHWORKS:
185 1.1 briggs vendor = AE_VENDOR_APPLE;
186 1.1 briggs break;
187 1.1 briggs case NUBUS_DRSW_ASANTE:
188 1.1 briggs vendor = AE_VENDOR_ASANTE;
189 1.1 briggs break;
190 1.1 briggs case NUBUS_DRSW_FARALLON:
191 1.1 briggs vendor = AE_VENDOR_FARALLON;
192 1.1 briggs break;
193 1.1 briggs case NUBUS_DRSW_FOCUS:
194 1.1 briggs vendor = AE_VENDOR_FOCUS;
195 1.1 briggs break;
196 1.1 briggs case NUBUS_DRSW_GATOR:
197 1.1 briggs switch (na->drhw) {
198 1.1 briggs default:
199 1.1 briggs case NUBUS_DRHW_INTERLAN:
200 1.1 briggs vendor = AE_VENDOR_INTERLAN;
201 1.1 briggs break;
202 1.1 briggs case NUBUS_DRHW_KINETICS:
203 1.1 briggs if (strncmp(
204 1.1 briggs nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
205 1.1 briggs vendor = AE_VENDOR_KINETICS;
206 1.1 briggs else
207 1.1 briggs vendor = AE_VENDOR_DAYNA;
208 1.1 briggs break;
209 1.1 briggs }
210 1.1 briggs break;
211 1.1 briggs default:
212 1.1 briggs #ifdef DIAGNOSTIC
213 1.1 briggs printf("Unknown ethernet drsw: %x\n", na->drsw);
214 1.1 briggs #endif
215 1.1 briggs vendor = AE_VENDOR_UNKNOWN;
216 1.1 briggs }
217 1.1 briggs return vendor;
218 1.1 briggs }
219