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