/*
* This file is derived from sys/arch/i386/stand/lib/netif/ne.c
* NetBSD: ne.c,v 1.7 2008/12/14 18:46:33 christos Exp
*/
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet
* adapters.
*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
*
* Copyright (C) 1993, David Greenman. This software may be used, modified,
* copied, distributed, and sold, in both source and binary form provided that
* the above copyright and these terms are retained. Under no circumstances is
* the author responsible for the proper functioning of this software, nor does
* the author assume any responsibility for damages incurred with its use.
*/
/*
* this code is mainly obtained from /sys/dev/ic/ne2000.c .
*/
/*
* NE2000 on Neptune-X and Nereid has the following register mappings:
* - 8bit NIC registers are mapped at sparse even addresses
* - 16bit data registers on NE2000 ASIC are used to transfer stream data
* so no software byte swap ops are necessary even on word access
*/
#define ASIC_PORT(x) (NE_ASIC_BASEREG + (x) * 2)
#define ASIC_INB(x) inb(ASIC_PORT(x))
#define ASIC_INW(x) inw(ASIC_PORT(x))
#define ASIC_OUTB(x, b) outb(ASIC_PORT(x), (b))
#define ASIC_OUTW(x, b) outw(ASIC_PORT(x), (b))
uint8_t eth_myaddr[6];
int
EtherInit(unsigned char *myadr)
{
uint8_t romdata[16];
uint8_t tmp;
int i;
for (i = 0; i < 100; i++) {
if ((NIC_INB(ED_P0_ISR) & ED_ISR_RST) == ED_ISR_RST) {
/* Ack the reset bit. */
NIC_OUTB(ED_P0_ISR, ED_ISR_RST);
break;
}
DELAY(100);
}
printf("ne: found\n");
/*
* This prevents packets from being stored in the NIC memory when
* the readmem routine turns on the start bit in the CR.
*/
NIC_OUTB(ED_P0_RCR, ED_RCR_MON);
#ifdef NE_16BIT
for (i = 0; i < len; i += 2, src += 2)
ASIC_OUTW(NE2000_ASIC_DATA, *(uint16_t *)src);
#else
for (i = 0; i < len; i++)
ASIC_OUTB(NE2000_ASIC_DATA, *src++);
#endif
/*
* Wait for remote DMA to complete. This is necessary because on the
* transmit side, data is handled internally by the NIC in bursts, and
* we can't start another remote DMA until this one completes. Not
* waiting causes really bad things to happen - like the NIC wedging
* the bus.
*/
while (((NIC_INB(ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait)
DELAY(1);
if (maxwait == 0)
printf("ne2000_writemem: failed to complete\n");
}
#ifdef NE_16BIT
for (i = 0; i < amount; i += 2, dst += 2)
*(uint16_t *)dst = ASIC_INW(NE2000_ASIC_DATA);
#else
for (i = 0; i < amount; i++)
*dst++ = ASIC_INB(NE2000_ASIC_DATA);
#endif
}