1 /* $NetBSD: if_sn_nubus.c,v 1.28 2007/10/17 19:55:15 garbled Exp $ */
4 * Copyright (C) 1997 Allen Briggs
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: if_sn_nubus.c,v 1.28 2007/10/17 19:55:15 garbled Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/ioctl.h>
42 #include <net/if_ether.h>
44 #include <machine/bus.h>
45 #include <machine/viareg.h>
47 #include <dev/ic/dp83932reg.h>
48 #include <dev/ic/dp83932var.h>
50 #include <mac68k/nubus/nubus.h>
51 #include <mac68k/dev/if_snvar.h>
53 static int sn_nubus_match(device_t
, cfdata_t
, void *);
54 static void sn_nubus_attach(device_t
, device_t
, void *);
55 static int sn_nb_card_vendor(bus_space_tag_t
, bus_space_handle_t
,
56 struct nubus_attach_args
*);
58 CFATTACH_DECL_NEW(sn_nubus
, sizeof(struct sonic_softc
),
59 sn_nubus_match
, sn_nubus_attach
, NULL
, NULL
);
63 sn_nubus_match(device_t parent
, cfdata_t cf
, void *aux
)
65 struct nubus_attach_args
*na
= aux
;
66 bus_space_handle_t bsh
;
69 if (bus_space_map(na
->na_tag
,
70 NUBUS_SLOT2PA(na
->slot
), NBMEMSIZE
, 0, &bsh
))
75 if (na
->category
== NUBUS_CATEGORY_NETWORK
&&
76 na
->type
== NUBUS_TYPE_ETHERNET
) {
77 switch (sn_nb_card_vendor(na
->na_tag
, bsh
, na
)) {
82 case SN_VENDOR_APPLE16
:
83 case SN_VENDOR_ASANTELC
:
90 bus_space_unmap(na
->na_tag
, bsh
, NBMEMSIZE
);
96 * Install interface into kernel networking data structures
99 sn_nubus_attach(device_t parent
, device_t self
, void *aux
)
101 struct sonic_softc
*sc
= device_private(self
);
102 struct nubus_attach_args
*na
= aux
;
103 int i
, success
, offset
;
105 bus_space_handle_t bsh
, tmp_bsh
;
106 uint8_t myaddr
[ETHER_ADDR_LEN
];
107 const char *cardtype
;
110 if (bus_space_map(bst
, NUBUS_SLOT2PA(na
->slot
), NBMEMSIZE
, 0, &bsh
)) {
111 aprint_error(": failed to map memory space.\n");
117 sc
->sc_dmat
= na
->na_dmat
;
119 cardtype
= nubus_get_card_name(bst
, bsh
, na
->fmt
);
124 switch (sn_nb_card_vendor(bst
, bsh
, na
)) {
125 case SN_VENDOR_DAYNA
:
126 sc
->sc_dcr
= DCR_BMS
| DCR_RFT1
| DCR_TFT0
;
128 sc
->sc_32bit
= 1; /* 32 bit card */
130 if (bus_space_subregion(bst
, bsh
,
131 0x00180000, SONIC_NREGS
* 4, &sc
->sc_sh
)) {
132 aprint_error(": failed to map register space.\n");
136 if (bus_space_subregion(bst
, bsh
,
137 0x00ffe004, ETHER_ADDR_LEN
, &tmp_bsh
)) {
138 aprint_error(": failed to map ROM space.\n");
142 sn_get_enaddr(bst
, tmp_bsh
, 0, myaddr
);
148 case SN_VENDOR_APPLE
:
149 sc
->sc_dcr
= DCR_BMS
| DCR_RFT1
| DCR_TFT0
;
151 sc
->sc_32bit
= 1; /* 32 bit card */
153 if (bus_space_subregion(bst
, bsh
,
154 0x0, SONIC_NREGS
* 4, &sc
->sc_sh
)) {
155 aprint_error(": failed to map register space.\n");
159 if (bus_space_subregion(bst
, bsh
,
160 0x40000, ETHER_ADDR_LEN
, &tmp_bsh
)) {
161 aprint_error(": failed to map ROM space.\n");
165 sn_get_enaddr(bst
, tmp_bsh
, 0, myaddr
);
171 case SN_VENDOR_APPLE16
:
172 sc
->sc_dcr
= DCR_EXBUS
| DCR_BMS
| DCR_PO1
|
175 sc
->sc_32bit
= 0; /* 16 bit card */
177 if (bus_space_subregion(bst
, bsh
,
178 0x0, SONIC_NREGS
* 4, &sc
->sc_sh
)) {
179 aprint_error(": failed to map register space.\n");
183 if (bus_space_subregion(bst
, bsh
,
184 0x40000, ETHER_ADDR_LEN
, &tmp_bsh
)) {
185 aprint_error(": failed to map ROM space.\n");
189 sn_get_enaddr(bst
, tmp_bsh
, 0, myaddr
);
195 case SN_VENDOR_ASANTELC
: /* Macintosh LC Ethernet Adapter */
196 sc
->sc_dcr
= DCR_BMS
| DCR_PO1
| DCR_RFT1
| DCR_TFT0
;
198 sc
->sc_32bit
= 0; /* 16 bit card */
200 if (bus_space_subregion(bst
, bsh
,
201 0x0, SONIC_NREGS
* 4, &sc
->sc_sh
)) {
202 aprint_error(": failed to map register space.\n");
206 if (bus_space_subregion(bst
, bsh
,
207 0x400000, ETHER_ADDR_LEN
, &tmp_bsh
)) {
208 aprint_error(": failed to map ROM space.\n");
212 sn_get_enaddr(bst
, tmp_bsh
, 0, myaddr
);
220 * You can't actually get this default, the snmatch
221 * will fail for unknown hardware. If you're adding support
222 * for a new card, the following defaults are a
223 * good starting point.
225 sc
->sc_dcr
= DCR_SBUS
| DCR_BMS
| DCR_RFT1
| DCR_TFT0
;
229 aprint_error(": unknown card: attachment incomplete.\n");
233 bus_space_unmap(bst
, bsh
, NBMEMSIZE
);
237 /* Regs are addressed as words, big endian. */
238 for (i
= 0; i
< SONIC_NREGS
; i
++) {
239 sc
->sc_regmap
[i
] = (bus_size_t
)((i
* 4) + offset
);
242 sc
->sc_bigendian
= 1;
244 aprint_error(": %s\n", cardtype
);
246 add_nubus_intr(na
->slot
, (void (*)(void *))sonic_intr
, (void *)sc
);
248 sonic_attach(sc
, myaddr
);
254 sn_nb_card_vendor(bus_space_tag_t bst
, bus_space_handle_t bsh
,
255 struct nubus_attach_args
*na
)
257 int vendor
= SN_VENDOR_UNKNOWN
;
260 case NUBUS_DRSW_3COM
:
261 if (na
->drhw
== NUBUS_DRHW_APPLE_SNT
)
262 vendor
= SN_VENDOR_APPLE
;
263 else if (na
->drhw
== NUBUS_DRHW_APPLE_SN
)
264 vendor
= SN_VENDOR_APPLE16
;
266 case NUBUS_DRSW_APPLE
:
267 if (na
->drhw
== NUBUS_DRHW_ASANTE_LC
)
268 vendor
= SN_VENDOR_ASANTELC
;
270 vendor
= SN_VENDOR_APPLE
;
272 case NUBUS_DRSW_TECHWORKS
:
273 vendor
= SN_VENDOR_APPLE
;
275 case NUBUS_DRSW_GATOR
:
276 if (na
->drhw
== NUBUS_DRHW_KINETICS
&&
277 strncmp(nubus_get_card_name(bst
, bsh
, na
->fmt
),
278 "EtherPort", 9) != 0)
279 vendor
= SN_VENDOR_DAYNA
;
281 case NUBUS_DRSW_DAYNA
:
282 vendor
= SN_VENDOR_DAYNA
;