Home | History | Annotate | Line # | Download | only in dev
if_ie_vme.c revision 1.13.30.1
      1 /*	$NetBSD: if_ie_vme.c,v 1.13.30.1 2002/10/18 02:40:20 nathanw 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  */
     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 
     71 static void ie_vmereset __P((struct ie_softc *));
     72 static void ie_vmeattend __P((struct ie_softc *));
     73 static void ie_vmerun __P((struct ie_softc *));
     74 
     75 /*
     76  * zero/copy functions: OBIO can use the normal functions, but VME
     77  *    must do only byte or half-word (16 bit) accesses...
     78  */
     79 static void *wmemcpy __P((void *dst, const void *src, size_t size));
     80 static void *wmemset __P((void *dst, int val, size_t size));
     81 
     82 
     83 /*
     84  * New-style autoconfig attachment
     85  */
     86 
     87 static int  ie_vme_match __P((struct device *, struct cfdata *, void *));
     88 static void ie_vme_attach __P((struct device *, struct device *, void *));
     89 
     90 CFATTACH_DECL(ie_vme, sizeof(struct ie_softc),
     91     ie_vme_match, ie_vme_attach, NULL, NULL);
     92 
     93 static int
     94 ie_vme_match(parent, cf, args)
     95 	struct device *parent;
     96 	struct cfdata *cf;
     97 	void *args;
     98 {
     99 	struct confargs *ca = args;
    100 
    101 	/* No default VME address. */
    102 	if (ca->ca_paddr == -1)
    103 		return(0);
    104 
    105 	/* Make sure something is there... */
    106 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
    107 		return (0);
    108 
    109 	/* Default interrupt priority. */
    110 	if (ca->ca_intpri == -1)
    111 		ca->ca_intpri = 3;
    112 
    113 	return (1);
    114 }
    115 
    116 /*
    117  * *note*: we don't detect the difference between a VME3E and
    118  * a multibus/vme card.   if you want to use a 3E you'll have
    119  * to fix this.
    120  */
    121 void
    122 ie_vme_attach(parent, self, args)
    123 	struct device *parent;
    124 	struct device *self;
    125 	void *args;
    126 {
    127 	struct ie_softc *sc = (void *) self;
    128 	struct confargs *ca = args;
    129 	volatile struct ievme *iev;
    130 	u_long  rampaddr;
    131 	int     lcv, off;
    132 
    133 	sc->hard_type = IE_VME;
    134 	sc->reset_586 = ie_vmereset;
    135 	sc->chan_attn = ie_vmeattend;
    136 	sc->run_586 = ie_vmerun;
    137 	sc->sc_memcpy = wmemcpy;
    138 	sc->sc_memset = wmemset;
    139 
    140 	/*
    141 	 * There is 64K of memory on the VME board.
    142 	 * (determined by hardware - NOT configurable!)
    143 	 */
    144 	sc->sc_msize = 0x10000; /* MEMSIZE 64K */
    145 
    146 	/* Map in the board control regs. */
    147 	sc->sc_reg = bus_mapin(ca->ca_bustype, ca->ca_paddr,
    148 						   sizeof(struct ievme));
    149 	iev = (volatile struct ievme *) sc->sc_reg;
    150 
    151 	/*
    152 	 * Find and map in the board memory.
    153 	 */
    154 	/* top 12 bits */
    155 	rampaddr = ca->ca_paddr & 0xfff00000;
    156 	/* 4 more */
    157 	rampaddr |= ((iev->status & IEVME_HADDR) << 16);
    158 	sc->sc_maddr = bus_mapin(ca->ca_bustype, rampaddr, sc->sc_msize);
    159 
    160 	/*
    161 	 * On this hardware, the i82586 address is just
    162 	 * masked to 16 bits, so sc_iobase == sc_maddr
    163 	 */
    164 	sc->sc_iobase = sc->sc_maddr;
    165 
    166 	/*
    167 	 * Set up on-board mapping registers for linear map.
    168 	 */
    169 	iev->pectrl |= IEVME_PARACK; /* clear to start */
    170 	for (lcv = 0; lcv < IEVME_MAPSZ; lcv++)
    171 		iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
    172 	(sc->sc_memset)(sc->sc_maddr, 0, sc->sc_msize);
    173 
    174 	/*
    175 	 * Set the System Configuration Pointer (SCP).
    176 	 * Its location is system-dependent because the
    177 	 * i82586 reads it from a fixed physical address.
    178 	 * On this hardware, the i82586 address is just
    179 	 * masked down to 16 bits, so the SCP is found
    180 	 * at the end of the RAM on the VME board.
    181 	 */
    182 	off = IE_SCP_ADDR & 0xFFFF;
    183 	sc->scp = (volatile void *) (sc->sc_maddr + off);
    184 
    185 	/*
    186 	 * The rest of ram is used for buffers, etc.
    187 	 */
    188 	sc->buf_area = sc->sc_maddr;
    189 	sc->buf_area_sz = off;
    190 
    191 	/* Set the ethernet address. */
    192 	idprom_etheraddr(sc->sc_addr);
    193 
    194 	/* Do machine-independent parts of attach. */
    195 	ie_attach(sc);
    196 
    197 	/* Install interrupt handler. */
    198 	isr_add_vectored(ie_intr, (void *)sc,
    199 		ca->ca_intpri, ca->ca_intvec);
    200 }
    201 
    202 
    203 /*
    204  * MULTIBUS/VME support
    205  */
    206 
    207 void
    208 ie_vmeattend(sc)
    209 	struct ie_softc *sc;
    210 {
    211 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    212 
    213 	iev->status |= IEVME_ATTEN;	/* flag! */
    214 	iev->status &= ~IEVME_ATTEN;	/* down. */
    215 }
    216 
    217 void
    218 ie_vmereset(sc)
    219 	struct ie_softc *sc;
    220 {
    221 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    222 
    223 	iev->status = IEVME_RESET;
    224 	delay(20);
    225 	iev->status = (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
    226 }
    227 
    228 void
    229 ie_vmerun(sc)
    230 	struct ie_softc *sc;
    231 {
    232 	/* do it all in reset */
    233 }
    234 
    235 /*
    236  * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits,
    237  * and also does byte swaps...
    238  * XXX - Would be nice to have asm versions in some library...
    239  */
    240 
    241 static void *
    242 wmemset(vb, val, l)
    243 	void *vb;
    244 	int val;
    245 	size_t l;
    246 {
    247 	u_char *b = vb;
    248 	u_char *be = b + l;
    249 	u_short *sp;
    250 
    251 	if (l == 0)
    252 		return (vb);
    253 
    254 	/* front, */
    255 	if ((u_long)b & 1)
    256 		*b++ = val;
    257 
    258 	/* back, */
    259 	if (b != be && ((u_long)be & 1) != 0) {
    260 		be--;
    261 		*be = val;
    262 	}
    263 
    264 	/* and middle. */
    265 	sp = (u_short *)b;
    266 	while (sp != (u_short *)be)
    267 		*sp++ = val;
    268 
    269 	return (vb);
    270 }
    271 
    272 static void *
    273 wmemcpy(dst, src, l)
    274 	void *dst;
    275 	const void *src;
    276 	size_t l;
    277 {
    278 	const u_char *b1e, *b1 = src;
    279 	u_char *b2 = dst;
    280 	u_short *sp;
    281 	int bstore = 0;
    282 
    283 	if (l == 0)
    284 		return (dst);
    285 
    286 	/* front, */
    287 	if ((u_long)b1 & 1) {
    288 		*b2++ = *b1++;
    289 		l--;
    290 	}
    291 
    292 	/* middle, */
    293 	sp = (u_short *)b1;
    294 	b1e = b1 + l;
    295 	if (l & 1)
    296 		b1e--;
    297 	bstore = (u_long)b2 & 1;
    298 
    299 	while (sp < (u_short *)b1e) {
    300 		if (bstore) {
    301 			b2[1] = *sp & 0xff;
    302 			b2[0] = *sp >> 8;
    303 		} else
    304 			*((short *)b2) = *sp;
    305 		sp++;
    306 		b2 += 2;
    307 	}
    308 
    309 	/* and back. */
    310 	if (l & 1)
    311 		*b2 = *b1e;
    312 
    313 	return (dst);
    314 }
    315