if_gem_sbus.c revision 1.6 1 1.6 martin /* $NetBSD: if_gem_sbus.c,v 1.6 2008/04/28 20:23:57 martin Exp $ */
2 1.1 martin
3 1.1 martin /*-
4 1.1 martin * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.1 martin * All rights reserved.
6 1.1 martin *
7 1.1 martin * This code is derived from software contributed to The NetBSD Foundation
8 1.1 martin * by Martin Husemann.
9 1.1 martin *
10 1.1 martin * Redistribution and use in source and binary forms, with or without
11 1.1 martin * modification, are permitted provided that the following conditions
12 1.1 martin * are met:
13 1.1 martin * 1. Redistributions of source code must retain the above copyright
14 1.1 martin * notice, this list of conditions and the following disclaimer.
15 1.1 martin * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 martin * notice, this list of conditions and the following disclaimer in the
17 1.1 martin * documentation and/or other materials provided with the distribution.
18 1.1 martin *
19 1.1 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 martin * POSSIBILITY OF SUCH DAMAGE.
30 1.1 martin */
31 1.1 martin
32 1.1 martin /*
33 1.1 martin * SBus front-end for the GEM network driver
34 1.1 martin */
35 1.1 martin
36 1.1 martin #include <sys/cdefs.h>
37 1.6 martin __KERNEL_RCSID(0, "$NetBSD: if_gem_sbus.c,v 1.6 2008/04/28 20:23:57 martin Exp $");
38 1.1 martin
39 1.1 martin #include <sys/param.h>
40 1.1 martin #include <sys/systm.h>
41 1.1 martin #include <sys/syslog.h>
42 1.1 martin #include <sys/device.h>
43 1.1 martin #include <sys/malloc.h>
44 1.1 martin #include <sys/socket.h>
45 1.1 martin
46 1.1 martin #include <net/if.h>
47 1.1 martin #include <net/if_dl.h>
48 1.1 martin #include <net/if_ether.h>
49 1.1 martin #include <net/if_media.h>
50 1.1 martin
51 1.1 martin #include <dev/mii/mii.h>
52 1.1 martin #include <dev/mii/miivar.h>
53 1.1 martin
54 1.2 ad #include <sys/bus.h>
55 1.2 ad #include <sys/intr.h>
56 1.1 martin #include <machine/autoconf.h>
57 1.1 martin
58 1.1 martin #include <dev/sbus/sbusvar.h>
59 1.1 martin
60 1.1 martin #include <dev/ic/gemreg.h>
61 1.1 martin #include <dev/ic/gemvar.h>
62 1.1 martin
63 1.1 martin struct gem_sbus_softc {
64 1.1 martin struct gem_softc gsc_gem; /* GEM device */
65 1.1 martin struct sbusdev gsc_sd;
66 1.1 martin void *gsc_ih;
67 1.1 martin bus_space_handle_t gsc_sbus_regs_h;
68 1.1 martin };
69 1.1 martin
70 1.1 martin int gemmatch_sbus(struct device *, struct cfdata *, void *);
71 1.1 martin void gemattach_sbus(struct device *, struct device *, void *);
72 1.1 martin
73 1.1 martin CFATTACH_DECL(gem_sbus, sizeof(struct gem_sbus_softc),
74 1.1 martin gemmatch_sbus, gemattach_sbus, NULL, NULL);
75 1.1 martin
76 1.1 martin int
77 1.1 martin gemmatch_sbus(struct device *parent, struct cfdata *cf, void *aux)
78 1.1 martin {
79 1.1 martin struct sbus_attach_args *sa = aux;
80 1.1 martin
81 1.1 martin return (strcmp("network", sa->sa_name) == 0);
82 1.1 martin }
83 1.1 martin
84 1.1 martin void
85 1.1 martin gemattach_sbus(struct device *parent, struct device *self, void *aux)
86 1.1 martin {
87 1.1 martin struct sbus_attach_args *sa = aux;
88 1.1 martin struct gem_sbus_softc *gsc = (void *)self;
89 1.1 martin struct gem_softc *sc = &gsc->gsc_gem;
90 1.1 martin uint8_t enaddr[ETHER_ADDR_LEN];
91 1.1 martin
92 1.1 martin /* Pass on the bus tags */
93 1.1 martin sc->sc_bustag = sa->sa_bustag;
94 1.1 martin sc->sc_dmatag = sa->sa_dmatag;
95 1.1 martin
96 1.5 jdc sc->sc_chiprev = prom_getpropint(sa->sa_node, "gem-rev", 0);
97 1.5 jdc
98 1.5 jdc printf(": GEM Ethernet controller (%s), version %s (rev 0x%02x)\n",
99 1.5 jdc sa->sa_name, prom_getpropstring(sa->sa_node, "version"),
100 1.5 jdc sc->sc_chiprev);
101 1.1 martin
102 1.1 martin if (sa->sa_nreg < 2) {
103 1.1 martin printf("%s: only %d register sets\n",
104 1.4 cegger device_xname(self), sa->sa_nreg);
105 1.1 martin return;
106 1.1 martin }
107 1.1 martin
108 1.1 martin /*
109 1.1 martin * Map two register banks:
110 1.1 martin *
111 1.1 martin * bank 0: status, config, reset
112 1.1 martin * bank 1: various gem parts
113 1.1 martin *
114 1.1 martin */
115 1.1 martin if (sbus_bus_map(sa->sa_bustag,
116 1.1 martin sa->sa_reg[0].oa_space,
117 1.1 martin sa->sa_reg[0].oa_base,
118 1.1 martin (bus_size_t)sa->sa_reg[0].oa_size,
119 1.1 martin 0, &sc->sc_h2) != 0) {
120 1.4 cegger aprint_error_dev(self, "cannot map registers\n");
121 1.1 martin return;
122 1.1 martin }
123 1.1 martin if (sbus_bus_map(sa->sa_bustag,
124 1.1 martin sa->sa_reg[1].oa_space,
125 1.1 martin sa->sa_reg[1].oa_base,
126 1.1 martin (bus_size_t)sa->sa_reg[1].oa_size,
127 1.1 martin 0, &sc->sc_h1) != 0) {
128 1.4 cegger aprint_error_dev(self, "cannot map registers\n");
129 1.1 martin return;
130 1.1 martin }
131 1.1 martin sbus_establish(&gsc->gsc_sd, self);
132 1.1 martin prom_getether(sa->sa_node, enaddr);
133 1.1 martin
134 1.3 jdc if (!strcmp("serdes", prom_getpropstring(sa->sa_node, "shared-pins")))
135 1.3 jdc sc->sc_flags |= GEM_SERDES;
136 1.5 jdc sc->sc_variant = GEM_SUN_GEM;
137 1.3 jdc
138 1.1 martin /*
139 1.1 martin * SBUS config
140 1.1 martin */
141 1.1 martin bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG,
142 1.1 martin GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64);
143 1.1 martin
144 1.1 martin gem_attach(sc, enaddr);
145 1.1 martin
146 1.1 martin /* Establish interrupt handler */
147 1.1 martin if (sa->sa_nintr != 0)
148 1.1 martin gsc->gsc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
149 1.1 martin gem_intr, sc);
150 1.1 martin }
151