if_gem_sbus.c revision 1.5 1 /* $NetBSD: if_gem_sbus.c,v 1.5 2008/04/28 20:07:39 jdc Exp $ */
2
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann.
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 for the GEM network driver
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: if_gem_sbus.c,v 1.5 2008/04/28 20:07:39 jdc 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 <sys/bus.h>
62 #include <sys/intr.h>
63 #include <machine/autoconf.h>
64
65 #include <dev/sbus/sbusvar.h>
66
67 #include <dev/ic/gemreg.h>
68 #include <dev/ic/gemvar.h>
69
70 struct gem_sbus_softc {
71 struct gem_softc gsc_gem; /* GEM device */
72 struct sbusdev gsc_sd;
73 void *gsc_ih;
74 bus_space_handle_t gsc_sbus_regs_h;
75 };
76
77 int gemmatch_sbus(struct device *, struct cfdata *, void *);
78 void gemattach_sbus(struct device *, struct device *, void *);
79
80 CFATTACH_DECL(gem_sbus, sizeof(struct gem_sbus_softc),
81 gemmatch_sbus, gemattach_sbus, NULL, NULL);
82
83 int
84 gemmatch_sbus(struct device *parent, struct cfdata *cf, void *aux)
85 {
86 struct sbus_attach_args *sa = aux;
87
88 return (strcmp("network", sa->sa_name) == 0);
89 }
90
91 void
92 gemattach_sbus(struct device *parent, struct device *self, void *aux)
93 {
94 struct sbus_attach_args *sa = aux;
95 struct gem_sbus_softc *gsc = (void *)self;
96 struct gem_softc *sc = &gsc->gsc_gem;
97 uint8_t enaddr[ETHER_ADDR_LEN];
98
99 /* Pass on the bus tags */
100 sc->sc_bustag = sa->sa_bustag;
101 sc->sc_dmatag = sa->sa_dmatag;
102
103 sc->sc_chiprev = prom_getpropint(sa->sa_node, "gem-rev", 0);
104
105 printf(": GEM Ethernet controller (%s), version %s (rev 0x%02x)\n",
106 sa->sa_name, prom_getpropstring(sa->sa_node, "version"),
107 sc->sc_chiprev);
108
109 if (sa->sa_nreg < 2) {
110 printf("%s: only %d register sets\n",
111 device_xname(self), sa->sa_nreg);
112 return;
113 }
114
115 /*
116 * Map two register banks:
117 *
118 * bank 0: status, config, reset
119 * bank 1: various gem parts
120 *
121 */
122 if (sbus_bus_map(sa->sa_bustag,
123 sa->sa_reg[0].oa_space,
124 sa->sa_reg[0].oa_base,
125 (bus_size_t)sa->sa_reg[0].oa_size,
126 0, &sc->sc_h2) != 0) {
127 aprint_error_dev(self, "cannot map registers\n");
128 return;
129 }
130 if (sbus_bus_map(sa->sa_bustag,
131 sa->sa_reg[1].oa_space,
132 sa->sa_reg[1].oa_base,
133 (bus_size_t)sa->sa_reg[1].oa_size,
134 0, &sc->sc_h1) != 0) {
135 aprint_error_dev(self, "cannot map registers\n");
136 return;
137 }
138 sbus_establish(&gsc->gsc_sd, self);
139 prom_getether(sa->sa_node, enaddr);
140
141 if (!strcmp("serdes", prom_getpropstring(sa->sa_node, "shared-pins")))
142 sc->sc_flags |= GEM_SERDES;
143 sc->sc_variant = GEM_SUN_GEM;
144
145 /*
146 * SBUS config
147 */
148 bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG,
149 GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64);
150
151 gem_attach(sc, enaddr);
152
153 /* Establish interrupt handler */
154 if (sa->sa_nintr != 0)
155 gsc->gsc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
156 gem_intr, sc);
157 }
158