1 /* $NetBSD: if_hme_sbus.c,v 1.32 2009/09/08 18:15:17 tsutsui Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * SBus front-end device driver for the HME ethernet device.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.32 2009/09/08 18:15:17 tsutsui Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/syslog.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44 #include <sys/socket.h>
47 #include <net/if_dl.h>
48 #include <net/if_ether.h>
49 #include <net/if_media.h>
51 #include <dev/mii/mii.h>
52 #include <dev/mii/miivar.h>
56 #include <machine/autoconf.h>
58 #include <dev/sbus/sbusvar.h>
59 #include <dev/ic/hmevar.h>
61 struct hmesbus_softc
{
62 struct hme_softc hsc_hme
; /* HME device */
63 /* sbus specific stuff here */
66 int hmematch_sbus(device_t
, cfdata_t
, void *);
67 void hmeattach_sbus(device_t
, device_t
, void *);
69 CFATTACH_DECL_NEW(hme_sbus
, sizeof(struct hmesbus_softc
),
70 hmematch_sbus
, hmeattach_sbus
, NULL
, NULL
);
73 hmematch_sbus(device_t parent
, cfdata_t cf
, void *aux
)
75 struct sbus_attach_args
*sa
= aux
;
77 return (strcmp(cf
->cf_name
, sa
->sa_name
) == 0 ||
78 strcmp("SUNW,qfe", sa
->sa_name
) == 0 ||
79 strcmp("SUNW,hme", sa
->sa_name
) == 0);
83 hmeattach_sbus(device_t parent
, device_t self
, void *aux
)
85 struct sbus_attach_args
*sa
= aux
;
86 struct hmesbus_softc
*hsc
= device_private(self
);
87 struct hme_softc
*sc
= &hsc
->hsc_hme
;
88 struct sbus_softc
*sbsc
= device_private(parent
);
89 uint32_t burst
, sbusburst
;
95 /* Pass on the bus tags */
96 sc
->sc_bustag
= sa
->sa_bustag
;
97 sc
->sc_dmatag
= sa
->sa_dmatag
;
99 aprint_normal(": Sun Happy Meal Ethernet (%s)\n",
102 if (sa
->sa_nreg
< 5) {
103 aprint_error_dev(self
, "only %d register sets\n",
109 * Map five register banks:
111 * bank 0: HME SEB registers
112 * bank 1: HME ETX registers
113 * bank 2: HME ERX registers
114 * bank 3: HME MAC registers
115 * bank 4: HME MIF registers
118 if (sbus_bus_map(sa
->sa_bustag
,
119 sa
->sa_reg
[0].oa_space
,
120 sa
->sa_reg
[0].oa_base
,
121 (bus_size_t
)sa
->sa_reg
[0].oa_size
,
122 0, &sc
->sc_seb
) != 0) {
123 aprint_error_dev(self
, "cannot map SEB registers\n");
126 if (sbus_bus_map(sa
->sa_bustag
,
127 sa
->sa_reg
[1].oa_space
,
128 sa
->sa_reg
[1].oa_base
,
129 (bus_size_t
)sa
->sa_reg
[1].oa_size
,
130 0, &sc
->sc_etx
) != 0) {
131 aprint_error_dev(self
, "cannot map ETX registers\n");
134 if (sbus_bus_map(sa
->sa_bustag
,
135 sa
->sa_reg
[2].oa_space
,
136 sa
->sa_reg
[2].oa_base
,
137 (bus_size_t
)sa
->sa_reg
[2].oa_size
,
138 0, &sc
->sc_erx
) != 0) {
139 aprint_error_dev(self
, "cannot map ERX registers\n");
142 if (sbus_bus_map(sa
->sa_bustag
,
143 sa
->sa_reg
[3].oa_space
,
144 sa
->sa_reg
[3].oa_base
,
145 (bus_size_t
)sa
->sa_reg
[3].oa_size
,
146 0, &sc
->sc_mac
) != 0) {
147 aprint_error_dev(self
, "cannot map MAC registers\n");
150 if (sbus_bus_map(sa
->sa_bustag
,
151 sa
->sa_reg
[4].oa_space
,
152 sa
->sa_reg
[4].oa_base
,
153 (bus_size_t
)sa
->sa_reg
[4].oa_size
,
154 0, &sc
->sc_mif
) != 0) {
155 aprint_error_dev(self
, "cannot map MIF registers\n");
159 prom_getether(node
, sc
->sc_enaddr
);
162 * Get transfer burst size from PROM and pass it on
163 * to the back-end driver.
165 sbusburst
= sbsc
->sc_burst
;
167 sbusburst
= SBUS_BURST_32
- 1; /* 1->16 */
169 burst
= prom_getpropint(node
, "burst-sizes", -1);
171 /* take SBus burst sizes */
174 /* Clamp at parent's burst sizes */
177 /* Translate into plain numerical format */
178 sc
->sc_burst
= (burst
& SBUS_BURST_32
) ? 32 :
179 (burst
& SBUS_BURST_16
) ? 16 : 0;
181 sc
->sc_pci
= 0; /* XXXXX should all be done in bus_dma. */
184 /* Establish interrupt handler */
185 if (sa
->sa_nintr
!= 0)
186 (void)bus_intr_establish(sa
->sa_bustag
, sa
->sa_pri
, IPL_NET
,