Home | History | Annotate | Line # | Download | only in vme
if_ie_vme.c revision 1.1
      1  1.1  pk /*	$NetBSD: if_ie_vme.c,v 1.1 1997/11/01 22:56:21 pk Exp $	*/
      2  1.1  pk 
      3  1.1  pk /*-
      4  1.1  pk  * Copyright (c) 1995 Charles D. Cranor
      5  1.1  pk  * All rights reserved.
      6  1.1  pk  *
      7  1.1  pk  * Redistribution and use in source and binary forms, with or without
      8  1.1  pk  * modification, are permitted provided that the following conditions
      9  1.1  pk  * are met:
     10  1.1  pk  * 1. Redistributions of source code must retain the above copyright
     11  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     12  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  pk  *    documentation and/or other materials provided with the distribution.
     15  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     16  1.1  pk  *    must display the following acknowledgement:
     17  1.1  pk  *      This product includes software developed by Charles D. Cranor.
     18  1.1  pk  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  pk  *    derived from this software without specific prior written permission.
     20  1.1  pk  *
     21  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  pk  */
     32  1.1  pk 
     33  1.1  pk /*
     34  1.1  pk  * Converted to SUN ie driver by Charles D. Cranor,
     35  1.1  pk  *		October 1994, January 1995.
     36  1.1  pk  */
     37  1.1  pk 
     38  1.1  pk /*
     39  1.1  pk  * The i82586 is a very painful chip, found in sun3's, sun-4/100's
     40  1.1  pk  * sun-4/200's, and VME based suns.  The byte order is all wrong for a
     41  1.1  pk  * SUN, making life difficult.  Programming this chip is mostly the same,
     42  1.1  pk  * but certain details differ from system to system.  This driver is
     43  1.1  pk  * written so that different "ie" interfaces can be controled by the same
     44  1.1  pk  * driver.
     45  1.1  pk  */
     46  1.1  pk 
     47  1.1  pk /*
     48  1.1  pk  * programming notes:
     49  1.1  pk  *
     50  1.1  pk  * the ie chip operates in a 24 bit address space.
     51  1.1  pk  *
     52  1.1  pk  * most ie interfaces appear to be divided into two parts:
     53  1.1  pk  *	 - generic 586 stuff
     54  1.1  pk  *	 - board specific
     55  1.1  pk  *
     56  1.1  pk  * generic:
     57  1.1  pk  *	the generic stuff of the ie chip is all done with data structures
     58  1.1  pk  * 	that live in the chip's memory address space.   the chip expects
     59  1.1  pk  * 	its main data structure (the sys conf ptr -- SCP) to be at a fixed
     60  1.1  pk  * 	address in its 24 bit space: 0xfffff4
     61  1.1  pk  *
     62  1.1  pk  *      the SCP points to another structure called the ISCP.
     63  1.1  pk  *      the ISCP points to another structure called the SCB.
     64  1.1  pk  * 	the SCB has a status field, a linked list of "commands", and
     65  1.1  pk  * 	a linked list of "receive buffers".   these are data structures that
     66  1.1  pk  * 	live in memory, not registers.
     67  1.1  pk  *
     68  1.1  pk  * board:
     69  1.1  pk  * 	to get the chip to do anything, you first put a command in the
     70  1.1  pk  * 	command data structure list.   then you have to signal "attention"
     71  1.1  pk  * 	to the chip to get it to look at the command.   how you
     72  1.1  pk  * 	signal attention depends on what board you have... on PC's
     73  1.1  pk  * 	there is an i/o port number to do this, on sun's there is a
     74  1.1  pk  * 	register bit you toggle.
     75  1.1  pk  *
     76  1.1  pk  * 	to get data from the chip you program it to interrupt...
     77  1.1  pk  *
     78  1.1  pk  *
     79  1.1  pk  * sun issues:
     80  1.1  pk  *
     81  1.1  pk  *      there are 3 kinds of sun "ie" interfaces:
     82  1.1  pk  *        1 - a VME/multibus card
     83  1.1  pk  *        2 - an on-board interface (sun3's, sun-4/100's, and sun-4/200's)
     84  1.1  pk  *        3 - another VME board called the 3E
     85  1.1  pk  *
     86  1.1  pk  * 	the VME boards lives in vme16 space.   only 16 and 8 bit accesses
     87  1.1  pk  * 	are allowed, so functions that copy data must be aware of this.
     88  1.1  pk  *
     89  1.1  pk  * 	the chip is an intel chip.  this means that the byte order
     90  1.1  pk  * 	on all the "short"s in the chip's data structures is wrong.
     91  1.1  pk  * 	so, constants described in the intel docs are swapped for the sun.
     92  1.1  pk  * 	that means that any buffer pointers you give the chip must be
     93  1.1  pk  * 	swapped to intel format.   yuck.
     94  1.1  pk  *
     95  1.1  pk  *   VME/multibus interface:
     96  1.1  pk  * 	for the multibus interface the board ignores the top 4 bits
     97  1.1  pk  * 	of the chip address.   the multibus interface seems to have its
     98  1.1  pk  * 	own MMU like page map (without protections or valid bits, etc).
     99  1.1  pk  * 	there are 256 pages of physical memory on the board (each page
    100  1.1  pk  * 	is 1024 bytes).   there are 1024 slots in the page map.  so,
    101  1.1  pk  * 	a 1024 byte page takes up 10 bits of address for the offset,
    102  1.1  pk  * 	and if there are 1024 slots in the page that is another 10 bits
    103  1.1  pk  * 	of the address.   that makes a 20 bit address, and as stated
    104  1.1  pk  * 	earlier the board ignores the top 4 bits, so that accounts
    105  1.1  pk  * 	for all 24 bits of address.
    106  1.1  pk  *
    107  1.1  pk  * 	note that the last entry of the page map maps the top of the
    108  1.1  pk  * 	24 bit address space and that the SCP is supposed to be at
    109  1.1  pk  * 	0xfffff4 (taking into account allignment).   so,
    110  1.1  pk  *	for multibus, that entry in the page map has to be used for the SCP.
    111  1.1  pk  *
    112  1.1  pk  * 	the page map effects BOTH how the ie chip sees the
    113  1.1  pk  * 	memory, and how the host sees it.
    114  1.1  pk  *
    115  1.1  pk  * 	the page map is part of the "register" area of the board
    116  1.1  pk  *
    117  1.1  pk  *   on-board interface:
    118  1.1  pk  *
    119  1.1  pk  *	<fill in useful info later>
    120  1.1  pk  *
    121  1.1  pk  *
    122  1.1  pk  *   VME3E interface:
    123  1.1  pk  *
    124  1.1  pk  *	<fill in useful info later>
    125  1.1  pk  *
    126  1.1  pk  */
    127  1.1  pk 
    128  1.1  pk #include <sys/param.h>
    129  1.1  pk #include <sys/systm.h>
    130  1.1  pk #include <sys/errno.h>
    131  1.1  pk #include <sys/device.h>
    132  1.1  pk #include <sys/protosw.h>
    133  1.1  pk #include <sys/socket.h>
    134  1.1  pk 
    135  1.1  pk #include <net/if.h>
    136  1.1  pk #include <net/if_types.h>
    137  1.1  pk #include <net/if_dl.h>
    138  1.1  pk #include <net/if_ether.h>
    139  1.1  pk 
    140  1.1  pk #include <vm/vm.h>
    141  1.1  pk 
    142  1.1  pk #include <machine/bus.h>
    143  1.1  pk #include <dev/vme/vmevar.h>
    144  1.1  pk 
    145  1.1  pk #include <dev/ic/i82586reg.h>
    146  1.1  pk #include <dev/ic/i82586var.h>
    147  1.1  pk 
    148  1.1  pk 
    149  1.1  pk /*
    150  1.1  pk  * VME/multibus definitions
    151  1.1  pk  */
    152  1.1  pk #define IEVME_PAGESIZE 1024	/* bytes */
    153  1.1  pk #define IEVME_PAGSHIFT 10	/* bits */
    154  1.1  pk #define IEVME_NPAGES   256	/* number of pages on chip */
    155  1.1  pk #define IEVME_MAPSZ    1024	/* number of entries in the map */
    156  1.1  pk 
    157  1.1  pk /*
    158  1.1  pk  * PTE for the page map
    159  1.1  pk  */
    160  1.1  pk #define IEVME_SBORDR 0x8000	/* sun byte order */
    161  1.1  pk #define IEVME_IBORDR 0x0000	/* intel byte ordr */
    162  1.1  pk 
    163  1.1  pk #define IEVME_P2MEM  0x2000	/* memory is on P2 */
    164  1.1  pk #define IEVME_OBMEM  0x0000	/* memory is on board */
    165  1.1  pk 
    166  1.1  pk #define IEVME_PGMASK 0x0fff	/* gives the physical page frame number */
    167  1.1  pk 
    168  1.1  pk struct ievme {
    169  1.1  pk 	u_int16_t	pgmap[IEVME_MAPSZ];
    170  1.1  pk 	u_int16_t	xxx[32];	/* prom */
    171  1.1  pk 	u_int16_t	status;		/* see below for bits */
    172  1.1  pk 	u_int16_t	xxx2;		/* filler */
    173  1.1  pk 	u_int16_t	pectrl;		/* parity control (see below) */
    174  1.1  pk 	u_int16_t	peaddr;		/* low 16 bits of address */
    175  1.1  pk };
    176  1.1  pk 
    177  1.1  pk /*
    178  1.1  pk  * status bits
    179  1.1  pk  */
    180  1.1  pk #define IEVME_RESET 0x8000	/* reset board */
    181  1.1  pk #define IEVME_ONAIR 0x4000	/* go out of loopback 'on-air' */
    182  1.1  pk #define IEVME_ATTEN 0x2000	/* attention */
    183  1.1  pk #define IEVME_IENAB 0x1000	/* interrupt enable */
    184  1.1  pk #define IEVME_PEINT 0x0800	/* parity error interrupt enable */
    185  1.1  pk #define IEVME_PERR  0x0200	/* parity error flag */
    186  1.1  pk #define IEVME_INT   0x0100	/* interrupt flag */
    187  1.1  pk #define IEVME_P2EN  0x0020	/* enable p2 bus */
    188  1.1  pk #define IEVME_256K  0x0010	/* 256kb rams */
    189  1.1  pk #define IEVME_HADDR 0x000f	/* mask for bits 17-20 of address */
    190  1.1  pk 
    191  1.1  pk /*
    192  1.1  pk  * parity control
    193  1.1  pk  */
    194  1.1  pk #define IEVME_PARACK 0x0100	/* parity error ack */
    195  1.1  pk #define IEVME_PARSRC 0x0080	/* parity error source */
    196  1.1  pk #define IEVME_PAREND 0x0040	/* which end of the data got the error */
    197  1.1  pk #define IEVME_PARADR 0x000f	/* mask to get bits 17-20 of parity address */
    198  1.1  pk 
    199  1.1  pk 
    200  1.1  pk /*
    201  1.1  pk  * the 3E board not supported (yet?)
    202  1.1  pk  */
    203  1.1  pk 
    204  1.1  pk 
    205  1.1  pk static void ie_vmereset __P((struct ie_softc *));
    206  1.1  pk static void ie_vmeattend __P((struct ie_softc *));
    207  1.1  pk static void ie_vmerun __P((struct ie_softc *));
    208  1.1  pk static int  ie_vmeintr __P((struct ie_softc *));
    209  1.1  pk static caddr_t ie_align __P((caddr_t));
    210  1.1  pk 
    211  1.1  pk int ie_vme_match __P((struct device *, struct cfdata *, void *));
    212  1.1  pk void ie_vme_attach __P((struct device *, struct device *, void *));
    213  1.1  pk 
    214  1.1  pk struct cfattach ie_vme_ca = {
    215  1.1  pk 	sizeof(struct ie_softc), ie_vme_match, ie_vme_attach
    216  1.1  pk };
    217  1.1  pk 
    218  1.1  pk /*
    219  1.1  pk  * MULTIBUS/VME support routines
    220  1.1  pk  */
    221  1.1  pk void
    222  1.1  pk ie_vmereset(sc)
    223  1.1  pk 	struct ie_softc *sc;
    224  1.1  pk {
    225  1.1  pk 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    226  1.1  pk 	iev->status = IEVME_RESET;
    227  1.1  pk 	delay(100);		/* XXX could be shorter? */
    228  1.1  pk 	iev->status = 0;
    229  1.1  pk }
    230  1.1  pk 
    231  1.1  pk void
    232  1.1  pk ie_vmeattend(sc)
    233  1.1  pk 	struct ie_softc *sc;
    234  1.1  pk {
    235  1.1  pk 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    236  1.1  pk 
    237  1.1  pk 	iev->status |= IEVME_ATTEN;	/* flag! */
    238  1.1  pk 	iev->status &= ~IEVME_ATTEN;	/* down. */
    239  1.1  pk }
    240  1.1  pk 
    241  1.1  pk void
    242  1.1  pk ie_vmerun(sc)
    243  1.1  pk 	struct ie_softc *sc;
    244  1.1  pk {
    245  1.1  pk 	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
    246  1.1  pk 
    247  1.1  pk 	iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
    248  1.1  pk }
    249  1.1  pk 
    250  1.1  pk int
    251  1.1  pk ie_vmeintr(sc)
    252  1.1  pk 	struct ie_softc *sc;
    253  1.1  pk {
    254  1.1  pk 	volatile struct ievme *iev = (volatile struct ievme *)sc->sc_reg;
    255  1.1  pk 
    256  1.1  pk         /*
    257  1.1  pk          * check for parity error
    258  1.1  pk          */
    259  1.1  pk 	if (iev->status & IEVME_PERR) {
    260  1.1  pk 		printf("%s: parity error (ctrl 0x%x @ 0x%02x%04x)\n",
    261  1.1  pk 			sc->sc_dev.dv_xname, iev->pectrl,
    262  1.1  pk 			iev->pectrl & IEVME_HADDR, iev->peaddr);
    263  1.1  pk 		iev->pectrl = iev->pectrl | IEVME_PARACK;
    264  1.1  pk 	}
    265  1.1  pk 	return (0);
    266  1.1  pk }
    267  1.1  pk 
    268  1.1  pk caddr_t
    269  1.1  pk ie_align(ptr)
    270  1.1  pk         caddr_t ptr;
    271  1.1  pk {
    272  1.1  pk         u_long  l = (u_long)ptr;
    273  1.1  pk 
    274  1.1  pk         l = (l + 3) & ~3L;
    275  1.1  pk         return (caddr_t)l;
    276  1.1  pk }
    277  1.1  pk 
    278  1.1  pk int
    279  1.1  pk ie_vme_match(parent, cf, aux)
    280  1.1  pk 	struct device *parent;
    281  1.1  pk 	struct cfdata *cf;
    282  1.1  pk 	void *aux;
    283  1.1  pk {
    284  1.1  pk 	struct vme_attach_args *va = aux;
    285  1.1  pk 	vme_chipset_tag_t ct = va->vma_chipset_tag;
    286  1.1  pk 	bus_space_tag_t bt = va->vma_bustag;
    287  1.1  pk 	int mod;
    288  1.1  pk 
    289  1.1  pk 	mod = VMEMOD_A24 | VMEMOD_S | VMEMOD_D;
    290  1.1  pk 	if (vme_bus_probe(ct, bt, va->vma_reg[0], 2, mod))
    291  1.1  pk 		return (1);
    292  1.1  pk 
    293  1.1  pk 	return (0);
    294  1.1  pk }
    295  1.1  pk 
    296  1.1  pk void
    297  1.1  pk ie_vme_attach(parent, self, aux)
    298  1.1  pk 	struct device *parent;
    299  1.1  pk 	struct device *self;
    300  1.1  pk 	void   *aux;
    301  1.1  pk {
    302  1.1  pk 	u_int8_t myaddr[ETHER_ADDR_LEN];
    303  1.1  pk 	extern void myetheraddr(u_char *);	/* should be elsewhere */
    304  1.1  pk 	struct ie_softc *sc = (void *) self;
    305  1.1  pk 	struct vme_attach_args *va = aux;
    306  1.1  pk 	vme_chipset_tag_t ct = va->vma_chipset_tag;
    307  1.1  pk 	bus_space_tag_t bt = va->vma_bustag;
    308  1.1  pk 	bus_space_handle_t bh;
    309  1.1  pk 	vme_intr_handle_t ih;
    310  1.1  pk 	volatile struct ievme *iev;
    311  1.1  pk 	u_long  rampaddr;
    312  1.1  pk 	int     lcv;
    313  1.1  pk 	vme_size_t sz;
    314  1.1  pk 
    315  1.1  pk 	int mod;
    316  1.1  pk 
    317  1.1  pk 	/*
    318  1.1  pk 	 * *note*: we don't detect the difference between a VME3E and
    319  1.1  pk 	 * a multibus/vme card.   if you want to use a 3E you'll have
    320  1.1  pk 	 * to fix this.
    321  1.1  pk 	 */
    322  1.1  pk 	mod = VMEMOD_A24 | VMEMOD_S | VMEMOD_D;
    323  1.1  pk 
    324  1.1  pk #if 0
    325  1.1  pk 	sc->dmat = va->vma_dmatag;
    326  1.1  pk #endif
    327  1.1  pk 	sc->bt = bt;
    328  1.1  pk 
    329  1.1  pk 	sc->hwreset = ie_vmereset;
    330  1.1  pk 	sc->hwinit = ie_vmerun;
    331  1.1  pk 	sc->chan_attn = ie_vmeattend;
    332  1.1  pk 	sc->align = ie_align;
    333  1.1  pk 	sc->intrhook = ie_vmeintr;
    334  1.1  pk 	sc->memcopy = wcopy;
    335  1.1  pk 	sc->memzero = wzero;
    336  1.1  pk 	sc->sc_msize = 4*65536;	/* XXX */
    337  1.1  pk 
    338  1.1  pk 	sz = sizeof(struct ievme);
    339  1.1  pk 	if (vme_bus_map(ct, va->vma_reg[0], sz, mod, bt, &bh) != 0)
    340  1.1  pk 		panic("if_ie: vme_map");
    341  1.1  pk 	sc->sc_reg = (caddr_t)bh;
    342  1.1  pk 
    343  1.1  pk 	iev = (volatile struct ievme *) sc->sc_reg;
    344  1.1  pk 	/* top 12 bits */
    345  1.1  pk 	rampaddr = (u_long)va->vma_reg[0] & 0xfff00000;
    346  1.1  pk 
    347  1.1  pk 	/* 4 more */
    348  1.1  pk 	rampaddr = rampaddr | ((iev->status & IEVME_HADDR) << 16);
    349  1.1  pk 	sz = sc->sc_msize;
    350  1.1  pk 	if (vme_bus_map(ct, rampaddr, sz, mod, bt, &bh) != 0)
    351  1.1  pk 		panic("if_ie: vme_map");
    352  1.1  pk 
    353  1.1  pk 	sc->sc_maddr = (caddr_t)bh;
    354  1.1  pk 	sc->sc_iobase = sc->sc_maddr;
    355  1.1  pk 
    356  1.1  pk 	iev->pectrl = iev->pectrl | IEVME_PARACK; /* clear to start */
    357  1.1  pk 
    358  1.1  pk 	/*
    359  1.1  pk 	 * Set up mappings, direct map except for last page
    360  1.1  pk 	 * which is mapped at zero and at high address (for scp)
    361  1.1  pk 	 */
    362  1.1  pk 	for (lcv = 0; lcv < IEVME_MAPSZ - 1; lcv++)
    363  1.1  pk 		iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
    364  1.1  pk 	iev->pgmap[IEVME_MAPSZ - 1] = IEVME_SBORDR | IEVME_OBMEM | 0;
    365  1.1  pk 
    366  1.1  pk 	/* Clear all ram */
    367  1.1  pk 	(sc->memzero)(sc->sc_maddr, sc->sc_msize);
    368  1.1  pk 
    369  1.1  pk 	/*
    370  1.1  pk 	 * set up pointers to data structures and buffer area.
    371  1.1  pk 	 * scp is in double mapped page... get offset into page
    372  1.1  pk 	 * and add to sc_maddr.
    373  1.1  pk 	 */
    374  1.1  pk 	sc->scp = (volatile struct ie_sys_conf_ptr *)
    375  1.1  pk 		(sc->sc_maddr + (IE_SCP_ADDR & (IEVME_PAGESIZE - 1)));
    376  1.1  pk 
    377  1.1  pk 	/* iscp at location zero */
    378  1.1  pk 	sc->iscp = (volatile struct ie_int_sys_conf_ptr *)sc->sc_maddr;
    379  1.1  pk 
    380  1.1  pk 	/* scb follows iscp */
    381  1.1  pk 	sc->scb = (volatile struct ie_sys_ctl_block *)
    382  1.1  pk 		sc->sc_maddr + sizeof(struct ie_int_sys_conf_ptr);
    383  1.1  pk 
    384  1.1  pk 	/*
    385  1.1  pk 	 * Rest of first page is unused; rest of ram for buffers.
    386  1.1  pk 	 */
    387  1.1  pk 	sc->buf_area = sc->sc_maddr + IEVME_PAGESIZE;
    388  1.1  pk 	sc->buf_area_sz = sc->sc_msize - IEVME_PAGESIZE;
    389  1.1  pk 
    390  1.1  pk 	myetheraddr(myaddr);
    391  1.1  pk 	ie_attach(sc, "multibus/vme", myaddr);
    392  1.1  pk 
    393  1.1  pk 	vme_intr_map(ct, va->vma_vec, va->vma_pri, &ih);
    394  1.1  pk 	vme_intr_establish(ct, ih, ieintr, sc);
    395  1.1  pk }
    396