2001-05-30 15:40:35 +04:00
|
|
|
/* $NetBSD: if_le_dec.c,v 1.11 2001/05/30 11:46:34 mrg Exp $ */
|
1995-12-20 03:52:16 +03:00
|
|
|
|
|
|
|
/*-
|
1997-07-22 08:32:13 +04:00
|
|
|
* Copyright (c) 1997 Jonathan Stone. All rights reserved.
|
1995-12-20 03:52:16 +03:00
|
|
|
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
|
|
|
|
*/
|
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1996-03-26 16:44:07 +03:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
1995-12-20 03:52:16 +03: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-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1997-03-17 06:17:34 +03:00
|
|
|
#include <net/if_media.h>
|
1995-12-20 03:52:16 +03:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1995-12-20 03:52:16 +03:00
|
|
|
#endif
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1995-12-20 03:52:16 +03:00
|
|
|
#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>
|
1995-12-20 03:52:16 +03:00
|
|
|
|
1997-06-16 07:46:29 +04:00
|
|
|
#include <machine/bus.h>
|
1997-06-15 22:23:02 +04:00
|
|
|
|
1995-12-20 03:52:16 +03:00
|
|
|
/* access LANCE registers */
|
1996-05-07 06:24:54 +04:00
|
|
|
void le_dec_writereg __P((volatile u_short *regptr, u_short val));
|
1995-12-20 03:52:16 +03:00
|
|
|
#define LERDWR(cntl, src, dst) { (dst) = (src); tc_mb(); }
|
1996-05-07 06:24:54 +04:00
|
|
|
#define LEWREG(src, dst) le_dec_writereg(&(dst), (src))
|
1995-12-20 03:52:16 +03:00
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-07-21 21:36:01 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
#define integrate
|
|
|
|
#define hide
|
|
|
|
#else
|
|
|
|
#define integrate static __inline
|
|
|
|
#define hide static
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hide void le_dec_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
|
|
|
|
hide u_int16_t le_dec_rdcsr __P((struct lance_softc *, u_int16_t));
|
1995-12-20 03:52:16 +03:00
|
|
|
|
1996-04-18 04:50:11 +04:00
|
|
|
void
|
|
|
|
dec_le_common_attach(sc, eap)
|
1996-05-07 06:24:54 +04:00
|
|
|
struct am7990_softc *sc;
|
1996-04-18 04:50:11 +04:00
|
|
|
u_char *eap;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
sc->lsc.sc_rdcsr = le_dec_rdcsr;
|
|
|
|
sc->lsc.sc_wrcsr = le_dec_wrcsr;
|
|
|
|
sc->lsc.sc_hwinit = NULL;
|
1996-05-07 06:24:54 +04:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
sc->lsc.sc_conf3 = 0;
|
|
|
|
sc->lsc.sc_addr = 0;
|
|
|
|
sc->lsc.sc_memsize = 65536;
|
1996-04-18 04:50:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the ethernet address out of rom
|
|
|
|
*/
|
1998-07-21 21:36:01 +04:00
|
|
|
for (i = 0; i < sizeof(sc->lsc.sc_enaddr); i++) {
|
|
|
|
sc->lsc.sc_enaddr[i] = *eap;
|
1996-04-18 04:50:11 +04:00
|
|
|
eap += 4;
|
|
|
|
}
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
am7990_config(sc);
|
1996-04-18 04:50:11 +04:00
|
|
|
}
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
hide void
|
|
|
|
le_dec_wrcsr(sc, port, val)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1995-12-20 03:52:16 +03:00
|
|
|
u_int16_t port, val;
|
|
|
|
{
|
1996-05-07 06:24:54 +04:00
|
|
|
struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
|
1995-12-20 03:52:16 +03:00
|
|
|
|
|
|
|
LEWREG(port, ler1->ler1_rap);
|
|
|
|
LERDWR(port, val, ler1->ler1_rdp);
|
|
|
|
}
|
|
|
|
|
1996-05-07 06:24:54 +04:00
|
|
|
hide u_int16_t
|
|
|
|
le_dec_rdcsr(sc, port)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1995-12-20 03:52:16 +03:00
|
|
|
u_int16_t port;
|
|
|
|
{
|
1996-05-07 06:24:54 +04:00
|
|
|
struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
|
1995-12-20 03:52:16 +03:00
|
|
|
u_int16_t val;
|
|
|
|
|
|
|
|
LEWREG(port, ler1->ler1_rap);
|
|
|
|
LERDWR(0, ler1->ler1_rdp, val);
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a lance register port, reading it back to ensure success. This seems
|
|
|
|
* to be necessary during initialization, since the chip appears to be a bit
|
|
|
|
* pokey sometimes.
|
|
|
|
*/
|
|
|
|
void
|
1996-05-07 06:24:54 +04:00
|
|
|
le_dec_writereg(regptr, val)
|
1995-12-20 03:52:16 +03:00
|
|
|
register volatile u_short *regptr;
|
|
|
|
register u_short val;
|
|
|
|
{
|
|
|
|
register int i = 0;
|
|
|
|
|
|
|
|
while (*regptr != val) {
|
|
|
|
*regptr = val;
|
|
|
|
tc_mb();
|
|
|
|
if (++i > 10000) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("le: Reg did not settle (to x%x): x%x\n", val,
|
1995-12-20 03:52:16 +03:00
|
|
|
*regptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines for accessing the transmit and receive buffers are provided
|
|
|
|
* by am7990.c, because of the LE_NEED_BUF_* macros defined above.
|
|
|
|
* Unfortunately, CPU addressing of these buffers is done in one of
|
|
|
|
* 3 ways:
|
|
|
|
* - contiguous (for the 3max and turbochannel option card)
|
|
|
|
* - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
|
1997-07-22 08:32:13 +04:00
|
|
|
* spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
|
1995-12-20 03:52:16 +03:00
|
|
|
* - gap16, which means 16bytes interspersed with 16byte spaces
|
|
|
|
* for buffers which must begin on a 32byte boundary (for 3min, maxine,
|
|
|
|
* and alpha)
|
|
|
|
* The buffer offset is the logical byte offset, assuming contiguous storage.
|
|
|
|
*/
|