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