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