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