xref: /netbsd-src/sys/dev/sbus/if_hme_sbus.c (revision fad4c9f71477ae11cea2ee75ec82151ac770a534)
1 /*	$NetBSD: if_hme_sbus.c,v 1.21 2005/12/11 12:23:44 christos 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/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.21 2005/12/11 12:23:44 christos Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/syslog.h>
49 #include <sys/device.h>
50 #include <sys/malloc.h>
51 #include <sys/socket.h>
52 
53 #include <net/if.h>
54 #include <net/if_dl.h>
55 #include <net/if_ether.h>
56 #include <net/if_media.h>
57 
58 #include <dev/mii/mii.h>
59 #include <dev/mii/miivar.h>
60 
61 #include <machine/bus.h>
62 #include <machine/intr.h>
63 #include <machine/autoconf.h>
64 
65 #include <dev/sbus/sbusvar.h>
66 #include <dev/ic/hmevar.h>
67 
68 struct hmesbus_softc {
69 	struct	hme_softc	hsc_hme;	/* HME device */
70 	struct	sbusdev		hsc_sbus;	/* SBus device */
71 };
72 
73 int	hmematch_sbus(struct device *, struct cfdata *, void *);
74 void	hmeattach_sbus(struct device *, struct device *, void *);
75 
76 CFATTACH_DECL(hme_sbus, sizeof(struct hmesbus_softc),
77     hmematch_sbus, hmeattach_sbus, NULL, NULL);
78 
79 int
80 hmematch_sbus(parent, cf, aux)
81 	struct device *parent;
82 	struct cfdata *cf;
83 	void *aux;
84 {
85 	struct sbus_attach_args *sa = aux;
86 
87 	return (strcmp(cf->cf_name, sa->sa_name) == 0 ||
88 	    strcmp("SUNW,qfe", sa->sa_name) == 0 ||
89 	    strcmp("SUNW,hme", sa->sa_name) == 0);
90 }
91 
92 void
93 hmeattach_sbus(parent, self, aux)
94 	struct device *parent, *self;
95 	void *aux;
96 {
97 	struct sbus_attach_args *sa = aux;
98 	struct hmesbus_softc *hsc = (void *)self;
99 	struct hme_softc *sc = &hsc->hsc_hme;
100 	struct sbusdev *sd = &hsc->hsc_sbus;
101 	u_int32_t burst, sbusburst;
102 	int node;
103 
104 	node = sa->sa_node;
105 
106 	/* Pass on the bus tags */
107 	sc->sc_bustag = sa->sa_bustag;
108 	sc->sc_dmatag = sa->sa_dmatag;
109 
110 	printf(": Sun Happy Meal Ethernet (%s)\n",
111 	    sa->sa_name);
112 
113 	if (sa->sa_nreg < 5) {
114 		printf("%s: only %d register sets\n",
115 			self->dv_xname, sa->sa_nreg);
116 		return;
117 	}
118 
119 	/*
120 	 * Map five register banks:
121 	 *
122 	 *	bank 0: HME SEB registers
123 	 *	bank 1: HME ETX registers
124 	 *	bank 2: HME ERX registers
125 	 *	bank 3: HME MAC registers
126 	 *	bank 4: HME MIF registers
127 	 *
128 	 */
129 	if (sbus_bus_map(sa->sa_bustag,
130 			 sa->sa_reg[0].oa_space,
131 			 sa->sa_reg[0].oa_base,
132 			 (bus_size_t)sa->sa_reg[0].oa_size,
133 			 0, &sc->sc_seb) != 0) {
134 		printf("%s: cannot map SEB registers\n", self->dv_xname);
135 		return;
136 	}
137 	if (sbus_bus_map(sa->sa_bustag,
138 			 sa->sa_reg[1].oa_space,
139 			 sa->sa_reg[1].oa_base,
140 			 (bus_size_t)sa->sa_reg[1].oa_size,
141 			 0, &sc->sc_etx) != 0) {
142 		printf("%s: cannot map ETX registers\n", self->dv_xname);
143 		return;
144 	}
145 	if (sbus_bus_map(sa->sa_bustag,
146 			 sa->sa_reg[2].oa_space,
147 			 sa->sa_reg[2].oa_base,
148 			 (bus_size_t)sa->sa_reg[2].oa_size,
149 			 0, &sc->sc_erx) != 0) {
150 		printf("%s: cannot map ERX registers\n", self->dv_xname);
151 		return;
152 	}
153 	if (sbus_bus_map(sa->sa_bustag,
154 			 sa->sa_reg[3].oa_space,
155 			 sa->sa_reg[3].oa_base,
156 			 (bus_size_t)sa->sa_reg[3].oa_size,
157 			 0, &sc->sc_mac) != 0) {
158 		printf("%s: cannot map MAC registers\n", self->dv_xname);
159 		return;
160 	}
161 	if (sbus_bus_map(sa->sa_bustag,
162 			 sa->sa_reg[4].oa_space,
163 			 sa->sa_reg[4].oa_base,
164 			 (bus_size_t)sa->sa_reg[4].oa_size,
165 			 0, &sc->sc_mif) != 0) {
166 		printf("%s: cannot map MIF registers\n", self->dv_xname);
167 		return;
168 	}
169 
170 	sd->sd_reset = (void *)hme_reset;
171 	sbus_establish(sd, self);
172 
173 	prom_getether(node, sc->sc_enaddr);
174 
175 	/*
176 	 * Get transfer burst size from PROM and pass it on
177 	 * to the back-end driver.
178 	 */
179 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
180 	if (sbusburst == 0)
181 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
182 
183 	burst = prom_getpropint(node, "burst-sizes", -1);
184 	if (burst == -1)
185 		/* take SBus burst sizes */
186 		burst = sbusburst;
187 
188 	/* Clamp at parent's burst sizes */
189 	burst &= sbusburst;
190 
191 	/* Translate into plain numerical format */
192 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
193 			(burst & SBUS_BURST_16) ? 16 : 0;
194 
195 	sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
196 	hme_config(sc);
197 
198 	/* Establish interrupt handler */
199 	if (sa->sa_nintr != 0)
200 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
201 					 hme_intr, sc);
202 }
203