Home | History | Annotate | Line # | Download | only in dev
if_ie_vme.c revision 1.9
      1 /*	$NetBSD: if_ie_vme.c,v 1.9 1997/10/17 03:44:49 gwr 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 <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 #include <sys/protosw.h>
     47 #include <sys/socket.h>
     48 #include <net/if.h>
     49 #include <net/if_ether.h>
     50 
     51 #ifdef INET
     52 #include <netinet/in.h>
     53 #include <netinet/in_systm.h>
     54 #include <netinet/in_var.h>
     55 #include <netinet/ip.h>
     56 #include <netinet/if_inarp.h>
     57 #endif
     58 
     59 #include <machine/autoconf.h>
     60 #include <machine/cpu.h>
     61 #include <machine/dvma.h>
     62 #include <machine/idprom.h>
     63 #include <machine/vmparam.h>
     64 
     65 #include "i82586.h"
     66 #include "if_iereg.h"
     67 #include "if_ievar.h"
     68 
     69 static void ie_vmereset __P((struct ie_softc *));
     70 static void ie_vmeattend __P((struct ie_softc *));
     71 static void ie_vmerun __P((struct ie_softc *));
     72 
     73 /*
     74  * zero/copy functions: OBIO can use the normal functions, but VME
     75  *    must do only byte or half-word (16 bit) accesses...
     76  */
     77 static void wcopy __P((const void *vb1, void *vb2, u_int l));
     78 static void wzero __P((void *vb, u_int l));
     79 
     80 
     81 /*
     82  * New-style autoconfig attachment
     83  */
     84 
     85 static int  ie_vmes_match __P((struct device *, struct cfdata *, void *));
     86 static void ie_vmes_attach __P((struct device *, struct device *, void *));
     87 
     88 struct cfattach ie_vmes_ca = {
     89 	sizeof(struct ie_softc), ie_vmes_match, ie_vmes_attach
     90 };
     91 
     92 
     93 static int
     94 ie_vmes_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_vmes_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_bcopy = wcopy;
    138 	sc->sc_bzero = wzero;
    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_bzero)(sc->sc_maddr, 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 void
    207 ie_vmereset(sc)
    208 	struct ie_softc *sc;
    209 {
    210 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    211 	iev->status = IEVME_RESET;
    212 	delay(100);		/* XXX could be shorter? */
    213 	iev->status = 0;
    214 }
    215 
    216 void
    217 ie_vmeattend(sc)
    218 	struct ie_softc *sc;
    219 {
    220 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    221 
    222 	iev->status |= IEVME_ATTEN;	/* flag! */
    223 	iev->status &= ~IEVME_ATTEN;	/* down. */
    224 }
    225 
    226 void
    227 ie_vmerun(sc)
    228 	struct ie_softc *sc;
    229 {
    230 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    231 
    232 	iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
    233 }
    234 
    235 /*
    236  * wcopy/wzero - like bcopy/bzero 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 wzero(vb, l)
    243 	void *vb;
    244 	u_int l;
    245 {
    246 	u_char *b = vb;
    247 	u_char *be = b + l;
    248 	u_short *sp;
    249 
    250 	if (l == 0)
    251 		return;
    252 
    253 	/* front, */
    254 	if ((u_long)b & 1)
    255 		*b++ = 0;
    256 
    257 	/* back, */
    258 	if (b != be && ((u_long)be & 1) != 0) {
    259 		be--;
    260 		*be = 0;
    261 	}
    262 
    263 	/* and middle. */
    264 	sp = (u_short *)b;
    265 	while (sp != (u_short *)be)
    266 		*sp++ = 0;
    267 }
    268 
    269 static void
    270 wcopy(vb1, vb2, l)
    271 	const void *vb1;
    272 	void *vb2;
    273 	u_int l;
    274 {
    275 	const u_char *b1e, *b1 = vb1;
    276 	u_char *b2 = vb2;
    277 	u_short *sp;
    278 	int bstore = 0;
    279 
    280 	if (l == 0)
    281 		return;
    282 
    283 	/* front, */
    284 	if ((u_long)b1 & 1) {
    285 		*b2++ = *b1++;
    286 		l--;
    287 	}
    288 
    289 	/* middle, */
    290 	sp = (u_short *)b1;
    291 	b1e = b1 + l;
    292 	if (l & 1)
    293 		b1e--;
    294 	bstore = (u_long)b2 & 1;
    295 
    296 	while (sp < (u_short *)b1e) {
    297 		if (bstore) {
    298 			b2[1] = *sp & 0xff;
    299 			b2[0] = *sp >> 8;
    300 		} else
    301 			*((short *)b2) = *sp;
    302 		sp++;
    303 		b2 += 2;
    304 	}
    305 
    306 	/* and back. */
    307 	if (l & 1)
    308 		*b2 = *b1e;
    309 }
    310