1 /* $OpenBSD: if_hme_sbus.c,v 1.12 2008/06/26 05:42:18 ray 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 * 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 device driver for the HME ethernet device. 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 #include <dev/ic/hmevar.h> 65 #include <dev/ofw/openfirm.h> 66 67 struct hmesbus_softc { 68 struct hme_softc hsc_hme; /* HME device */ 69 }; 70 71 int hmematch_sbus(struct device *, void *, void *); 72 void hmeattach_sbus(struct device *, struct device *, void *); 73 74 struct cfattach hme_sbus_ca = { 75 sizeof(struct hmesbus_softc), hmematch_sbus, hmeattach_sbus 76 }; 77 78 int 79 hmematch_sbus(struct device *parent, void *vcf, void *aux) 80 { 81 struct cfdata *cf = vcf; 82 struct sbus_attach_args *sa = aux; 83 84 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 || 85 strcmp("SUNW,qfe", sa->sa_name) == 0 || 86 strcmp("SUNW,hme", sa->sa_name) == 0); 87 } 88 89 void 90 hmeattach_sbus(struct device *parent, struct device *self, void *aux) 91 { 92 struct sbus_attach_args *sa = aux; 93 struct hmesbus_softc *hsc = (void *)self; 94 struct hme_softc *sc = &hsc->hsc_hme; 95 u_int32_t burst, sbusburst; 96 int node; 97 /* XXX the following declarations should be elsewhere */ 98 extern void myetheraddr(u_char *); 99 100 node = sa->sa_node; 101 102 /* Pass on the bus tags */ 103 sc->sc_bustag = sa->sa_bustag; 104 sc->sc_dmatag = sa->sa_dmatag; 105 106 if (sa->sa_nreg < 5) { 107 printf("%s: only %d register sets\n", 108 self->dv_xname, sa->sa_nreg); 109 return; 110 } 111 112 /* 113 * Map five register banks: 114 * 115 * bank 0: HME SEB registers 116 * bank 1: HME ETX registers 117 * bank 2: HME ERX registers 118 * bank 3: HME MAC registers 119 * bank 4: HME MIF registers 120 * 121 */ 122 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 123 (bus_addr_t)sa->sa_reg[0].sbr_offset, 124 (bus_size_t)sa->sa_reg[0].sbr_size, 0, 0, &sc->sc_seb) != 0) { 125 printf("%s @ sbus: cannot map registers\n", self->dv_xname); 126 return; 127 } 128 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[1].sbr_slot, 129 (bus_addr_t)sa->sa_reg[1].sbr_offset, 130 (bus_size_t)sa->sa_reg[1].sbr_size, 0, 0, &sc->sc_etx) != 0) { 131 printf("%s @ sbus: cannot map registers\n", self->dv_xname); 132 return; 133 } 134 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[2].sbr_slot, 135 (bus_addr_t)sa->sa_reg[2].sbr_offset, 136 (bus_size_t)sa->sa_reg[2].sbr_size, 0, 0, &sc->sc_erx) != 0) { 137 printf("%s @ sbus: cannot map registers\n", self->dv_xname); 138 return; 139 } 140 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[3].sbr_slot, 141 (bus_addr_t)sa->sa_reg[3].sbr_offset, 142 (bus_size_t)sa->sa_reg[3].sbr_size, 0, 0, &sc->sc_mac) != 0) { 143 printf("%s @ sbus: cannot map registers\n", self->dv_xname); 144 return; 145 } 146 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[4].sbr_slot, 147 (bus_addr_t)sa->sa_reg[4].sbr_offset, 148 (bus_size_t)sa->sa_reg[4].sbr_size, 0, 0, &sc->sc_mif) != 0) { 149 printf("%s @ sbus: cannot map registers\n", self->dv_xname); 150 return; 151 } 152 153 if (OF_getprop(sa->sa_node, "local-mac-address", 154 sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN) <= 0) 155 myetheraddr(sc->sc_arpcom.ac_enaddr); 156 157 /* 158 * Get transfer burst size from PROM and pass it on 159 * to the back-end driver. 160 */ 161 sbusburst = ((struct sbus_softc *)parent)->sc_burst; 162 if (sbusburst == 0) 163 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */ 164 165 burst = getpropint(node, "burst-sizes", -1); 166 if (burst == -1) 167 /* take SBus burst sizes */ 168 burst = sbusburst; 169 170 /* Clamp at parent's burst sizes */ 171 burst &= sbusburst; 172 173 /* Translate into plain numerical format */ 174 if ((burst & SBUS_BURST_64)) 175 sc->sc_burst = 64; 176 else if ((burst & SBUS_BURST_32)) 177 sc->sc_burst = 32; 178 else if ((burst & SBUS_BURST_16)) 179 sc->sc_burst = 16; 180 else 181 sc->sc_burst = 0; 182 183 sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */ 184 185 /* Establish interrupt handler */ 186 if (sa->sa_nintr != 0) 187 (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, 188 hme_intr, sc, self->dv_xname); 189 190 hme_config(sc); 191 } 192