1 /* $OpenBSD: if_gem_sbus.c,v 1.5 2008/11/07 17:44:14 brad Exp $ */ 2 /* $NetBSD: if_gem_sbus.c,v 1.1 2006/11/24 13:23:32 martin Exp $ */ 3 4 /*- 5 * Copyright (c) 2006 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Martin Husemann. 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 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * SBus front-end for the GEM network driver 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/syslog.h> 40 #include <sys/device.h> 41 #include <sys/malloc.h> 42 #include <sys/socket.h> 43 44 #include <net/if.h> 45 #include <net/if_dl.h> 46 #include <net/if_media.h> 47 48 #ifdef INET 49 #include <netinet/in.h> 50 #include <netinet/in_systm.h> 51 #include <netinet/in_var.h> 52 #include <netinet/ip.h> 53 #include <netinet/if_ether.h> 54 #endif 55 56 #include <dev/mii/mii.h> 57 #include <dev/mii/miivar.h> 58 59 #include <machine/bus.h> 60 #include <machine/intr.h> 61 #include <machine/autoconf.h> 62 63 #include <dev/sbus/sbusvar.h> 64 65 #include <dev/ic/gemreg.h> 66 #include <dev/ic/gemvar.h> 67 68 #include <dev/ofw/openfirm.h> 69 70 struct gem_sbus_softc { 71 struct gem_softc gsc_gem; /* GEM device */ 72 }; 73 74 int gemmatch_sbus(struct device *, void *, void *); 75 void gemattach_sbus(struct device *, struct device *, void *); 76 77 struct cfattach gem_sbus_ca = { 78 sizeof(struct gem_sbus_softc), gemmatch_sbus, gemattach_sbus 79 }; 80 81 int 82 gemmatch_sbus(struct device *parent, void *vcf, void *aux) 83 { 84 struct sbus_attach_args *sa = aux; 85 86 return (strcmp("network", sa->sa_name) == 0); 87 } 88 89 void 90 gemattach_sbus(struct device *parent, struct device *self, void *aux) 91 { 92 struct sbus_attach_args *sa = aux; 93 struct gem_sbus_softc *gsc = (void *)self; 94 struct gem_softc *sc = &gsc->gsc_gem; 95 /* XXX the following declarations should be elsewhere */ 96 extern void myetheraddr(u_char *); 97 98 /* Pass on the bus tags */ 99 sc->sc_bustag = sa->sa_bustag; 100 sc->sc_dmatag = sa->sa_dmatag; 101 102 if (sa->sa_nreg < 2) { 103 printf("%s: only %d register sets\n", 104 self->dv_xname, sa->sa_nreg); 105 return; 106 } 107 108 sc->sc_variant = GEM_SUN_GEM; 109 110 /* 111 * Map two register banks: 112 * 113 * bank 0: status, config, reset 114 * bank 1: various gem parts 115 * 116 */ 117 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 118 (bus_addr_t)sa->sa_reg[0].sbr_offset, 119 (bus_size_t)sa->sa_reg[0].sbr_size, 0, 0, 120 &sc->sc_h2) != 0) { 121 printf("%s: cannot map registers\n", self->dv_xname); 122 return; 123 } 124 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 125 (bus_addr_t)sa->sa_reg[1].sbr_offset, 126 (bus_size_t)sa->sa_reg[1].sbr_size, 0, 0, 127 &sc->sc_h1) != 0) { 128 printf("%s: cannot map registers\n", self->dv_xname); 129 return; 130 } 131 132 if (OF_getprop(sa->sa_node, "local-mac-address", 133 sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN) <= 0) 134 myetheraddr(sc->sc_arpcom.ac_enaddr); 135 136 /* 137 * SBUS config 138 */ 139 (void) bus_space_read_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_RESET); 140 delay(100); 141 bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG, 142 GEM_SBUS_CFG_BSIZE128|GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64); 143 144 /* Establish interrupt handler */ 145 if (sa->sa_nintr != 0) 146 (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, 147 gem_intr, sc, self->dv_xname); 148 149 gem_config(sc); 150 } 151