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