Home | History | Annotate | Line # | Download | only in tc
if_le_ioasic.c revision 1.4
      1  1.4       is /*	$NetBSD: if_le_ioasic.c,v 1.4 1997/03/15 18:12:05 is Exp $	*/
      2  1.1      cgd 
      3  1.1      cgd /*
      4  1.1      cgd  * Copyright (c) 1996 Carnegie-Mellon University.
      5  1.1      cgd  * All rights reserved.
      6  1.1      cgd  *
      7  1.1      cgd  * Author: Chris G. Demetriou
      8  1.1      cgd  *
      9  1.1      cgd  * Permission to use, copy, modify and distribute this software and
     10  1.1      cgd  * its documentation is hereby granted, provided that both the copyright
     11  1.1      cgd  * notice and this permission notice appear in all copies of the
     12  1.1      cgd  * software, derivative works or modified versions, and any portions
     13  1.1      cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.1      cgd  *
     15  1.1      cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1      cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1      cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1      cgd  *
     19  1.1      cgd  * Carnegie Mellon requests users of this software to return to
     20  1.1      cgd  *
     21  1.1      cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1      cgd  *  School of Computer Science
     23  1.1      cgd  *  Carnegie Mellon University
     24  1.1      cgd  *  Pittsburgh PA 15213-3890
     25  1.1      cgd  *
     26  1.1      cgd  * any improvements or extensions that they make and grant Carnegie the
     27  1.1      cgd  * rights to redistribute these changes.
     28  1.1      cgd  */
     29  1.1      cgd 
     30  1.1      cgd /*
     31  1.1      cgd  * LANCE on DEC IOCTL ASIC.
     32  1.1      cgd  */
     33  1.1      cgd 
     34  1.1      cgd #include <sys/param.h>
     35  1.1      cgd #include <sys/systm.h>
     36  1.1      cgd #include <sys/mbuf.h>
     37  1.1      cgd #include <sys/syslog.h>
     38  1.1      cgd #include <sys/socket.h>
     39  1.1      cgd #include <sys/device.h>
     40  1.1      cgd 
     41  1.1      cgd #include <net/if.h>
     42  1.1      cgd 
     43  1.1      cgd #ifdef INET
     44  1.1      cgd #include <netinet/in.h>
     45  1.4       is #include <netinet/if_inarp.h>
     46  1.1      cgd #endif
     47  1.1      cgd 
     48  1.1      cgd #include <dev/ic/am7990reg.h>
     49  1.1      cgd #include <dev/ic/am7990var.h>
     50  1.1      cgd 
     51  1.2  thorpej #include <dev/tc/if_levar.h>
     52  1.1      cgd #include <dev/tc/tcvar.h>
     53  1.1      cgd #include <dev/tc/ioasicvar.h>
     54  1.1      cgd 
     55  1.1      cgd extern caddr_t le_iomem;
     56  1.1      cgd 
     57  1.3      cgd #ifdef __BROKEN_INDIRECT_CONFIG
     58  1.1      cgd int	le_ioasic_match __P((struct device *, void *, void *));
     59  1.3      cgd #else
     60  1.3      cgd int	le_ioasic_match __P((struct device *, struct cfdata *, void *));
     61  1.3      cgd #endif
     62  1.1      cgd void	le_ioasic_attach __P((struct device *, struct device *, void *));
     63  1.1      cgd 
     64  1.2  thorpej hide void le_ioasic_copytobuf_gap2 __P((struct am7990_softc *, void *,
     65  1.2  thorpej 	    int, int));
     66  1.2  thorpej hide void le_ioasic_copyfrombuf_gap2 __P((struct am7990_softc *, void *,
     67  1.2  thorpej 	    int, int));
     68  1.2  thorpej 
     69  1.2  thorpej hide void le_ioasic_copytobuf_gap16 __P((struct am7990_softc *, void *,
     70  1.2  thorpej 	    int, int));
     71  1.2  thorpej hide void le_ioasic_copyfrombuf_gap16 __P((struct am7990_softc *, void *,
     72  1.2  thorpej 	    int, int));
     73  1.2  thorpej hide void le_ioasic_zerobuf_gap16 __P((struct am7990_softc *, int, int));
     74  1.2  thorpej 
     75  1.1      cgd struct cfattach le_ioasic_ca = {
     76  1.1      cgd 	sizeof(struct le_softc), le_ioasic_match, le_ioasic_attach
     77  1.1      cgd };
     78  1.1      cgd 
     79  1.1      cgd int
     80  1.1      cgd le_ioasic_match(parent, match, aux)
     81  1.1      cgd 	struct device *parent;
     82  1.3      cgd #ifdef __BROKEN_INDIRECT_CONFIG
     83  1.3      cgd 	void *match;
     84  1.3      cgd #else
     85  1.3      cgd 	struct cfdata *match;
     86  1.3      cgd #endif
     87  1.3      cgd 	void *aux;
     88  1.1      cgd {
     89  1.1      cgd 	struct ioasicdev_attach_args *d = aux;
     90  1.1      cgd 
     91  1.1      cgd 	if (!ioasic_submatch(match, aux))
     92  1.1      cgd 		return (0);
     93  1.1      cgd 	if (strncmp("lance", d->iada_modname, TC_ROM_LLEN))
     94  1.1      cgd 		return (0);
     95  1.1      cgd 
     96  1.1      cgd 	return (1);
     97  1.1      cgd }
     98  1.1      cgd 
     99  1.1      cgd void
    100  1.1      cgd le_ioasic_attach(parent, self, aux)
    101  1.1      cgd 	struct device *parent, *self;
    102  1.1      cgd 	void *aux;
    103  1.1      cgd {
    104  1.1      cgd 	struct ioasicdev_attach_args *d = aux;
    105  1.2  thorpej 	register struct le_softc *lesc = (void *)self;
    106  1.2  thorpej 	register struct am7990_softc *sc = &lesc->sc_am7990;
    107  1.1      cgd 
    108  1.2  thorpej 	lesc->sc_r1 = (struct lereg1 *)
    109  1.1      cgd 		TC_DENSE_TO_SPARSE(TC_PHYS_TO_UNCACHED(d->iada_addr));
    110  1.1      cgd 	sc->sc_mem = (void *)TC_PHYS_TO_UNCACHED(le_iomem);
    111  1.1      cgd 
    112  1.2  thorpej 	sc->sc_copytodesc = le_ioasic_copytobuf_gap2;
    113  1.2  thorpej 	sc->sc_copyfromdesc = le_ioasic_copyfrombuf_gap2;
    114  1.2  thorpej 	sc->sc_copytobuf = le_ioasic_copytobuf_gap16;
    115  1.2  thorpej 	sc->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
    116  1.2  thorpej 	sc->sc_zerobuf = le_ioasic_zerobuf_gap16;
    117  1.1      cgd 
    118  1.1      cgd 	ioasic_lance_dma_setup(le_iomem);	/* XXX more thought */
    119  1.1      cgd 
    120  1.1      cgd 	dec_le_common_attach(sc, ioasic_lance_ether_address());
    121  1.1      cgd 
    122  1.2  thorpej 	ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_NET,
    123  1.2  thorpej 	    am7990_intr, sc);
    124  1.2  thorpej }
    125  1.2  thorpej 
    126  1.2  thorpej /*
    127  1.2  thorpej  * Special memory access functions needed by ioasic-attached LANCE
    128  1.2  thorpej  * chips.
    129  1.2  thorpej  */
    130  1.2  thorpej 
    131  1.2  thorpej /*
    132  1.2  thorpej  * gap2: two bytes of data followed by two bytes of pad.
    133  1.2  thorpej  *
    134  1.2  thorpej  * Buffers must be 4-byte aligned.  The code doesn't worry about
    135  1.2  thorpej  * doing an extra byte.
    136  1.2  thorpej  */
    137  1.2  thorpej 
    138  1.2  thorpej void
    139  1.2  thorpej le_ioasic_copytobuf_gap2(sc, fromv, boff, len)
    140  1.2  thorpej 	struct am7990_softc *sc;
    141  1.2  thorpej 	void *fromv;
    142  1.2  thorpej 	int boff;
    143  1.2  thorpej 	register int len;
    144  1.2  thorpej {
    145  1.2  thorpej 	volatile caddr_t buf = sc->sc_mem;
    146  1.2  thorpej 	register caddr_t from = fromv;
    147  1.2  thorpej 	register volatile u_int16_t *bptr;
    148  1.2  thorpej 
    149  1.2  thorpej 	if (boff & 0x1) {
    150  1.2  thorpej 		/* handle unaligned first byte */
    151  1.2  thorpej 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    152  1.2  thorpej 		*bptr = (*from++ << 8) | (*bptr & 0xff);
    153  1.2  thorpej 		bptr += 2;
    154  1.2  thorpej 		len--;
    155  1.2  thorpej 	} else
    156  1.2  thorpej 		bptr = ((volatile u_int16_t *)buf) + boff;
    157  1.2  thorpej 	while (len > 1) {
    158  1.2  thorpej 		*bptr = (from[1] << 8) | (from[0] & 0xff);
    159  1.2  thorpej 		bptr += 2;
    160  1.2  thorpej 		from += 2;
    161  1.2  thorpej 		len -= 2;
    162  1.2  thorpej 	}
    163  1.2  thorpej 	if (len == 1)
    164  1.2  thorpej 		*bptr = (u_int16_t)*from;
    165  1.2  thorpej }
    166  1.2  thorpej 
    167  1.2  thorpej void
    168  1.2  thorpej le_ioasic_copyfrombuf_gap2(sc, tov, boff, len)
    169  1.2  thorpej 	struct am7990_softc *sc;
    170  1.2  thorpej 	void *tov;
    171  1.2  thorpej 	int boff, len;
    172  1.2  thorpej {
    173  1.2  thorpej 	volatile caddr_t buf = sc->sc_mem;
    174  1.2  thorpej 	register caddr_t to = tov;
    175  1.2  thorpej 	register volatile u_int16_t *bptr;
    176  1.2  thorpej 	register u_int16_t tmp;
    177  1.2  thorpej 
    178  1.2  thorpej 	if (boff & 0x1) {
    179  1.2  thorpej 		/* handle unaligned first byte */
    180  1.2  thorpej 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    181  1.2  thorpej 		*to++ = (*bptr >> 8) & 0xff;
    182  1.2  thorpej 		bptr += 2;
    183  1.2  thorpej 		len--;
    184  1.2  thorpej 	} else
    185  1.2  thorpej 		bptr = ((volatile u_int16_t *)buf) + boff;
    186  1.2  thorpej 	while (len > 1) {
    187  1.2  thorpej 		tmp = *bptr;
    188  1.2  thorpej 		*to++ = tmp & 0xff;
    189  1.2  thorpej 		*to++ = (tmp >> 8) & 0xff;
    190  1.2  thorpej 		bptr += 2;
    191  1.2  thorpej 		len -= 2;
    192  1.2  thorpej 	}
    193  1.2  thorpej 	if (len == 1)
    194  1.2  thorpej 		*to = *bptr & 0xff;
    195  1.2  thorpej }
    196  1.2  thorpej 
    197  1.2  thorpej /*
    198  1.2  thorpej  * gap16: 16 bytes of data followed by 16 bytes of pad.
    199  1.2  thorpej  *
    200  1.2  thorpej  * Buffers must be 32-byte aligned.
    201  1.2  thorpej  */
    202  1.2  thorpej 
    203  1.2  thorpej void
    204  1.2  thorpej le_ioasic_copytobuf_gap16(sc, fromv, boff, len)
    205  1.2  thorpej 	struct am7990_softc *sc;
    206  1.2  thorpej 	void *fromv;
    207  1.2  thorpej 	int boff;
    208  1.2  thorpej 	register int len;
    209  1.2  thorpej {
    210  1.2  thorpej 	volatile caddr_t buf = sc->sc_mem;
    211  1.2  thorpej 	register caddr_t from = fromv;
    212  1.2  thorpej 	register caddr_t bptr;
    213  1.2  thorpej 	register int xfer;
    214  1.2  thorpej 
    215  1.2  thorpej 	bptr = buf + ((boff << 1) & ~0x1f);
    216  1.2  thorpej 	boff &= 0xf;
    217  1.2  thorpej 	xfer = min(len, 16 - boff);
    218  1.2  thorpej 	while (len > 0) {
    219  1.2  thorpej 		bcopy(from, bptr + boff, xfer);
    220  1.2  thorpej 		from += xfer;
    221  1.2  thorpej 		bptr += 32;
    222  1.2  thorpej 		boff = 0;
    223  1.2  thorpej 		len -= xfer;
    224  1.2  thorpej 		xfer = min(len, 16);
    225  1.2  thorpej 	}
    226  1.2  thorpej }
    227  1.2  thorpej 
    228  1.2  thorpej void
    229  1.2  thorpej le_ioasic_copyfrombuf_gap16(sc, tov, boff, len)
    230  1.2  thorpej 	struct am7990_softc *sc;
    231  1.2  thorpej 	void *tov;
    232  1.2  thorpej 	int boff, len;
    233  1.2  thorpej {
    234  1.2  thorpej 	volatile caddr_t buf = sc->sc_mem;
    235  1.2  thorpej 	register caddr_t to = tov;
    236  1.2  thorpej 	register caddr_t bptr;
    237  1.2  thorpej 	register int xfer;
    238  1.2  thorpej 
    239  1.2  thorpej 	bptr = buf + ((boff << 1) & ~0x1f);
    240  1.2  thorpej 	boff &= 0xf;
    241  1.2  thorpej 	xfer = min(len, 16 - boff);
    242  1.2  thorpej 	while (len > 0) {
    243  1.2  thorpej 		bcopy(bptr + boff, to, xfer);
    244  1.2  thorpej 		to += xfer;
    245  1.2  thorpej 		bptr += 32;
    246  1.2  thorpej 		boff = 0;
    247  1.2  thorpej 		len -= xfer;
    248  1.2  thorpej 		xfer = min(len, 16);
    249  1.2  thorpej 	}
    250  1.2  thorpej }
    251  1.2  thorpej 
    252  1.2  thorpej void
    253  1.2  thorpej le_ioasic_zerobuf_gap16(sc, boff, len)
    254  1.2  thorpej 	struct am7990_softc *sc;
    255  1.2  thorpej 	int boff, len;
    256  1.2  thorpej {
    257  1.2  thorpej 	volatile caddr_t buf = sc->sc_mem;
    258  1.2  thorpej 	register caddr_t bptr;
    259  1.2  thorpej 	register int xfer;
    260  1.2  thorpej 
    261  1.2  thorpej 	bptr = buf + ((boff << 1) & ~0x1f);
    262  1.2  thorpej 	boff &= 0xf;
    263  1.2  thorpej 	xfer = min(len, 16 - boff);
    264  1.2  thorpej 	while (len > 0) {
    265  1.2  thorpej 		bzero(bptr + boff, xfer);
    266  1.2  thorpej 		bptr += 32;
    267  1.2  thorpej 		boff = 0;
    268  1.2  thorpej 		len -= xfer;
    269  1.2  thorpej 		xfer = min(len, 16);
    270  1.2  thorpej 	}
    271  1.1      cgd }
    272