1 1.30 thorpej /* $NetBSD: if_le_lebuffer.c,v 1.30 2022/09/25 18:03:04 thorpej Exp $ */ 2 1.1 pk 3 1.1 pk /*- 4 1.2 mycroft * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 1.1 pk * All rights reserved. 6 1.1 pk * 7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation 8 1.3 pk * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace 9 1.3 pk * Simulation Facility, NASA Ames Research Center; Paul Kranenburg. 10 1.1 pk * 11 1.1 pk * Redistribution and use in source and binary forms, with or without 12 1.1 pk * modification, are permitted provided that the following conditions 13 1.1 pk * are met: 14 1.1 pk * 1. Redistributions of source code must retain the above copyright 15 1.1 pk * notice, this list of conditions and the following disclaimer. 16 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 pk * notice, this list of conditions and the following disclaimer in the 18 1.1 pk * documentation and/or other materials provided with the distribution. 19 1.1 pk * 20 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.1 pk * POSSIBILITY OF SUCH DAMAGE. 31 1.1 pk */ 32 1.1 pk 33 1.9 lukem #include <sys/cdefs.h> 34 1.30 thorpej __KERNEL_RCSID(0, "$NetBSD: if_le_lebuffer.c,v 1.30 2022/09/25 18:03:04 thorpej Exp $"); 35 1.1 pk 36 1.1 pk #include "opt_inet.h" 37 1.1 pk 38 1.1 pk #include <sys/param.h> 39 1.1 pk #include <sys/systm.h> 40 1.1 pk #include <sys/mbuf.h> 41 1.1 pk #include <sys/syslog.h> 42 1.1 pk #include <sys/socket.h> 43 1.1 pk #include <sys/device.h> 44 1.1 pk 45 1.1 pk #include <net/if.h> 46 1.1 pk #include <net/if_ether.h> 47 1.1 pk #include <net/if_media.h> 48 1.1 pk 49 1.1 pk #ifdef INET 50 1.1 pk #include <netinet/in.h> 51 1.1 pk #include <netinet/if_inarp.h> 52 1.1 pk #endif 53 1.1 pk 54 1.22 ad #include <sys/bus.h> 55 1.22 ad #include <sys/intr.h> 56 1.1 pk #include <machine/autoconf.h> 57 1.1 pk 58 1.1 pk #include <dev/sbus/sbusvar.h> 59 1.1 pk #include <dev/sbus/lebuffervar.h> 60 1.1 pk 61 1.1 pk #include <dev/ic/lancereg.h> 62 1.1 pk #include <dev/ic/lancevar.h> 63 1.1 pk #include <dev/ic/am7990reg.h> 64 1.1 pk #include <dev/ic/am7990var.h> 65 1.1 pk 66 1.23 tsutsui #include "ioconf.h" 67 1.23 tsutsui 68 1.1 pk /* 69 1.1 pk * LANCE registers. 70 1.1 pk */ 71 1.3 pk #define LEREG1_RDP 0 /* Register Data port */ 72 1.3 pk #define LEREG1_RAP 2 /* Register Address port */ 73 1.1 pk 74 1.1 pk struct le_softc { 75 1.3 pk struct am7990_softc sc_am7990; /* glue to MI code */ 76 1.3 pk bus_space_tag_t sc_bustag; 77 1.3 pk bus_dma_tag_t sc_dmatag; 78 1.3 pk bus_space_handle_t sc_reg; /* LANCE registers */ 79 1.1 pk }; 80 1.1 pk 81 1.1 pk 82 1.23 tsutsui int lematch_lebuffer(device_t, cfdata_t, void *); 83 1.23 tsutsui void leattach_lebuffer(device_t, device_t, void *); 84 1.1 pk 85 1.1 pk /* 86 1.1 pk * Media types supported. 87 1.1 pk */ 88 1.1 pk static int lemedia[] = { 89 1.29 msaitoh IFM_ETHER | IFM_10_T, 90 1.1 pk }; 91 1.23 tsutsui #define NLEMEDIA __arraycount(lemedia) 92 1.1 pk 93 1.23 tsutsui CFATTACH_DECL_NEW(le_lebuffer, sizeof(struct le_softc), 94 1.15 thorpej lematch_lebuffer, leattach_lebuffer, NULL, NULL); 95 1.1 pk 96 1.7 mrg #if defined(_KERNEL_OPT) 97 1.1 pk #include "opt_ddb.h" 98 1.1 pk #endif 99 1.1 pk 100 1.23 tsutsui static void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 101 1.23 tsutsui static uint16_t lerdcsr(struct lance_softc *, uint16_t); 102 1.1 pk 103 1.1 pk static void 104 1.23 tsutsui lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 105 1.1 pk { 106 1.3 pk struct le_softc *lesc = (struct le_softc *)sc; 107 1.17 pk bus_space_tag_t t = lesc->sc_bustag; 108 1.17 pk bus_space_handle_t h = lesc->sc_reg; 109 1.1 pk 110 1.17 pk bus_space_write_2(t, h, LEREG1_RAP, port); 111 1.17 pk bus_space_write_2(t, h, LEREG1_RDP, val); 112 1.1 pk 113 1.1 pk #if defined(SUN4M) 114 1.1 pk /* 115 1.1 pk * We need to flush the Sbus->Mbus write buffers. This can most 116 1.1 pk * easily be accomplished by reading back the register that we 117 1.1 pk * just wrote (thanks to Chris Torek for this solution). 118 1.1 pk */ 119 1.17 pk (void)bus_space_read_2(t, h, LEREG1_RDP); 120 1.1 pk #endif 121 1.1 pk } 122 1.1 pk 123 1.23 tsutsui static uint16_t 124 1.23 tsutsui lerdcsr(struct lance_softc *sc, uint16_t port) 125 1.1 pk { 126 1.3 pk struct le_softc *lesc = (struct le_softc *)sc; 127 1.17 pk bus_space_tag_t t = lesc->sc_bustag; 128 1.17 pk bus_space_handle_t h = lesc->sc_reg; 129 1.1 pk 130 1.17 pk bus_space_write_2(t, h, LEREG1_RAP, port); 131 1.17 pk return (bus_space_read_2(t, h, LEREG1_RDP)); 132 1.1 pk } 133 1.1 pk 134 1.1 pk int 135 1.23 tsutsui lematch_lebuffer(device_t parent, cfdata_t cf, void *aux) 136 1.1 pk { 137 1.1 pk struct sbus_attach_args *sa = aux; 138 1.1 pk 139 1.12 thorpej return (strcmp(cf->cf_name, sa->sa_name) == 0); 140 1.1 pk } 141 1.1 pk 142 1.1 pk 143 1.1 pk void 144 1.23 tsutsui leattach_lebuffer(device_t parent, device_t self, void *aux) 145 1.1 pk { 146 1.23 tsutsui struct le_softc *lesc = device_private(self); 147 1.23 tsutsui struct lance_softc *sc = &lesc->sc_am7990.lsc; 148 1.23 tsutsui struct lebuf_softc *lebuf = device_private(parent); 149 1.1 pk struct sbus_attach_args *sa = aux; 150 1.1 pk 151 1.23 tsutsui sc->sc_dev = self; 152 1.1 pk lesc->sc_bustag = sa->sa_bustag; 153 1.1 pk lesc->sc_dmatag = sa->sa_dmatag; 154 1.1 pk 155 1.10 pk if (sbus_bus_map(sa->sa_bustag, 156 1.10 pk sa->sa_slot, 157 1.10 pk sa->sa_offset, 158 1.10 pk sa->sa_size, 159 1.11 eeh 0, &lesc->sc_reg)) { 160 1.23 tsutsui aprint_error(": cannot map registers\n"); 161 1.1 pk return; 162 1.1 pk } 163 1.1 pk 164 1.1 pk sc->sc_mem = lebuf->sc_buffer; 165 1.1 pk sc->sc_memsize = lebuf->sc_bufsiz; 166 1.1 pk sc->sc_addr = 0; /* Lance view is offset by buffer location */ 167 1.1 pk lebuf->attached = 1; 168 1.1 pk 169 1.1 pk /* That old black magic... */ 170 1.19 pk sc->sc_conf3 = prom_getpropint(sa->sa_node, "busmaster-regval", 171 1.1 pk LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON); 172 1.1 pk 173 1.1 pk sc->sc_supmedia = lemedia; 174 1.1 pk sc->sc_nsupmedia = NLEMEDIA; 175 1.1 pk sc->sc_defaultmedia = lemedia[0]; 176 1.1 pk 177 1.18 pk prom_getether(sa->sa_node, sc->sc_enaddr); 178 1.1 pk 179 1.1 pk sc->sc_copytodesc = lance_copytobuf_contig; 180 1.1 pk sc->sc_copyfromdesc = lance_copyfrombuf_contig; 181 1.1 pk sc->sc_copytobuf = lance_copytobuf_contig; 182 1.1 pk sc->sc_copyfrombuf = lance_copyfrombuf_contig; 183 1.1 pk sc->sc_zerobuf = lance_zerobuf_contig; 184 1.1 pk 185 1.1 pk sc->sc_rdcsr = lerdcsr; 186 1.1 pk sc->sc_wrcsr = lewrcsr; 187 1.1 pk 188 1.1 pk am7990_config(&lesc->sc_am7990); 189 1.1 pk 190 1.4 pk /* Establish interrupt handler */ 191 1.4 pk if (sa->sa_nintr != 0) 192 1.6 pk (void)bus_intr_establish(lesc->sc_bustag, sa->sa_pri, 193 1.16 pk IPL_NET, am7990_intr, sc); 194 1.1 pk } 195