1 1.17 tsutsui /* $NetBSD: if_ie_sebuf.c,v 1.17 2024/12/20 23:52:00 tsutsui Exp $ */ 2 1.1 gwr 3 1.1 gwr /*- 4 1.1 gwr * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 1.1 gwr * All rights reserved. 6 1.1 gwr * 7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation 8 1.1 gwr * by Gordon W. Ross. 9 1.1 gwr * 10 1.1 gwr * Redistribution and use in source and binary forms, with or without 11 1.1 gwr * modification, are permitted provided that the following conditions 12 1.1 gwr * are met: 13 1.1 gwr * 1. Redistributions of source code must retain the above copyright 14 1.1 gwr * notice, this list of conditions and the following disclaimer. 15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 gwr * notice, this list of conditions and the following disclaimer in the 17 1.1 gwr * documentation and/or other materials provided with the distribution. 18 1.1 gwr * 19 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 gwr * POSSIBILITY OF SUCH DAMAGE. 30 1.1 gwr */ 31 1.1 gwr 32 1.1 gwr /* 33 1.1 gwr * Machine-dependent glue for the Intel Ethernet (ie) driver, 34 1.1 gwr * as found on the Sun3/E SCSI/Ethernet board. 35 1.1 gwr */ 36 1.10 lukem 37 1.10 lukem #include <sys/cdefs.h> 38 1.17 tsutsui __KERNEL_RCSID(0, "$NetBSD: if_ie_sebuf.c,v 1.17 2024/12/20 23:52:00 tsutsui Exp $"); 39 1.10 lukem 40 1.5 jonathan #include "opt_inet.h" 41 1.1 gwr 42 1.1 gwr #include <sys/param.h> 43 1.1 gwr #include <sys/systm.h> 44 1.1 gwr #include <sys/device.h> 45 1.1 gwr #include <sys/protosw.h> 46 1.1 gwr #include <sys/socket.h> 47 1.1 gwr #include <net/if.h> 48 1.1 gwr #include <net/if_ether.h> 49 1.1 gwr 50 1.1 gwr #ifdef INET 51 1.1 gwr #include <netinet/in.h> 52 1.1 gwr #include <netinet/in_systm.h> 53 1.1 gwr #include <netinet/in_var.h> 54 1.1 gwr #include <netinet/ip.h> 55 1.1 gwr #include <netinet/if_inarp.h> 56 1.1 gwr #endif 57 1.1 gwr 58 1.1 gwr #include <machine/autoconf.h> 59 1.1 gwr #include <machine/cpu.h> 60 1.1 gwr #include <machine/dvma.h> 61 1.1 gwr #include <machine/idprom.h> 62 1.1 gwr #include <machine/vmparam.h> 63 1.1 gwr 64 1.1 gwr #include "i82586.h" 65 1.1 gwr #include "if_iereg.h" 66 1.1 gwr #include "if_ievar.h" 67 1.1 gwr #include "sereg.h" 68 1.1 gwr #include "sevar.h" 69 1.1 gwr 70 1.11 chs static void ie_sebuf_reset(struct ie_softc *); 71 1.11 chs static void ie_sebuf_attend(struct ie_softc *); 72 1.11 chs static void ie_sebuf_run(struct ie_softc *); 73 1.1 gwr 74 1.1 gwr /* 75 1.4 gwr * zero/copy functions: OBIO can use the normal functions, but VME 76 1.4 gwr * must do only byte or half-word (16 bit) accesses... 77 1.4 gwr */ 78 1.11 chs static void *wmemcpy(void *, const void *, size_t); 79 1.11 chs static void *wmemset(void *, int, size_t); 80 1.4 gwr 81 1.4 gwr 82 1.4 gwr /* 83 1.1 gwr * New-style autoconfig attachment 84 1.1 gwr */ 85 1.1 gwr 86 1.16 tsutsui static int ie_sebuf_match(device_t, cfdata_t, void *); 87 1.16 tsutsui static void ie_sebuf_attach(device_t, device_t, void *); 88 1.1 gwr 89 1.16 tsutsui CFATTACH_DECL_NEW(ie_sebuf, sizeof(struct ie_softc), 90 1.9 thorpej ie_sebuf_match, ie_sebuf_attach, NULL, NULL); 91 1.1 gwr 92 1.17 tsutsui static int 93 1.16 tsutsui ie_sebuf_match(device_t parent, cfdata_t cf, void *args) 94 1.1 gwr { 95 1.1 gwr struct sebuf_attach_args *aa = args; 96 1.1 gwr 97 1.1 gwr /* Match by name. */ 98 1.1 gwr if (strcmp(aa->name, "ie")) 99 1.16 tsutsui return 0; 100 1.1 gwr 101 1.2 gwr /* Anyting else to check? */ 102 1.1 gwr 103 1.16 tsutsui return 1; 104 1.1 gwr } 105 1.1 gwr 106 1.17 tsutsui static void 107 1.16 tsutsui ie_sebuf_attach(device_t parent, device_t self, void *args) 108 1.1 gwr { 109 1.16 tsutsui struct ie_softc *sc = device_private(self); 110 1.1 gwr struct sebuf_attach_args *aa = args; 111 1.1 gwr volatile struct ie_regs *regs; 112 1.1 gwr int off; 113 1.1 gwr 114 1.16 tsutsui sc->sc_dev = self; 115 1.1 gwr sc->hard_type = IE_VME3E; 116 1.1 gwr sc->reset_586 = ie_sebuf_reset; 117 1.1 gwr sc->chan_attn = ie_sebuf_attend; 118 1.1 gwr sc->run_586 = ie_sebuf_run; 119 1.6 thorpej sc->sc_memcpy = wmemcpy; 120 1.6 thorpej sc->sc_memset = wmemset; 121 1.4 gwr 122 1.4 gwr /* Control regs mapped by parent. */ 123 1.4 gwr sc->sc_reg = aa->regs; 124 1.16 tsutsui regs = (struct ie_regs *)sc->sc_reg; 125 1.4 gwr 126 1.4 gwr /* 127 1.4 gwr * On this hardware, the i82586 address zero 128 1.4 gwr * maps to the start of the board, which we 129 1.4 gwr * happen to know is 128K below (XXX). 130 1.4 gwr */ 131 1.4 gwr sc->sc_iobase = aa->buf - 0x20000; 132 1.1 gwr 133 1.1 gwr /* 134 1.3 gwr * There is 128K of memory for the i82586 on 135 1.3 gwr * the Sun3/E SCSI/Ethernet board, and the 136 1.3 gwr * "sebuf" driver has mapped it in for us. 137 1.3 gwr * (Fixed in hardware; NOT configurable!) 138 1.1 gwr */ 139 1.3 gwr if (aa->blen < SE_IEBUFSIZE) 140 1.3 gwr panic("ie_sebuf: bad size"); 141 1.3 gwr sc->sc_msize = SE_IEBUFSIZE; 142 1.1 gwr sc->sc_maddr = aa->buf; 143 1.4 gwr 144 1.4 gwr /* Clear the memory. */ 145 1.6 thorpej (sc->sc_memset)(sc->sc_maddr, 0, sc->sc_msize); 146 1.1 gwr 147 1.3 gwr /* 148 1.4 gwr * XXX: Unfortunately, the common driver code 149 1.4 gwr * is not ready to deal with more than 64K of 150 1.4 gwr * memory, so skip the first 64K. Too bad. 151 1.4 gwr * Note: device needs the SCP at the end. 152 1.3 gwr */ 153 1.4 gwr sc->sc_msize -= 0x10000; 154 1.14 tsutsui sc->sc_maddr = (char *)sc->sc_maddr + 0x10000; 155 1.1 gwr 156 1.1 gwr /* 157 1.1 gwr * Set the System Configuration Pointer (SCP). 158 1.1 gwr * Its location is system-dependent because the 159 1.1 gwr * i82586 reads it from a fixed physical address. 160 1.1 gwr * On this hardware, the i82586 address is just 161 1.3 gwr * masked down to 17 bits, so the SCP is found 162 1.1 gwr * at the end of the RAM on the VME board. 163 1.1 gwr */ 164 1.4 gwr off = IE_SCP_ADDR & 0xFFFF; 165 1.14 tsutsui sc->scp = (volatile void *)((char *)sc->sc_maddr + off); 166 1.1 gwr 167 1.1 gwr /* 168 1.1 gwr * The rest of ram is used for buffers, etc. 169 1.1 gwr */ 170 1.3 gwr sc->buf_area = sc->sc_maddr; 171 1.3 gwr sc->buf_area_sz = off; 172 1.1 gwr 173 1.1 gwr /* Install interrupt handler. */ 174 1.1 gwr regs->ie_ivec = aa->ca.ca_intvec; 175 1.16 tsutsui isr_add_vectored(ie_intr, sc, aa->ca.ca_intpri, aa->ca.ca_intvec); 176 1.1 gwr 177 1.4 gwr /* Set the ethernet address. */ 178 1.4 gwr idprom_etheraddr(sc->sc_addr); 179 1.4 gwr 180 1.1 gwr /* Do machine-independent parts of attach. */ 181 1.1 gwr ie_attach(sc); 182 1.1 gwr 183 1.1 gwr } 184 1.1 gwr 185 1.4 gwr /* Whack the "channel attetion" line. */ 186 1.17 tsutsui void 187 1.11 chs ie_sebuf_attend(struct ie_softc *sc) 188 1.4 gwr { 189 1.16 tsutsui volatile struct ie_regs *regs = (struct ie_regs *)sc->sc_reg; 190 1.4 gwr 191 1.4 gwr regs->ie_csr |= IE_CSR_ATTEN; /* flag! */ 192 1.4 gwr regs->ie_csr &= ~IE_CSR_ATTEN; /* down. */ 193 1.4 gwr } 194 1.1 gwr 195 1.1 gwr /* 196 1.4 gwr * This is called during driver attach. 197 1.4 gwr * Reset and initialize. 198 1.1 gwr */ 199 1.17 tsutsui void 200 1.11 chs ie_sebuf_reset(struct ie_softc *sc) 201 1.1 gwr { 202 1.16 tsutsui volatile struct ie_regs *regs = (struct ie_regs *)sc->sc_reg; 203 1.1 gwr regs->ie_csr = IE_CSR_RESET; 204 1.4 gwr delay(20); 205 1.4 gwr regs->ie_csr = (IE_CSR_NOLOOP | IE_CSR_IENAB); 206 1.1 gwr } 207 1.1 gwr 208 1.4 gwr /* 209 1.4 gwr * This is called at the end of ieinit(). 210 1.4 gwr * optional. 211 1.4 gwr */ 212 1.17 tsutsui void 213 1.11 chs ie_sebuf_run(struct ie_softc *sc) 214 1.1 gwr { 215 1.16 tsutsui 216 1.4 gwr /* do it all in reset */ 217 1.4 gwr } 218 1.4 gwr 219 1.4 gwr /* 220 1.6 thorpej * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits, 221 1.4 gwr * and also does byte swaps... 222 1.4 gwr * XXX - Would be nice to have asm versions in some library... 223 1.4 gwr */ 224 1.1 gwr 225 1.6 thorpej static void * 226 1.11 chs wmemset(void *vb, int val, size_t l) 227 1.4 gwr { 228 1.16 tsutsui uint8_t *b = vb; 229 1.16 tsutsui uint8_t *be = b + l; 230 1.16 tsutsui uint16_t *sp; 231 1.4 gwr 232 1.4 gwr if (l == 0) 233 1.16 tsutsui return vb; 234 1.4 gwr 235 1.4 gwr /* front, */ 236 1.16 tsutsui if ((uint32_t)b & 1) 237 1.6 thorpej *b++ = val; 238 1.4 gwr 239 1.4 gwr /* back, */ 240 1.16 tsutsui if (b != be && ((uint32_t)be & 1) != 0) { 241 1.4 gwr be--; 242 1.6 thorpej *be = val; 243 1.4 gwr } 244 1.4 gwr 245 1.4 gwr /* and middle. */ 246 1.16 tsutsui sp = (uint16_t *)b; 247 1.16 tsutsui while (sp != (uint16_t *)be) 248 1.6 thorpej *sp++ = val; 249 1.6 thorpej 250 1.16 tsutsui return vb; 251 1.1 gwr } 252 1.1 gwr 253 1.6 thorpej static void * 254 1.11 chs wmemcpy(void *dst, const void *src, size_t l) 255 1.1 gwr { 256 1.16 tsutsui const uint8_t *b1e, *b1 = src; 257 1.16 tsutsui uint8_t *b2 = dst; 258 1.16 tsutsui const uint16_t *sp; 259 1.4 gwr int bstore = 0; 260 1.4 gwr 261 1.4 gwr if (l == 0) 262 1.16 tsutsui return dst; 263 1.4 gwr 264 1.4 gwr /* front, */ 265 1.16 tsutsui if ((uint32_t)b1 & 1) { 266 1.4 gwr *b2++ = *b1++; 267 1.4 gwr l--; 268 1.4 gwr } 269 1.4 gwr 270 1.4 gwr /* middle, */ 271 1.16 tsutsui sp = (const uint16_t *)b1; 272 1.4 gwr b1e = b1 + l; 273 1.4 gwr if (l & 1) 274 1.4 gwr b1e--; 275 1.16 tsutsui bstore = (uint32_t)b2 & 1; 276 1.4 gwr 277 1.16 tsutsui while (sp < (const uint16_t *)b1e) { 278 1.4 gwr if (bstore) { 279 1.4 gwr b2[1] = *sp & 0xff; 280 1.4 gwr b2[0] = *sp >> 8; 281 1.4 gwr } else 282 1.16 tsutsui *((uint16_t *)b2) = *sp; 283 1.4 gwr sp++; 284 1.4 gwr b2 += 2; 285 1.4 gwr } 286 1.4 gwr 287 1.4 gwr /* and back. */ 288 1.4 gwr if (l & 1) 289 1.4 gwr *b2 = *b1e; 290 1.6 thorpej 291 1.16 tsutsui return dst; 292 1.1 gwr } 293