1 /* $NetBSD: if_sn_obio.c,v 1.27 2007/10/17 19:55:16 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_obio.c,v 1.27 2007/10/17 19:55:16 garbled Exp $");
36 #include <sys/param.h>
37 #include <sys/device.h>
38 #include <sys/systm.h>
39 #include <sys/ioctl.h>
42 #include <net/if_ether.h>
44 #include <machine/bus.h>
45 #include <machine/cpu.h>
46 #include <machine/viareg.h>
48 #include <dev/ic/dp83932reg.h>
49 #include <dev/ic/dp83932var.h>
51 #include <mac68k/obio/obiovar.h>
52 #include <mac68k/dev/if_snvar.h>
54 #define SONIC_REG_BASE 0x50F0A000
55 #define SONIC_PROM_BASE 0x50F08000
56 #define SONIC_SLOTNO 9
58 static int sn_obio_match(device_t
, cfdata_t
, void *);
59 static void sn_obio_attach(device_t
, device_t
, void *);
60 static int sn_obio_getaddr(struct sonic_softc
*, uint8_t *);
61 static int sn_obio_getaddr_kludge(struct sonic_softc
*, uint8_t *);
63 CFATTACH_DECL_NEW(sn_obio
, sizeof(struct sonic_softc
),
64 sn_obio_match
, sn_obio_attach
, NULL
, NULL
);
67 sn_obio_match(device_t parent
, cfdata_t cf
, void *aux
)
69 struct obio_attach_args
*oa
= aux
;
70 bus_space_handle_t bsh
;
73 if (!mac68k_machine
.sonic
)
76 if (bus_space_map(oa
->oa_tag
,
77 SONIC_REG_BASE
, SONIC_NREGS
* 4, 0, &bsh
))
80 if (mac68k_bus_space_probe(oa
->oa_tag
, bsh
, 0, 4))
83 bus_space_unmap(oa
->oa_tag
, bsh
, SONIC_NREGS
* 4);
89 * Install interface into kernel networking data structures
92 sn_obio_attach(device_t parent
, device_t self
, void *aux
)
94 struct sonic_softc
*sc
= device_private(self
);
95 struct obio_attach_args
*oa
= aux
;
96 uint8_t myaddr
[ETHER_ADDR_LEN
];
100 sc
->sc_st
= oa
->oa_tag
;
101 sc
->sc_dmat
= oa
->oa_dmat
;
103 if (bus_space_map(sc
->sc_st
,
104 SONIC_REG_BASE
, SONIC_NREGS
* 4, 0, &sc
->sc_sh
)) {
105 aprint_error(": failed to map space for SONIC regs.\n");
109 /* regs are addressed as words, big-endian. */
110 for (i
= 0; i
< SONIC_NREGS
; i
++) {
111 sc
->sc_regmap
[i
] = (bus_size_t
)((i
* 4) + 2);
114 sc
->sc_bigendian
= 1;
116 sc
->sc_dcr
= DCR_BMS
| DCR_RFT1
| DCR_TFT0
;
119 switch (current_mac_model
->machineid
) {
128 sc
->sc_dcr
|= DCR_EXBUS
;
135 /* Apple Comm Slot cards; assume they are 32 bit */
136 sc
->sc_dcr
|= DCR_EXBUS
| DCR_USR1
| DCR_USR0
;
141 sc
->sc_dcr
|= DCR_SBUS
| DCR_LBR
;
142 sc
->sc_32bit
= 0; /* 16 bit interface */
146 aprint_error(": unsupported machine type\n");
150 if (sn_obio_getaddr(sc
, myaddr
) &&
151 sn_obio_getaddr_kludge(sc
, myaddr
)) { /* XXX kludge for PB */
152 aprint_error(": failed to get MAC address.\n");
153 bus_space_unmap(sc
->sc_st
, sc
->sc_sh
, SONIC_NREGS
* 4);
157 aprint_normal(": integrated SONIC Ethernet adapter\n");
159 if (mac68k_machine
.aux_interrupts
) {
160 intr_establish(sonic_intr
, (void *)sc
, 3);
162 add_nubus_intr(SONIC_SLOTNO
, (void (*)(void *))sonic_intr
,
166 sonic_attach(sc
, myaddr
);
170 sn_obio_getaddr(struct sonic_softc
*sc
, uint8_t *lladdr
)
172 bus_space_handle_t bsh
;
174 if (bus_space_map(sc
->sc_st
, SONIC_PROM_BASE
, PAGE_SIZE
, 0, &bsh
)) {
175 aprint_error(": failed to map space to read SONIC address.\n");
176 aprint_normal("%s:", device_xname(sc
->sc_dev
));
180 if (!mac68k_bus_space_probe(sc
->sc_st
, bsh
, 0, 1)) {
181 bus_space_unmap(sc
->sc_st
, bsh
, PAGE_SIZE
);
185 sn_get_enaddr(sc
->sc_st
, bsh
, 0, lladdr
);
187 bus_space_unmap(sc
->sc_st
, bsh
, PAGE_SIZE
);
193 * Assume that the SONIC was initialized in MacOS. This should go away
194 * when we can properly get the MAC address on the PBs.
197 sn_obio_getaddr_kludge(struct sonic_softc
*sc
, u_int8_t
*lladdr
)
202 CSR_WRITE(sc
, SONIC_CR
, CR_RST
);
204 /* For some reason, Apple fills top first. */
205 CSR_WRITE(sc
, SONIC_CEP
, 15);
207 i
= CSR_READ(sc
, SONIC_CAP2
);
213 i
= CSR_READ(sc
, SONIC_CAP1
);
219 i
= CSR_READ(sc
, SONIC_CAP0
);
225 CSR_WRITE(sc
, SONIC_CR
, 0);