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