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