1997-03-16 00:06:09 +03:00
|
|
|
/* $NetBSD: if_le_ioasic.c,v 1.5 1997/03/15 21:06:12 cgd Exp $ */
|
1996-04-18 04:50:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LANCE on DEC IOCTL ASIC.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-16 00:06:09 +03:00
|
|
|
#include <net/if_ether.h>
|
1996-04-18 04:50:11 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1996-04-18 04:50:11 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
#include <dev/tc/if_levar.h>
|
1996-04-18 04:50:11 +04:00
|
|
|
#include <dev/tc/tcvar.h>
|
|
|
|
#include <dev/tc/ioasicvar.h>
|
|
|
|
|
|
|
|
extern caddr_t le_iomem;
|
|
|
|
|
1996-12-05 04:25:23 +03:00
|
|
|
#ifdef __BROKEN_INDIRECT_CONFIG
|
1996-04-18 04:50:11 +04:00
|
|
|
int le_ioasic_match __P((struct device *, void *, void *));
|
1996-12-05 04:25:23 +03:00
|
|
|
#else
|
|
|
|
int le_ioasic_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
#endif
|
1996-04-18 04:50:11 +04:00
|
|
|
void le_ioasic_attach __P((struct device *, struct device *, void *));
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
hide void le_ioasic_copytobuf_gap2 __P((struct am7990_softc *, void *,
|
|
|
|
int, int));
|
|
|
|
hide void le_ioasic_copyfrombuf_gap2 __P((struct am7990_softc *, void *,
|
|
|
|
int, int));
|
|
|
|
|
|
|
|
hide void le_ioasic_copytobuf_gap16 __P((struct am7990_softc *, void *,
|
|
|
|
int, int));
|
|
|
|
hide void le_ioasic_copyfrombuf_gap16 __P((struct am7990_softc *, void *,
|
|
|
|
int, int));
|
|
|
|
hide void le_ioasic_zerobuf_gap16 __P((struct am7990_softc *, int, int));
|
|
|
|
|
1996-04-18 04:50:11 +04:00
|
|
|
struct cfattach le_ioasic_ca = {
|
|
|
|
sizeof(struct le_softc), le_ioasic_match, le_ioasic_attach
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
le_ioasic_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
1996-12-05 04:25:23 +03:00
|
|
|
#ifdef __BROKEN_INDIRECT_CONFIG
|
|
|
|
void *match;
|
|
|
|
#else
|
|
|
|
struct cfdata *match;
|
|
|
|
#endif
|
|
|
|
void *aux;
|
1996-04-18 04:50:11 +04:00
|
|
|
{
|
|
|
|
struct ioasicdev_attach_args *d = aux;
|
|
|
|
|
|
|
|
if (!ioasic_submatch(match, aux))
|
|
|
|
return (0);
|
|
|
|
if (strncmp("lance", d->iada_modname, TC_ROM_LLEN))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct ioasicdev_attach_args *d = aux;
|
1996-05-07 06:24:54 +04:00
|
|
|
register struct le_softc *lesc = (void *)self;
|
|
|
|
register struct am7990_softc *sc = &lesc->sc_am7990;
|
1996-04-18 04:50:11 +04:00
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
lesc->sc_r1 = (struct lereg1 *)
|
1996-04-18 04:50:11 +04:00
|
|
|
TC_DENSE_TO_SPARSE(TC_PHYS_TO_UNCACHED(d->iada_addr));
|
|
|
|
sc->sc_mem = (void *)TC_PHYS_TO_UNCACHED(le_iomem);
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
sc->sc_copytodesc = le_ioasic_copytobuf_gap2;
|
|
|
|
sc->sc_copyfromdesc = le_ioasic_copyfrombuf_gap2;
|
|
|
|
sc->sc_copytobuf = le_ioasic_copytobuf_gap16;
|
|
|
|
sc->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
|
|
|
|
sc->sc_zerobuf = le_ioasic_zerobuf_gap16;
|
1996-04-18 04:50:11 +04:00
|
|
|
|
|
|
|
ioasic_lance_dma_setup(le_iomem); /* XXX more thought */
|
|
|
|
|
|
|
|
dec_le_common_attach(sc, ioasic_lance_ether_address());
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_NET,
|
|
|
|
am7990_intr, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special memory access functions needed by ioasic-attached LANCE
|
|
|
|
* chips.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gap2: two bytes of data followed by two bytes of pad.
|
|
|
|
*
|
|
|
|
* Buffers must be 4-byte aligned. The code doesn't worry about
|
|
|
|
* doing an extra byte.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_copytobuf_gap2(sc, fromv, boff, len)
|
|
|
|
struct am7990_softc *sc;
|
|
|
|
void *fromv;
|
|
|
|
int boff;
|
|
|
|
register int len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
register caddr_t from = fromv;
|
|
|
|
register volatile u_int16_t *bptr;
|
|
|
|
|
|
|
|
if (boff & 0x1) {
|
|
|
|
/* handle unaligned first byte */
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*bptr = (*from++ << 8) | (*bptr & 0xff);
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 1) {
|
|
|
|
*bptr = (from[1] << 8) | (from[0] & 0xff);
|
|
|
|
bptr += 2;
|
|
|
|
from += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
if (len == 1)
|
|
|
|
*bptr = (u_int16_t)*from;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_copyfrombuf_gap2(sc, tov, boff, len)
|
|
|
|
struct am7990_softc *sc;
|
|
|
|
void *tov;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
register caddr_t to = tov;
|
|
|
|
register volatile u_int16_t *bptr;
|
|
|
|
register u_int16_t tmp;
|
|
|
|
|
|
|
|
if (boff & 0x1) {
|
|
|
|
/* handle unaligned first byte */
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*to++ = (*bptr >> 8) & 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 1) {
|
|
|
|
tmp = *bptr;
|
|
|
|
*to++ = tmp & 0xff;
|
|
|
|
*to++ = (tmp >> 8) & 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
if (len == 1)
|
|
|
|
*to = *bptr & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gap16: 16 bytes of data followed by 16 bytes of pad.
|
|
|
|
*
|
|
|
|
* Buffers must be 32-byte aligned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_copytobuf_gap16(sc, fromv, boff, len)
|
|
|
|
struct am7990_softc *sc;
|
|
|
|
void *fromv;
|
|
|
|
int boff;
|
|
|
|
register int len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
register caddr_t from = fromv;
|
|
|
|
register caddr_t bptr;
|
|
|
|
register int xfer;
|
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
|
|
|
bcopy(from, bptr + boff, xfer);
|
|
|
|
from += xfer;
|
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_copyfrombuf_gap16(sc, tov, boff, len)
|
|
|
|
struct am7990_softc *sc;
|
|
|
|
void *tov;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
register caddr_t to = tov;
|
|
|
|
register caddr_t bptr;
|
|
|
|
register int xfer;
|
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
|
|
|
bcopy(bptr + boff, to, xfer);
|
|
|
|
to += xfer;
|
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_ioasic_zerobuf_gap16(sc, boff, len)
|
|
|
|
struct am7990_softc *sc;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
register caddr_t bptr;
|
|
|
|
register int xfer;
|
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
|
|
|
bzero(bptr + boff, xfer);
|
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
1996-04-18 04:50:11 +04:00
|
|
|
}
|