Home | History | Annotate | Line # | Download | only in vme
if_le_vme.c revision 1.9.2.1
      1  1.9.2.1       leo /*	$NetBSD: if_le_vme.c,v 1.9.2.1 1999/04/15 14:53:06 leo Exp $	*/
      2      1.1       leo 
      3      1.1       leo /*-
      4      1.9       leo  * Copyright (c) 1998 maximum entropy.  All rights reserved.
      5      1.1       leo  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
      6      1.1       leo  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      7      1.1       leo  * Copyright (c) 1992, 1993
      8      1.1       leo  *	The Regents of the University of California.  All rights reserved.
      9      1.1       leo  *
     10      1.1       leo  * This code is derived from software contributed to Berkeley by
     11      1.1       leo  * Ralph Campbell and Rick Macklem.
     12      1.1       leo  *
     13      1.1       leo  * Redistribution and use in source and binary forms, with or without
     14      1.1       leo  * modification, are permitted provided that the following conditions
     15      1.1       leo  * are met:
     16      1.1       leo  * 1. Redistributions of source code must retain the above copyright
     17      1.1       leo  *    notice, this list of conditions and the following disclaimer.
     18      1.1       leo  * 2. Redistributions in binary form must reproduce the above copyright
     19      1.1       leo  *    notice, this list of conditions and the following disclaimer in the
     20      1.1       leo  *    documentation and/or other materials provided with the distribution.
     21      1.1       leo  * 3. All advertising materials mentioning features or use of this software
     22      1.1       leo  *    must display the following acknowledgement:
     23      1.1       leo  *	This product includes software developed by the University of
     24      1.1       leo  *	California, Berkeley and its contributors.
     25      1.1       leo  * 4. Neither the name of the University nor the names of its contributors
     26      1.1       leo  *    may be used to endorse or promote products derived from this software
     27      1.1       leo  *    without specific prior written permission.
     28      1.1       leo  *
     29      1.1       leo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30      1.1       leo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31      1.1       leo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32      1.1       leo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33      1.1       leo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34      1.1       leo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35      1.1       leo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36      1.1       leo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37      1.1       leo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38      1.1       leo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39      1.1       leo  * SUCH DAMAGE.
     40      1.1       leo  *
     41      1.1       leo  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     42      1.1       leo  */
     43      1.1       leo 
     44      1.5  jonathan #include "opt_inet.h"
     45      1.1       leo #include "bpfilter.h"
     46      1.1       leo 
     47      1.1       leo #include <sys/param.h>
     48      1.1       leo #include <sys/systm.h>
     49      1.1       leo #include <sys/mbuf.h>
     50      1.1       leo #include <sys/syslog.h>
     51      1.1       leo #include <sys/socket.h>
     52      1.1       leo #include <sys/device.h>
     53      1.1       leo 
     54      1.1       leo #include <net/if.h>
     55      1.3   thorpej #include <net/if_media.h>
     56      1.4       leo #include <net/if_ether.h>
     57      1.1       leo 
     58      1.1       leo #ifdef INET
     59      1.1       leo #include <netinet/in.h>
     60      1.4       leo #include <netinet/if_inarp.h>
     61      1.1       leo #endif
     62      1.1       leo 
     63      1.1       leo #include <machine/cpu.h>
     64      1.1       leo #include <machine/bus.h>
     65      1.1       leo #include <machine/iomap.h>
     66      1.1       leo #include <machine/scu.h>
     67      1.1       leo 
     68      1.1       leo #include <atari/atari/device.h>
     69      1.1       leo #include <atari/atari/intr.h>
     70      1.1       leo 
     71      1.6  drochner #include <dev/ic/lancereg.h>
     72      1.6  drochner #include <dev/ic/lancevar.h>
     73      1.1       leo #include <dev/ic/am7990reg.h>
     74      1.1       leo #include <dev/ic/am7990var.h>
     75      1.1       leo 
     76      1.1       leo #include <atari/vme/vmevar.h>
     77      1.1       leo #include <atari/vme/if_levar.h>
     78      1.1       leo 
     79      1.7       leo /*
     80      1.7       leo  * All cards except BVME410 have 64KB RAM. However.... On the Riebl cards the
     81      1.7       leo  * area between the offsets 0xee70-0xeec0 is used to store config data.
     82      1.7       leo  */
     83      1.1       leo struct le_addresses {
     84      1.1       leo 	u_long	reg_addr;
     85      1.1       leo 	u_long	mem_addr;
     86      1.1       leo 	int	irq;
     87      1.7       leo 	int	reg_size;
     88      1.7       leo 	int	mem_size;
     89      1.8       leo 	int	type_hint;
     90      1.1       leo } lestd[] = {
     91      1.8       leo 	{ 0xfe00fff0, 0xfe010000, IRQUNK, 16, 64*1024,
     92      1.8       leo 				LE_OLD_RIEBL|LE_NEW_RIEBL }, /* Riebl	*/
     93      1.8       leo 	{ 0xffcffff0, 0xffcf0000,      5, 16, 64*1024,
     94      1.8       leo 				LE_PAM },		     /* PAM	*/
     95      1.8       leo 	{ 0xfecffff0, 0xfecf0000,      5, 16, 64*1024,
     96      1.8       leo 				LE_ROTHRON },		     /* Rhotron	*/
     97      1.8       leo 	{ 0xfeff4100, 0xfe000000,      4,  8, VMECF_MEMSIZ_DEFAULT,
     98      1.8       leo 				LE_BVME410 }		     /* BVME410 */
     99      1.1       leo };
    100      1.1       leo 
    101      1.1       leo #define	NLESTD	(sizeof(lestd) / sizeof(lestd[0]))
    102      1.1       leo 
    103      1.1       leo /*
    104      1.1       leo  * Default mac for RIEBL cards without a (working) battery. The first 4 bytes
    105      1.1       leo  * are the manufacturer id.
    106      1.1       leo  */
    107      1.1       leo static u_char riebl_def_mac[] = {
    108      1.1       leo 	0x00, 0x00, 0x36, 0x04, 0x00, 0x00
    109      1.1       leo };
    110      1.1       leo 
    111      1.1       leo static int le_intr __P((struct le_softc *, int));
    112      1.1       leo static void lepseudointr __P((struct le_softc *, void *));
    113      1.1       leo static int le_vme_match __P((struct device *, struct cfdata *, void *));
    114      1.1       leo static void le_vme_attach __P((struct device *, struct device *, void *));
    115      1.1       leo static int probe_addresses __P((bus_space_tag_t *, bus_space_tag_t *,
    116      1.1       leo 				bus_space_handle_t *, bus_space_handle_t *));
    117      1.6  drochner static void riebl_skip_reserved_area __P((struct lance_softc *));
    118      1.7       leo static int nm93c06_read __P((bus_space_tag_t, bus_space_handle_t, int));
    119      1.9       leo static int bvme410_probe __P((bus_space_tag_t, bus_space_handle_t));
    120      1.7       leo static int bvme410_mem_size __P((bus_space_tag_t, u_long));
    121      1.7       leo static void bvme410_copytobuf __P((struct lance_softc *, void *, int, int));
    122      1.7       leo static void bvme410_zerobuf __P((struct lance_softc *, int, int));
    123      1.1       leo 
    124      1.1       leo struct cfattach le_vme_ca = {
    125      1.1       leo 	sizeof(struct le_softc), le_vme_match, le_vme_attach
    126      1.1       leo };
    127      1.1       leo 
    128      1.6  drochner #if defined(_KERNEL) && !defined(_LKM)
    129      1.6  drochner #include "opt_ddb.h"
    130      1.6  drochner #endif
    131      1.6  drochner 
    132      1.6  drochner #ifdef DDB
    133      1.6  drochner #define	integrate
    134      1.6  drochner #define hide
    135      1.6  drochner #else
    136      1.6  drochner #define	integrate	static __inline
    137      1.6  drochner #define hide		static
    138      1.6  drochner #endif
    139      1.6  drochner 
    140      1.6  drochner hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    141      1.6  drochner hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    142      1.1       leo 
    143      1.1       leo hide void
    144      1.1       leo lewrcsr(sc, port, val)
    145      1.6  drochner 	struct lance_softc	*sc;
    146      1.1       leo 	u_int16_t		port, val;
    147      1.1       leo {
    148      1.1       leo 	struct le_softc		*lesc = (struct le_softc *)sc;
    149      1.1       leo 	int			s;
    150      1.1       leo 
    151      1.1       leo 	s = splhigh();
    152      1.1       leo 	bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RAP, port);
    153      1.1       leo 	bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RDP, val);
    154      1.1       leo 	splx(s);
    155      1.1       leo }
    156      1.1       leo 
    157      1.1       leo hide u_int16_t
    158      1.1       leo lerdcsr(sc, port)
    159      1.6  drochner 	struct lance_softc	*sc;
    160      1.1       leo 	u_int16_t		port;
    161      1.1       leo {
    162      1.1       leo 	struct le_softc		*lesc = (struct le_softc *)sc;
    163      1.1       leo 	u_int16_t		val;
    164      1.1       leo 	int			s;
    165      1.1       leo 
    166      1.1       leo 	s = splhigh();
    167      1.1       leo 	bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RAP, port);
    168      1.1       leo 	val = bus_space_read_2(lesc->sc_iot, lesc->sc_ioh, LER_RDP);
    169      1.1       leo 	splx(s);
    170      1.1       leo 
    171      1.1       leo 	return (val);
    172      1.1       leo }
    173      1.1       leo 
    174      1.1       leo static int
    175      1.1       leo le_vme_match(parent, cfp, aux)
    176      1.1       leo 	struct device	*parent;
    177      1.1       leo 	struct cfdata	*cfp;
    178      1.1       leo 	void		*aux;
    179      1.1       leo {
    180      1.1       leo 	struct vme_attach_args	*va = aux;
    181      1.1       leo 	int			i;
    182      1.1       leo 	bus_space_tag_t		iot;
    183      1.1       leo 	bus_space_tag_t		memt;
    184      1.1       leo 	bus_space_handle_t	ioh;
    185      1.1       leo 	bus_space_handle_t	memh;
    186      1.1       leo 
    187      1.1       leo 	iot  = va->va_iot;
    188      1.1       leo 	memt = va->va_memt;
    189      1.1       leo 
    190      1.1       leo 	for (i = 0; i < NLESTD; i++) {
    191      1.1       leo 		struct le_addresses	*le_ap = &lestd[i];
    192      1.1       leo 		int			found  = 0;
    193      1.1       leo 
    194      1.1       leo 		if ((va->va_iobase != IOBASEUNK)
    195      1.1       leo 		     && (va->va_iobase != le_ap->reg_addr))
    196      1.1       leo 			continue;
    197      1.1       leo 
    198      1.1       leo 		if ((va->va_maddr != MADDRUNK)
    199      1.1       leo 		     && (va->va_maddr != le_ap->mem_addr))
    200      1.1       leo 			continue;
    201      1.1       leo 
    202      1.1       leo 		if ((le_ap->irq != IRQUNK) && (va->va_irq != le_ap->irq))
    203      1.1       leo 			continue;
    204      1.1       leo 
    205      1.7       leo 		if (bus_space_map(iot, le_ap->reg_addr, le_ap->reg_size, 0, &ioh)) {
    206      1.1       leo 			printf("leprobe: cannot map io-area\n");
    207      1.1       leo 			return (0);
    208      1.1       leo 		}
    209      1.7       leo 		if (le_ap->mem_size == VMECF_MEMSIZ_DEFAULT) {
    210      1.9       leo 			if (bvme410_probe(iot, ioh)) {
    211      1.7       leo 				bus_space_write_2(iot, ioh, BVME410_BAR, 0x1); /* XXX */
    212      1.7       leo 				le_ap->mem_size = bvme410_mem_size(memt, le_ap->mem_addr);
    213      1.7       leo 			}
    214      1.7       leo 		}
    215      1.7       leo 		if (le_ap->mem_size == VMECF_MEMSIZ_DEFAULT) {
    216      1.7       leo 			bus_space_unmap(iot, (caddr_t)le_ap->reg_addr, le_ap->reg_size);
    217      1.7       leo 			continue;
    218      1.7       leo 		}
    219      1.7       leo 
    220      1.7       leo 		if (bus_space_map(memt, le_ap->mem_addr, le_ap->mem_size, 0, &memh)) {
    221      1.7       leo 			bus_space_unmap(iot, (caddr_t)le_ap->reg_addr, le_ap->reg_size);
    222      1.1       leo 			printf("leprobe: cannot map memory-area\n");
    223      1.1       leo 			return (0);
    224      1.1       leo 		}
    225      1.1       leo 		found = probe_addresses(&iot, &memt, &ioh, &memh);
    226      1.7       leo 		bus_space_unmap(iot, (caddr_t)le_ap->reg_addr, le_ap->reg_size);
    227      1.7       leo 		bus_space_unmap(memt, (caddr_t)le_ap->mem_addr, le_ap->mem_size);
    228      1.1       leo 
    229      1.1       leo 		if (found) {
    230      1.1       leo 			va->va_iobase = le_ap->reg_addr;
    231      1.7       leo 			va->va_iosize = le_ap->reg_size;
    232      1.1       leo 			va->va_maddr  = le_ap->mem_addr;
    233      1.7       leo 			va->va_msize  = le_ap->mem_size;
    234      1.8       leo 			va->va_aux    = le_ap;
    235      1.1       leo 			if (va->va_irq == IRQUNK)
    236      1.1       leo 				va->va_irq = le_ap->irq;
    237      1.1       leo 			return 1;
    238      1.1       leo 		}
    239      1.1       leo     }
    240      1.1       leo     return (0);
    241      1.1       leo }
    242      1.1       leo 
    243      1.1       leo static int
    244      1.1       leo probe_addresses(iot, memt, ioh, memh)
    245      1.1       leo bus_space_tag_t		*iot;
    246      1.1       leo bus_space_tag_t		*memt;
    247      1.1       leo bus_space_handle_t	*ioh;
    248      1.1       leo bus_space_handle_t	*memh;
    249      1.1       leo {
    250      1.1       leo 	/*
    251      1.1       leo 	 * Test accesibility of register and memory area
    252      1.1       leo 	 */
    253      1.1       leo 	if(!bus_space_peek_2(*iot, *ioh, LER_RDP))
    254      1.1       leo 		return 0;
    255      1.1       leo 	if(!bus_space_peek_1(*memt, *memh, 0))
    256      1.1       leo 		return 0;
    257      1.1       leo 
    258      1.1       leo 	/*
    259      1.1       leo 	 * Test for writable memory
    260      1.1       leo 	 */
    261      1.1       leo 	bus_space_write_2(*memt, *memh, 0, 0xa5a5);
    262      1.1       leo 	if (bus_space_read_2(*memt, *memh, 0) != 0xa5a5)
    263      1.1       leo 		return 0;
    264      1.1       leo 
    265      1.1       leo 	/*
    266      1.1       leo 	 * Test writability of selector port.
    267      1.1       leo 	 */
    268      1.1       leo 	bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR1);
    269      1.1       leo 	if (bus_space_read_2(*iot, *ioh, LER_RAP) != LE_CSR1)
    270      1.1       leo 		return 0;
    271      1.1       leo 
    272      1.1       leo 	/*
    273      1.1       leo 	 * Do a small register test
    274      1.1       leo 	 */
    275      1.1       leo 	bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR0);
    276      1.1       leo 	bus_space_write_2(*iot, *ioh, LER_RDP, LE_C0_INIT | LE_C0_STOP);
    277      1.1       leo 	if (bus_space_read_2(*iot, *ioh, LER_RDP) != LE_C0_STOP)
    278      1.1       leo 		return 0;
    279      1.1       leo 
    280      1.1       leo 	bus_space_write_2(*iot, *ioh, LER_RDP, LE_C0_STOP);
    281      1.1       leo 	if (bus_space_read_2(*iot, *ioh, LER_RDP) != LE_C0_STOP)
    282      1.1       leo 		return 0;
    283      1.1       leo 
    284      1.1       leo 	return 1;
    285      1.1       leo }
    286      1.1       leo 
    287      1.1       leo /*
    288      1.1       leo  * Interrupt mess. Because the card's interrupt is hardwired to either
    289      1.1       leo  * ipl5 or ipl3 (mostly on ipl5) and raising splnet to spl5() just won't do
    290      1.1       leo  * (it kills the serial at the least), we use a 2-level interrupt sceme. The
    291      1.1       leo  * card interrupt is routed to 'le_intr'. If the previous ipl was below
    292      1.1       leo  * splnet, just call the mi-function. If not, save the interrupt status,
    293      1.1       leo  * turn off card interrupts (the card is *very* persistent) and arrange
    294      1.1       leo  * for a softint 'callback' through 'lepseudointr'.
    295      1.1       leo  */
    296      1.1       leo static int
    297      1.1       leo le_intr(lesc, sr)
    298      1.1       leo 	struct le_softc	*lesc;
    299      1.1       leo 	int		 sr;
    300      1.1       leo {
    301      1.6  drochner 	struct lance_softc	*sc = &lesc->sc_am7990.lsc;
    302      1.1       leo 	u_int16_t		csr0;
    303      1.1       leo 
    304  1.9.2.1       leo 	if ((sr & PSL_IPL) < (IPL_NET & PSL_IPL))
    305      1.1       leo 		am7990_intr(sc);
    306      1.1       leo 	else {
    307      1.1       leo 		sc->sc_saved_csr0 = csr0 = lerdcsr(sc, LE_CSR0);
    308      1.1       leo 		lewrcsr(sc, LE_CSR0, csr0 & ~LE_C0_INEA);
    309      1.1       leo 		add_sicallback((si_farg)lepseudointr, lesc, sc);
    310      1.1       leo 	}
    311      1.1       leo 	return 1;
    312      1.1       leo }
    313      1.1       leo 
    314      1.1       leo 
    315      1.1       leo static void
    316      1.1       leo lepseudointr(lesc, sc)
    317      1.1       leo struct le_softc	*lesc;
    318      1.1       leo void		*sc;
    319      1.1       leo {
    320      1.1       leo 	int	s;
    321      1.1       leo 
    322      1.1       leo 	s = splx(lesc->sc_splval);
    323      1.1       leo 	am7990_intr(sc);
    324      1.1       leo 	splx(s);
    325      1.1       leo }
    326      1.1       leo 
    327      1.1       leo static void
    328      1.1       leo le_vme_attach(parent, self, aux)
    329      1.1       leo 	struct device *parent, *self;
    330      1.1       leo 	void *aux;
    331      1.1       leo {
    332      1.1       leo 	struct le_softc		*lesc = (struct le_softc *)self;
    333      1.6  drochner 	struct lance_softc	*sc = &lesc->sc_am7990.lsc;
    334      1.1       leo 	struct vme_attach_args	*va = aux;
    335      1.1       leo 	bus_space_handle_t	ioh;
    336      1.1       leo 	bus_space_handle_t	memh;
    337      1.8       leo 	struct le_addresses	*le_ap;
    338      1.1       leo 	int			i;
    339      1.1       leo 
    340      1.1       leo 	printf("\n%s: ", sc->sc_dev.dv_xname);
    341      1.1       leo 
    342      1.1       leo 	if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh))
    343      1.1       leo 		panic("leattach: cannot map io-area\n");
    344      1.1       leo 	if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize, 0, &memh))
    345      1.1       leo 		panic("leattach: cannot map mem-area\n");
    346      1.1       leo 
    347      1.1       leo 	lesc->sc_iot    = va->va_iot;
    348      1.1       leo 	lesc->sc_ioh    = ioh;
    349      1.1       leo 	lesc->sc_memt   = va->va_memt;
    350      1.1       leo 	lesc->sc_memh   = memh;
    351      1.1       leo 	lesc->sc_splval = (va->va_irq << 8) | PSL_S; /* XXX */
    352      1.8       leo 	le_ap           = (struct le_addresses *)va->va_aux;
    353      1.1       leo 
    354      1.1       leo 	/*
    355      1.1       leo 	 * Go on to find board type
    356      1.1       leo 	 */
    357      1.8       leo 	if ((le_ap->type_hint & LE_PAM)
    358      1.8       leo 		&& bus_space_peek_1(va->va_iot, ioh, LER_EEPROM)) {
    359      1.1       leo 		printf("PAM card");
    360      1.1       leo 		lesc->sc_type = LE_PAM;
    361      1.1       leo 		bus_space_read_1(va->va_iot, ioh, LER_MEME);
    362      1.1       leo 	}
    363      1.8       leo 	else if((le_ap->type_hint & LE_BVME410)
    364      1.9       leo 		&& bvme410_probe(va->va_iot, ioh)) {
    365      1.7       leo 		printf("BVME410");
    366      1.7       leo 		lesc->sc_type = LE_BVME410;
    367      1.7       leo 	}
    368      1.8       leo 	else if (le_ap->type_hint & (LE_NEW_RIEBL|LE_OLD_RIEBL)) {
    369      1.1       leo 		printf("Riebl card");
    370      1.1       leo 		if(bus_space_read_4(va->va_memt, memh, RIEBL_MAGIC_ADDR)
    371      1.1       leo 								== RIEBL_MAGIC)
    372      1.1       leo 			lesc->sc_type = LE_NEW_RIEBL;
    373      1.1       leo 		else {
    374      1.1       leo 			printf("(without battery) ");
    375      1.1       leo 			lesc->sc_type = LE_OLD_RIEBL;
    376      1.1       leo 		}
    377      1.1       leo 	}
    378      1.8       leo 	else printf("le_vme_attach: Unsupported card!");
    379      1.1       leo 
    380      1.7       leo 	switch (lesc->sc_type) {
    381      1.7       leo 	    case LE_BVME410:
    382      1.7       leo 		sc->sc_copytodesc   = bvme410_copytobuf;
    383      1.7       leo 		sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    384      1.7       leo 		sc->sc_copytobuf    = bvme410_copytobuf;
    385      1.7       leo 		sc->sc_copyfrombuf  = lance_copyfrombuf_contig;
    386      1.7       leo 		sc->sc_zerobuf      = bvme410_zerobuf;
    387      1.7       leo 		break;
    388      1.7       leo 	    default:
    389      1.7       leo 		sc->sc_copytodesc   = lance_copytobuf_contig;
    390      1.7       leo 		sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    391      1.7       leo 		sc->sc_copytobuf    = lance_copytobuf_contig;
    392      1.7       leo 		sc->sc_copyfrombuf  = lance_copyfrombuf_contig;
    393      1.7       leo 		sc->sc_zerobuf      = lance_zerobuf_contig;
    394      1.7       leo 		break;
    395      1.7       leo 	}
    396      1.1       leo 
    397      1.1       leo 	sc->sc_rdcsr   = lerdcsr;
    398      1.1       leo 	sc->sc_wrcsr   = lewrcsr;
    399      1.1       leo 	sc->sc_hwinit  = NULL;
    400      1.1       leo 	sc->sc_conf3   = LE_C3_BSWP;
    401      1.1       leo 	sc->sc_addr    = 0;
    402      1.1       leo 	sc->sc_memsize = va->va_msize;
    403      1.1       leo 	sc->sc_mem     = (void *)memh; /* XXX */
    404      1.1       leo 
    405      1.1       leo 	/*
    406      1.1       leo 	 * Get MAC address
    407      1.1       leo 	 */
    408      1.1       leo 	switch (lesc->sc_type) {
    409      1.1       leo 	    case LE_OLD_RIEBL:
    410      1.4       leo 		bcopy(riebl_def_mac, sc->sc_enaddr,
    411      1.4       leo 					sizeof(sc->sc_enaddr));
    412      1.1       leo 		break;
    413      1.1       leo 	    case LE_NEW_RIEBL:
    414      1.4       leo 		for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    415      1.4       leo 		    sc->sc_enaddr[i] =
    416      1.1       leo 			bus_space_read_1(va->va_memt, memh, i + RIEBL_MAC_ADDR);
    417      1.1       leo 			break;
    418      1.1       leo 	    case LE_PAM:
    419      1.1       leo 		i = bus_space_read_1(va->va_iot, ioh, LER_EEPROM);
    420      1.4       leo 		for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
    421      1.4       leo 		    sc->sc_enaddr[i] =
    422      1.1       leo 			(bus_space_read_2(va->va_memt, memh, 2 * i) << 4) |
    423      1.1       leo 			(bus_space_read_2(va->va_memt, memh, 2 * i + 1) & 0xf);
    424      1.1       leo 		}
    425      1.1       leo 		i = bus_space_read_1(va->va_iot, ioh, LER_MEME);
    426      1.1       leo 		break;
    427      1.7       leo 	    case LE_BVME410:
    428      1.7       leo 		for (i = 0; i < (sizeof(sc->sc_enaddr) >> 1); i++) {
    429      1.7       leo 		    u_int16_t tmp;
    430      1.7       leo 
    431      1.7       leo 		    tmp = nm93c06_read(va->va_iot, ioh, i);
    432      1.7       leo 		    sc->sc_enaddr[2 * i] = (tmp >> 8) & 0xff;
    433      1.7       leo 		    sc->sc_enaddr[2 * i + 1] = tmp & 0xff;
    434      1.7       leo 		}
    435      1.7       leo 		bus_space_write_2(va->va_iot, ioh, BVME410_BAR, 0x1); /* XXX */
    436      1.1       leo 	}
    437      1.1       leo 
    438      1.6  drochner 	am7990_config(&lesc->sc_am7990);
    439      1.1       leo 
    440      1.1       leo 	if ((lesc->sc_type == LE_OLD_RIEBL) || (lesc->sc_type == LE_NEW_RIEBL))
    441      1.1       leo 		riebl_skip_reserved_area(sc);
    442      1.1       leo 
    443      1.1       leo 	/*
    444      1.1       leo 	 * XXX: We always use uservector 64....
    445      1.1       leo 	 */
    446      1.1       leo 	if ((lesc->sc_intr = intr_establish(64, USER_VEC, 0,
    447      1.1       leo 				(hw_ifun_t)le_intr, lesc)) == NULL) {
    448      1.1       leo 		printf("le_vme_attach: Can't establish interrupt\n");
    449      1.1       leo 		return;
    450      1.1       leo 	}
    451      1.1       leo 
    452      1.1       leo 	/*
    453      1.1       leo 	 * Notify the card of the vector
    454      1.1       leo 	 */
    455      1.1       leo 	switch (lesc->sc_type) {
    456      1.1       leo 		case LE_OLD_RIEBL:
    457      1.1       leo 		case LE_NEW_RIEBL:
    458      1.1       leo 			bus_space_write_2(va->va_memt, memh, RIEBL_IVEC_ADDR,
    459      1.1       leo 								64 + 64);
    460      1.1       leo 			break;
    461      1.1       leo 		case LE_PAM:
    462      1.1       leo 			bus_space_write_1(va->va_iot, ioh, LER_IVEC, 64 + 64);
    463      1.1       leo 			break;
    464      1.7       leo 		case LE_BVME410:
    465      1.7       leo 			bus_space_write_2(va->va_iot, ioh, BVME410_IVEC, 64 + 64);
    466      1.7       leo 			break;
    467      1.1       leo 	}
    468      1.1       leo 
    469      1.1       leo 	/*
    470      1.1       leo 	 * Unmask the VME-interrupt we're on
    471      1.1       leo 	 */
    472      1.1       leo 	if (machineid & ATARI_TT)
    473      1.1       leo 		SCU->vme_mask |= 1 << va->va_irq;
    474      1.1       leo }
    475      1.1       leo 
    476      1.1       leo /*
    477      1.1       leo  * True if 'addr' containe within [start,len]
    478      1.1       leo  */
    479      1.1       leo #define WITHIN(start, len, addr)	\
    480      1.1       leo 		((addr >= start) && ((addr) <= ((start) + (len))))
    481      1.1       leo static void
    482      1.1       leo riebl_skip_reserved_area(sc)
    483      1.6  drochner 	struct lance_softc	*sc;
    484      1.1       leo {
    485      1.1       leo 	int	offset = 0;
    486      1.1       leo 	int	i;
    487      1.1       leo 
    488      1.1       leo 	for(i = 0; i < sc->sc_nrbuf; i++) {
    489      1.1       leo 		if (WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_START)
    490      1.1       leo 		    || WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_END)) {
    491      1.1       leo 			offset = RIEBL_RES_END - sc->sc_rbufaddr[i];
    492      1.1       leo 		}
    493      1.1       leo 		sc->sc_rbufaddr[i] += offset;
    494      1.1       leo 	}
    495      1.1       leo 
    496      1.1       leo 	for(i = 0; i < sc->sc_ntbuf; i++) {
    497      1.1       leo 		if (WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_START)
    498      1.1       leo 		    || WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_END)) {
    499      1.1       leo 			offset = RIEBL_RES_END - sc->sc_tbufaddr[i];
    500      1.1       leo 		}
    501      1.1       leo 		sc->sc_tbufaddr[i] += offset;
    502      1.1       leo 	}
    503      1.1       leo }
    504      1.7       leo 
    505      1.7       leo static int
    506      1.7       leo nm93c06_read(iot, ioh, nm93c06reg)
    507      1.7       leo 	bus_space_tag_t iot;
    508      1.7       leo 	bus_space_handle_t ioh;
    509      1.7       leo 	int nm93c06reg;
    510      1.7       leo {
    511      1.7       leo 	int bar;
    512      1.7       leo 	int shift;
    513      1.7       leo 	int bits = 0x180 | (nm93c06reg & 0xf);
    514      1.7       leo 	int data = 0;
    515      1.7       leo 
    516      1.7       leo 	bar = 1<<BVME410_CS_SHIFT;
    517      1.7       leo 	bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    518      1.7       leo 	delay(1); /* tCSS = 1 us */
    519      1.7       leo 	for (shift = 9; shift >= 0; shift--) {
    520      1.7       leo 		if (((bits >> shift) & 1) == 1)
    521      1.7       leo 			bar |= 1<<BVME410_DIN_SHIFT;
    522      1.7       leo 		else
    523      1.7       leo 			bar &= ~(1<<BVME410_DIN_SHIFT);
    524      1.7       leo 		bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    525      1.7       leo 		delay(1); /* tDIS = 0.4 us */
    526      1.7       leo 		bar |= 1<<BVME410_CLK_SHIFT;
    527      1.7       leo 		bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    528      1.7       leo 		delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */
    529      1.7       leo 		bar &= ~(1<<BVME410_CLK_SHIFT);
    530      1.7       leo 		bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    531      1.7       leo 		delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */
    532      1.7       leo 	}
    533      1.7       leo 	bar &= ~(1<<BVME410_DIN_SHIFT);
    534      1.7       leo 	for (shift = 15; shift >= 0; shift--) {
    535      1.7       leo 		delay(1); /* tDIS = 100 ns, BVM manual says 0.4 us */
    536      1.7       leo 		bar |= 1<<BVME410_CLK_SHIFT;
    537      1.7       leo 		bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    538      1.7       leo 		delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */
    539      1.7       leo 		data |= (bus_space_read_2(iot, ioh, BVME410_BAR) & 1) << shift;
    540      1.7       leo 		bar &= ~(1<<BVME410_CLK_SHIFT);
    541      1.7       leo 		bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    542      1.7       leo 		delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */
    543      1.7       leo 	}
    544      1.7       leo 	bar &= ~(1<<BVME410_CS_SHIFT);
    545      1.7       leo 	bus_space_write_2(iot, ioh, BVME410_BAR, bar);
    546      1.7       leo 	delay(1); /* tCS = 1 us */
    547      1.7       leo 	return data;
    548      1.7       leo }
    549      1.7       leo 
    550      1.7       leo static int
    551      1.9       leo bvme410_probe(iot, ioh)
    552      1.9       leo 	bus_space_tag_t iot;
    553      1.9       leo 	bus_space_handle_t ioh;
    554      1.9       leo {
    555      1.9       leo 	if (!bus_space_peek_2(iot, ioh, BVME410_IVEC))
    556      1.9       leo 		return 0;
    557      1.9       leo 
    558      1.9       leo 	bus_space_write_2(iot, ioh, BVME410_IVEC, 0x0000);
    559      1.9       leo 	if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xff00)
    560      1.9       leo 		return 0;
    561      1.9       leo 
    562      1.9       leo 	bus_space_write_2(iot, ioh, BVME410_IVEC, 0xffff);
    563      1.9       leo 	if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xffff)
    564      1.9       leo 		return 0;
    565      1.9       leo 
    566      1.9       leo 	bus_space_write_2(iot, ioh, BVME410_IVEC, 0xa5a5);
    567      1.9       leo 	if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xffa5)
    568      1.9       leo 		return 0;
    569      1.9       leo 
    570      1.9       leo 	return 1;
    571      1.9       leo }
    572      1.9       leo 
    573      1.9       leo static int
    574      1.7       leo bvme410_mem_size(memt, mem_addr)
    575      1.7       leo 	bus_space_tag_t memt;
    576      1.7       leo 	u_long mem_addr;
    577      1.7       leo {
    578      1.7       leo 	bus_space_handle_t memh;
    579      1.7       leo 	int r;
    580      1.7       leo 
    581      1.7       leo 	if (bus_space_map(memt, mem_addr, 256*1024, 0, &memh))
    582      1.7       leo 		return VMECF_MEMSIZ_DEFAULT;
    583      1.7       leo 	if (!bus_space_peek_1(memt, memh, 0)) {
    584      1.7       leo 		bus_space_unmap(memt, (caddr_t)mem_addr, 256*1024);
    585      1.7       leo 		return VMECF_MEMSIZ_DEFAULT;
    586      1.7       leo 	}
    587      1.7       leo 	bus_space_write_1(memt, memh, 0, 128);
    588      1.7       leo 	bus_space_write_1(memt, memh, 64*1024, 32);
    589      1.7       leo 	bus_space_write_1(memt, memh, 32*1024, 8);
    590      1.7       leo 	r = (int)(bus_space_read_1(memt, memh, 0) * 2048);
    591      1.7       leo 	bus_space_unmap(memt, (caddr_t)mem_addr, 256*1024);
    592      1.7       leo 	return r;
    593      1.7       leo }
    594      1.7       leo 
    595      1.7       leo /*
    596      1.7       leo  * Need to be careful when writing to the bvme410 dual port memory.
    597      1.7       leo  * Continue writing each byte until it reads back the same.
    598      1.7       leo  */
    599      1.7       leo 
    600      1.7       leo static void
    601      1.7       leo bvme410_copytobuf(sc, from, boff, len)
    602      1.7       leo 	struct lance_softc *sc;
    603      1.7       leo 	void *from;
    604      1.7       leo 	int boff, len;
    605      1.7       leo {
    606      1.7       leo 	volatile char *buf = (volatile char *) sc->sc_mem;
    607      1.7       leo 	char *f = (char *) from;
    608      1.7       leo 
    609      1.7       leo 	for (buf += boff; len; buf++,f++,len--)
    610      1.9       leo 		do {
    611      1.9       leo  			*buf = *f;
    612      1.9       leo 		} while (*buf != *f);
    613      1.7       leo }
    614      1.7       leo 
    615      1.7       leo static void
    616      1.7       leo bvme410_zerobuf(sc, boff, len)
    617      1.7       leo 	struct lance_softc *sc;
    618      1.7       leo 	int boff, len;
    619      1.7       leo {
    620      1.7       leo 	volatile char *buf = (volatile char *)sc->sc_mem;
    621      1.7       leo 
    622      1.7       leo 	for (buf += boff; len; buf++,len--)
    623      1.9       leo 		do {
    624      1.9       leo  			*buf = '\0';
    625      1.9       leo 		} while (*buf != '\0');
    626      1.7       leo }
    627      1.7       leo 
    628