1 /* $NetBSD: if_gem_sbus.c,v 1.2 2007/10/19 12:01:11 ad 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.2 2007/10/19 12:01:11 ad 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 printf(": GEM Ethernet controller (%s), version %s\n", 104 sa->sa_name, prom_getpropstring(sa->sa_node, "version")); 105 106 if (sa->sa_nreg < 2) { 107 printf("%s: only %d register sets\n", 108 self->dv_xname, sa->sa_nreg); 109 return; 110 } 111 112 /* 113 * Map two register banks: 114 * 115 * bank 0: status, config, reset 116 * bank 1: various gem parts 117 * 118 */ 119 if (sbus_bus_map(sa->sa_bustag, 120 sa->sa_reg[0].oa_space, 121 sa->sa_reg[0].oa_base, 122 (bus_size_t)sa->sa_reg[0].oa_size, 123 0, &sc->sc_h2) != 0) { 124 printf("%s: cannot map registers\n", self->dv_xname); 125 return; 126 } 127 if (sbus_bus_map(sa->sa_bustag, 128 sa->sa_reg[1].oa_space, 129 sa->sa_reg[1].oa_base, 130 (bus_size_t)sa->sa_reg[1].oa_size, 131 0, &sc->sc_h1) != 0) { 132 printf("%s: cannot map registers\n", self->dv_xname); 133 return; 134 } 135 sbus_establish(&gsc->gsc_sd, self); 136 prom_getether(sa->sa_node, enaddr); 137 138 /* 139 * SBUS config 140 */ 141 bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG, 142 GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64); 143 144 gem_attach(sc, enaddr); 145 146 /* Establish interrupt handler */ 147 if (sa->sa_nintr != 0) 148 gsc->gsc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 149 gem_intr, sc); 150 } 151