1 /* $NetBSD: if_ie_sebuf.c,v 1.9 2002/10/02 16:02:26 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Gordon W. Ross. 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 * Machine-dependent glue for the Intel Ethernet (ie) driver, 41 * as found on the Sun3/E SCSI/Ethernet board. 42 */ 43 #include "opt_inet.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/device.h> 48 #include <sys/protosw.h> 49 #include <sys/socket.h> 50 #include <net/if.h> 51 #include <net/if_ether.h> 52 53 #ifdef INET 54 #include <netinet/in.h> 55 #include <netinet/in_systm.h> 56 #include <netinet/in_var.h> 57 #include <netinet/ip.h> 58 #include <netinet/if_inarp.h> 59 #endif 60 61 #include <machine/autoconf.h> 62 #include <machine/cpu.h> 63 #include <machine/dvma.h> 64 #include <machine/idprom.h> 65 #include <machine/vmparam.h> 66 67 #include "i82586.h" 68 #include "if_iereg.h" 69 #include "if_ievar.h" 70 #include "sereg.h" 71 #include "sevar.h" 72 73 static void ie_sebuf_reset __P((struct ie_softc *)); 74 static void ie_sebuf_attend __P((struct ie_softc *)); 75 static void ie_sebuf_run __P((struct ie_softc *)); 76 77 /* 78 * zero/copy functions: OBIO can use the normal functions, but VME 79 * must do only byte or half-word (16 bit) accesses... 80 */ 81 static void *wmemcpy __P((void *dst, const void *src, size_t size)); 82 static void *wmemset __P((void *dst, int val, size_t size)); 83 84 85 /* 86 * New-style autoconfig attachment 87 */ 88 89 static int ie_sebuf_match __P((struct device *, struct cfdata *, void *)); 90 static void ie_sebuf_attach __P((struct device *, struct device *, void *)); 91 92 CFATTACH_DECL(ie_sebuf, sizeof(struct ie_softc), 93 ie_sebuf_match, ie_sebuf_attach, NULL, NULL); 94 95 static int 96 ie_sebuf_match(parent, cf, args) 97 struct device *parent; 98 struct cfdata *cf; 99 void *args; 100 { 101 struct sebuf_attach_args *aa = args; 102 103 /* Match by name. */ 104 if (strcmp(aa->name, "ie")) 105 return (0); 106 107 /* Anyting else to check? */ 108 109 return (1); 110 } 111 112 static void 113 ie_sebuf_attach(parent, self, args) 114 struct device *parent; 115 struct device *self; 116 void *args; 117 { 118 struct ie_softc *sc = (void *) self; 119 struct sebuf_attach_args *aa = args; 120 volatile struct ie_regs *regs; 121 int off; 122 123 sc->hard_type = IE_VME3E; 124 sc->reset_586 = ie_sebuf_reset; 125 sc->chan_attn = ie_sebuf_attend; 126 sc->run_586 = ie_sebuf_run; 127 sc->sc_memcpy = wmemcpy; 128 sc->sc_memset = wmemset; 129 130 /* Control regs mapped by parent. */ 131 sc->sc_reg = aa->regs; 132 regs = (struct ie_regs *) sc->sc_reg; 133 134 /* 135 * On this hardware, the i82586 address zero 136 * maps to the start of the board, which we 137 * happen to know is 128K below (XXX). 138 */ 139 sc->sc_iobase = aa->buf - 0x20000; 140 141 /* 142 * There is 128K of memory for the i82586 on 143 * the Sun3/E SCSI/Ethernet board, and the 144 * "sebuf" driver has mapped it in for us. 145 * (Fixed in hardware; NOT configurable!) 146 */ 147 if (aa->blen < SE_IEBUFSIZE) 148 panic("ie_sebuf: bad size"); 149 sc->sc_msize = SE_IEBUFSIZE; 150 sc->sc_maddr = aa->buf; 151 152 /* Clear the memory. */ 153 (sc->sc_memset)(sc->sc_maddr, 0, sc->sc_msize); 154 155 /* 156 * XXX: Unfortunately, the common driver code 157 * is not ready to deal with more than 64K of 158 * memory, so skip the first 64K. Too bad. 159 * Note: device needs the SCP at the end. 160 */ 161 sc->sc_msize -= 0x10000; 162 sc->sc_maddr += 0x10000; 163 164 /* 165 * Set the System Configuration Pointer (SCP). 166 * Its location is system-dependent because the 167 * i82586 reads it from a fixed physical address. 168 * On this hardware, the i82586 address is just 169 * masked down to 17 bits, so the SCP is found 170 * at the end of the RAM on the VME board. 171 */ 172 off = IE_SCP_ADDR & 0xFFFF; 173 sc->scp = (volatile void *) (sc->sc_maddr + off); 174 175 /* 176 * The rest of ram is used for buffers, etc. 177 */ 178 sc->buf_area = sc->sc_maddr; 179 sc->buf_area_sz = off; 180 181 /* Install interrupt handler. */ 182 regs->ie_ivec = aa->ca.ca_intvec; 183 isr_add_vectored(ie_intr, (void *)sc, 184 aa->ca.ca_intpri, aa->ca.ca_intvec); 185 186 /* Set the ethernet address. */ 187 idprom_etheraddr(sc->sc_addr); 188 189 /* Do machine-independent parts of attach. */ 190 ie_attach(sc); 191 192 } 193 194 /* Whack the "channel attetion" line. */ 195 void 196 ie_sebuf_attend(sc) 197 struct ie_softc *sc; 198 { 199 volatile struct ie_regs *regs = (struct ie_regs *) sc->sc_reg; 200 201 regs->ie_csr |= IE_CSR_ATTEN; /* flag! */ 202 regs->ie_csr &= ~IE_CSR_ATTEN; /* down. */ 203 } 204 205 /* 206 * This is called during driver attach. 207 * Reset and initialize. 208 */ 209 void 210 ie_sebuf_reset(sc) 211 struct ie_softc *sc; 212 { 213 volatile struct ie_regs *regs = (struct ie_regs *) sc->sc_reg; 214 regs->ie_csr = IE_CSR_RESET; 215 delay(20); 216 regs->ie_csr = (IE_CSR_NOLOOP | IE_CSR_IENAB); 217 } 218 219 /* 220 * This is called at the end of ieinit(). 221 * optional. 222 */ 223 void 224 ie_sebuf_run(sc) 225 struct ie_softc *sc; 226 { 227 /* do it all in reset */ 228 } 229 230 /* 231 * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits, 232 * and also does byte swaps... 233 * XXX - Would be nice to have asm versions in some library... 234 */ 235 236 static void * 237 wmemset(vb, val, l) 238 void *vb; 239 int val; 240 size_t l; 241 { 242 u_char *b = vb; 243 u_char *be = b + l; 244 u_short *sp; 245 246 if (l == 0) 247 return (vb); 248 249 /* front, */ 250 if ((u_long)b & 1) 251 *b++ = val; 252 253 /* back, */ 254 if (b != be && ((u_long)be & 1) != 0) { 255 be--; 256 *be = val; 257 } 258 259 /* and middle. */ 260 sp = (u_short *)b; 261 while (sp != (u_short *)be) 262 *sp++ = val; 263 264 return (vb); 265 } 266 267 static void * 268 wmemcpy(dst, src, l) 269 void *dst; 270 const void *src; 271 size_t l; 272 { 273 const u_char *b1e, *b1 = src; 274 u_char *b2 = dst; 275 u_short *sp; 276 int bstore = 0; 277 278 if (l == 0) 279 return (dst); 280 281 /* front, */ 282 if ((u_long)b1 & 1) { 283 *b2++ = *b1++; 284 l--; 285 } 286 287 /* middle, */ 288 sp = (u_short *)b1; 289 b1e = b1 + l; 290 if (l & 1) 291 b1e--; 292 bstore = (u_long)b2 & 1; 293 294 while (sp < (u_short *)b1e) { 295 if (bstore) { 296 b2[1] = *sp & 0xff; 297 b2[0] = *sp >> 8; 298 } else 299 *((short *)b2) = *sp; 300 sp++; 301 b2 += 2; 302 } 303 304 /* and back. */ 305 if (l & 1) 306 *b2 = *b1e; 307 308 return (dst); 309 } 310