if_hme_sbus.c revision 1.8 1 /* $NetBSD: if_hme_sbus.c,v 1.8 2001/10/05 17:49:45 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * SBus front-end device driver for the HME ethernet device.
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/syslog.h>
46 #include <sys/device.h>
47 #include <sys/malloc.h>
48 #include <sys/socket.h>
49
50 #include <net/if.h>
51 #include <net/if_dl.h>
52 #include <net/if_ether.h>
53 #include <net/if_media.h>
54
55 #include <dev/mii/mii.h>
56 #include <dev/mii/miivar.h>
57
58 #include <machine/bus.h>
59 #include <machine/intr.h>
60 #include <machine/autoconf.h>
61
62 #include <dev/sbus/sbusvar.h>
63 #include <dev/ic/hmevar.h>
64
65 struct hmesbus_softc {
66 struct hme_softc hsc_hme; /* HME device */
67 struct sbusdev hsc_sbus; /* SBus device */
68 };
69
70 int hmematch_sbus __P((struct device *, struct cfdata *, void *));
71 void hmeattach_sbus __P((struct device *, struct device *, void *));
72
73 struct cfattach hme_sbus_ca = {
74 sizeof(struct hmesbus_softc), hmematch_sbus, hmeattach_sbus
75 };
76
77 int
78 hmematch_sbus(parent, cf, aux)
79 struct device *parent;
80 struct cfdata *cf;
81 void *aux;
82 {
83 struct sbus_attach_args *sa = aux;
84
85 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
86 strcmp("SUNW,qfe", sa->sa_name) == 0 ||
87 strcmp("SUNW,hme", sa->sa_name) == 0);
88 }
89
90 void
91 hmeattach_sbus(parent, self, aux)
92 struct device *parent, *self;
93 void *aux;
94 {
95 struct sbus_attach_args *sa = aux;
96 struct hmesbus_softc *hsc = (void *)self;
97 struct hme_softc *sc = &hsc->hsc_hme;
98 struct sbusdev *sd = &hsc->hsc_sbus;
99 u_int32_t burst, sbusburst;
100 int node;
101
102 /* XXX the following declarations should be elsewhere */
103 extern void myetheraddr __P((u_char *));
104
105 node = sa->sa_node;
106
107 /* Pass on the bus tags */
108 sc->sc_bustag = sa->sa_bustag;
109 sc->sc_dmatag = sa->sa_dmatag;
110
111 printf(": Sun Happy Meal Ethernet (%s)\n",
112 sa->sa_name);
113
114 if (sa->sa_nreg < 5) {
115 printf("%s: only %d register sets\n",
116 self->dv_xname, sa->sa_nreg);
117 return;
118 }
119
120 /*
121 * Map five register banks:
122 *
123 * bank 0: HME SEB registers
124 * bank 1: HME ETX registers
125 * bank 2: HME ERX registers
126 * bank 3: HME MAC registers
127 * bank 4: HME MIF registers
128 *
129 */
130 if (sbus_bus_map(sa->sa_bustag,
131 (bus_type_t)sa->sa_reg[0].sbr_slot,
132 (bus_addr_t)sa->sa_reg[0].sbr_offset,
133 (bus_size_t)sa->sa_reg[0].sbr_size,
134 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_seb) != 0) {
135 printf("%s: cannot map SEB registers\n", self->dv_xname);
136 return;
137 }
138 if (sbus_bus_map(sa->sa_bustag,
139 (bus_type_t)sa->sa_reg[1].sbr_slot,
140 (bus_addr_t)sa->sa_reg[1].sbr_offset,
141 (bus_size_t)sa->sa_reg[1].sbr_size,
142 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_etx) != 0) {
143 printf("%s: cannot map ETX registers\n", self->dv_xname);
144 return;
145 }
146 if (sbus_bus_map(sa->sa_bustag,
147 (bus_type_t)sa->sa_reg[2].sbr_slot,
148 (bus_addr_t)sa->sa_reg[2].sbr_offset,
149 (bus_size_t)sa->sa_reg[2].sbr_size,
150 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_erx) != 0) {
151 printf("%s: cannot map ERX registers\n", self->dv_xname);
152 return;
153 }
154 if (sbus_bus_map(sa->sa_bustag,
155 (bus_type_t)sa->sa_reg[3].sbr_slot,
156 (bus_addr_t)sa->sa_reg[3].sbr_offset,
157 (bus_size_t)sa->sa_reg[3].sbr_size,
158 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_mac) != 0) {
159 printf("%s: cannot map MAC registers\n", self->dv_xname);
160 return;
161 }
162 if (sbus_bus_map(sa->sa_bustag,
163 (bus_type_t)sa->sa_reg[4].sbr_slot,
164 (bus_addr_t)sa->sa_reg[4].sbr_offset,
165 (bus_size_t)sa->sa_reg[4].sbr_size,
166 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_mif) != 0) {
167 printf("%s: cannot map MIF registers\n", self->dv_xname);
168 return;
169 }
170
171 sd->sd_reset = (void *)hme_reset;
172 sbus_establish(sd, self);
173
174 myetheraddr(sc->sc_enaddr);
175
176 /*
177 * Get transfer burst size from PROM and pass it on
178 * to the back-end driver.
179 */
180 sbusburst = ((struct sbus_softc *)parent)->sc_burst;
181 if (sbusburst == 0)
182 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
183
184 burst = PROM_getpropint(node, "burst-sizes", -1);
185 if (burst == -1)
186 /* take SBus burst sizes */
187 burst = sbusburst;
188
189 /* Clamp at parent's burst sizes */
190 burst &= sbusburst;
191
192 /* Translate into plain numerical format */
193 sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
194 (burst & SBUS_BURST_16) ? 16 : 0;
195
196 sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
197 hme_config(sc);
198
199 /* Establish interrupt handler */
200 if (sa->sa_nintr != 0)
201 (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0,
202 hme_intr, sc);
203 }
204