2000-03-30 16:41:09 +04:00
|
|
|
/* $NetBSD: if_le_ibus.c,v 1.15 2000/03/30 12:45:43 augustss Exp $ */
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1996 The Board of Trustees of The Leland Stanford
|
|
|
|
* Junior University. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies. Stanford University
|
|
|
|
* makes no representations about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without
|
|
|
|
* express or implied warranty.
|
|
|
|
*
|
|
|
|
* This driver was contributed by Jonathan Stone.
|
1996-05-21 03:19:16 +04:00
|
|
|
*/
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LANCE on Decstation kn01/kn220(?) baseboard.
|
|
|
|
*/
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
#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>
|
1997-03-17 06:17:34 +03:00
|
|
|
#include <net/if_media.h>
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1996-05-20 06:25:08 +04:00
|
|
|
#endif
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1996-05-20 06:25:08 +04:00
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
|
|
|
|
|
|
|
#include <dev/tc/if_levar.h>
|
|
|
|
#include <dev/tc/tcvar.h>
|
1998-04-19 17:04:24 +04:00
|
|
|
#include <pmax/ibus/ibusvar.h>
|
1996-05-21 03:19:16 +04:00
|
|
|
#include <pmax/pmax/kn01.h>
|
1996-05-20 06:25:08 +04:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
extern void le_dec_copytobuf_gap2 __P((struct lance_softc *, void *,
|
1996-05-20 06:25:08 +04:00
|
|
|
int, int));
|
1998-07-21 21:36:01 +04:00
|
|
|
extern void le_dec_copyfrombuf_gap2 __P((struct lance_softc *, void *,
|
1996-05-20 06:25:08 +04:00
|
|
|
int, int));
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#if defined(_KERNEL) && !defined(_LKM)
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
#define integrate
|
|
|
|
#define hide
|
|
|
|
#else
|
|
|
|
#define integrate static __inline
|
|
|
|
#define hide static
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hide void le_dec_zerobuf_gap2 __P((struct lance_softc *, int, int));
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
|
1997-07-21 09:39:02 +04:00
|
|
|
int le_pmax_match __P((struct device *, struct cfdata *, void *));
|
1996-05-20 06:25:08 +04:00
|
|
|
void le_pmax_attach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach le_pmax_ca = {
|
|
|
|
sizeof(struct le_softc), le_pmax_match, le_pmax_attach
|
|
|
|
};
|
1999-11-15 08:25:57 +03:00
|
|
|
extern struct cfdriver ibus_cd;
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
le_pmax_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-07-21 09:39:02 +04:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1996-05-20 06:25:08 +04:00
|
|
|
{
|
1998-04-19 17:04:24 +04:00
|
|
|
struct ibus_attach_args *d = aux;
|
1998-01-12 12:51:28 +03:00
|
|
|
|
1999-11-15 08:25:57 +03:00
|
|
|
if (parent->dv_cfdata->cf_driver != &ibus_cd)
|
1998-04-19 17:04:24 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (strcmp("lance", d->ia_name) != 0)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
1996-05-20 06:25:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_pmax_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct le_softc *lesc = (void *)self;
|
|
|
|
struct lance_softc *sc = &lesc->sc_am7990.lsc;
|
|
|
|
u_char *cp;
|
|
|
|
struct ibus_attach_args *ia = aux;
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It's on the baseboard, with a dedicated interrupt line.
|
|
|
|
*/
|
1998-04-19 17:04:24 +04:00
|
|
|
lesc->sc_r1 = (struct lereg1 *)(ia->ia_addr);
|
2000-01-10 16:32:02 +03:00
|
|
|
/*XXX*/ sc->sc_mem = (void *)TC_PHYS_TO_UNCACHED(KN01_SYS_LANCE_B_START);
|
1996-05-20 06:25:08 +04:00
|
|
|
/*XXX*/ cp = (u_char *)(TC_PHYS_TO_UNCACHED(KN01_SYS_CLOCK) + 1);
|
|
|
|
|
|
|
|
sc->sc_copytodesc = le_dec_copytobuf_gap2;
|
|
|
|
sc->sc_copyfromdesc = le_dec_copyfrombuf_gap2;
|
|
|
|
sc->sc_copytobuf = le_dec_copytobuf_gap2;
|
|
|
|
sc->sc_copyfrombuf = le_dec_copyfrombuf_gap2;
|
|
|
|
sc->sc_zerobuf = le_dec_zerobuf_gap2;
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
dec_le_common_attach(&lesc->sc_am7990, cp);
|
1998-04-19 17:04:24 +04:00
|
|
|
|
1999-11-15 12:54:41 +03:00
|
|
|
ibus_intr_establish(parent, (void*)ia->ia_cookie, IPL_NET,
|
1996-05-20 06:25:08 +04:00
|
|
|
am7990_intr, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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_dec_copytobuf_gap2(sc, fromv, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1996-05-20 06:25:08 +04:00
|
|
|
void *fromv;
|
|
|
|
int boff;
|
2000-03-30 16:41:09 +04:00
|
|
|
int len;
|
1996-05-20 06:25:08 +04:00
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t from = fromv;
|
|
|
|
volatile u_int16_t *bptr;
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
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_dec_copyfrombuf_gap2(sc, tov, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1996-05-20 06:25:08 +04:00
|
|
|
void *tov;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t to = tov;
|
|
|
|
volatile u_int16_t *bptr;
|
|
|
|
u_int16_t tmp;
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_dec_zerobuf_gap2(sc, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1996-05-20 06:25:08 +04:00
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
volatile u_int16_t *bptr;
|
1996-05-20 06:25:08 +04:00
|
|
|
|
|
|
|
if ((unsigned)boff & 0x1) {
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*bptr &= 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 0) {
|
|
|
|
*bptr = 0;
|
|
|
|
bptr += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
}
|