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