Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/ether2000.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/ether2000.c 1992/1222
## diff -e /dev/null /n/bootesdump/1992/1222/sys/src/9/pc/ether2000.c
0a
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
#include "io.h"
#include "devtab.h"

#include "ether.h"

/*
 * Driver written for the 'Notebook Computer Ethernet LAN Adapter',
 * a plug-in to the bus-slot on the rear of the Gateway NOMAD 425DXL
 * laptop. The manual says NE2000 compatible.
 * The interface appears to be pretty well described in the National
 * Semiconductor Local Area Network Databook (1992) as one of the
 * AT evaluation boards.
 *
 * The NE2000 is really just a DP8390 plus a data port
 * and a reset port.
 */
enum {
	Data		= 0x10,		/* offset from I/O base of data port */
	Reset		= 0x18,		/* offset from I/O base of reset port */
};

static int
reset(Ctlr *ctlr)
{
	Board *board = ctlr->board;
	ushort buf[16];
	int i;

	/*
	 * We look for boards.
	 * We look for boards to make us barf.
	 */
	for(board->io = 0x300; board->io < 0x380; board->io += 0x20){
		/*
		 * Reset the board. This is done by doing a read
		 * followed by a write to the Reset address.
		 */
		outb(board->io+Reset, inb(board->io+Reset));

		/*
		 * Init the (possible) chip, then use the (possible)
		 * chip to read the (possible) PROM for ethernet address
		 * and a marker byte.
		 * We could just look at the DP8390 command register after
		 * initialisation has been tried, but that wouldn't be
		 * enough, there are other ethernet boards which could
		 * match.
		 */
		board->dp8390 = board->io;
		board->data = board->io+Data;
		dp8390reset(ctlr);
		memset(buf, 0, sizeof(buf));
		dp8390read(ctlr, buf, 0, sizeof(buf));
		if(buf[0x0E] == 0x57 && buf[0x0F] == 0x57)
			break;
	}
	if(board->io >= 0x380)
		return -1;

	/*
	 * Stupid machine. We asked for shorts, we got shorts,
	 * although the PROM is a byte array.
	 * Now we can set the ethernet address.
	 */
	for(i = 0; i < sizeof(ctlr->ea); i++)
		ctlr->ea[i] = buf[i];
	dp8390setea(ctlr);

	print("NE2000 I/O addr %lux width %d addr %lux size %d irq %d:",
		board->io, board->bit16 ? 16: 8, board->ramstart,
		board->ramstop-board->ramstart, board->irq);
	for(i = 0; i < sizeof(ctlr->ea); i++)
		print(" %2.2ux", ctlr->ea[i]);
	print("\n");

	return 0;
}

Board ether2000 = {
	reset,
	0,			/* init */
	dp8390attach,
	dp8390mode,
	dp8390receive,
	dp8390transmit,
	dp8390intr,
	0,			/* watch */

	0x300,			/* addr */
	2,			/* irq */
	1,			/* bit16 */

	0,			/* ram */
	0x4000,			/* ramstart */
	0x4000+16*1024,		/* ramstop */

	0x300,			/* dp8390 */
	0x300+Data,		/* data */
	0x4000/Dp8390BufSz,	/* tstart */
	0x4600/Dp8390BufSz,	/* pstart */
	0x8000/Dp8390BufSz,	/* pstop */
};
.
## diffname pc/ether2000.c 1993/0212
## diff -e /n/bootesdump/1992/1222/sys/src/9/pc/ether2000.c /n/bootesdump/1993/0212/sys/src/9/pc/ether2000.c
103,107c
	dp8390receive,			/* receive */
	dp8390transmit,			/* transmit */
	dp8390intr,			/* interrupt */
	dp8390watch,			/* watch */
	dp8390overflow,			/* overflow */

	0x300,				/* addr */
	2,				/* irq */
	1,				/* bit16 */

	0,				/* ram */
	0x4000,				/* ramstart */
	0x4000+16*1024,			/* ramstop */

	0x300,				/* dp8390 */
	0x300+Data,			/* data */
	0,				/* software bndry */
	0x4000/Dp8390BufSz,		/* tstart */
	0x4600/Dp8390BufSz,		/* pstart */
	0x8000/Dp8390BufSz,		/* pstop */
.
99,101c
	dp8390read,			/* read */
	dp8390write,			/* write */
.
95,97c
	reset,				/* reset */
	0,				/* init */
	dp8390attach,			/* attach */
	dp8390mode,			/* mode */
.
85,93c
Card ether2000 = {
	"NE2000",			/* ident */
.
75,81d
65d
63c
	if(ctlr->card.io >= 0x380)
.
60c
		if((buf[0x0E] & 0xFF) == 0x57 && (buf[0x0F] & 0xFF) == 0x57)
.
55,56c
		ctlr->card.dp8390 = ctlr->card.io;
		ctlr->card.data = ctlr->card.io+Data;
.
44c
		outb(ctlr->card.io+Reset, inb(ctlr->card.io+Reset));
.
39c
	for(ctlr->card.io = 0x300; ctlr->card.io < 0x380; ctlr->card.io += 0x20){
.
31d
20c
 * The NE2000 is really just a DP83901 plus a data port
.
18c
 * AT evaluation cards.
.
## diffname pc/ether2000.c 1993/0216
## diff -e /n/bootesdump/1993/0212/sys/src/9/pc/ether2000.c /n/bootesdump/1993/0216/sys/src/9/pc/ether2000.c
43c
		buf[0] = inb(ctlr->card.io+Reset);
		delay(2);
		outb(ctlr->card.io+Reset, buf[0]);
.
## diffname pc/ether2000.c 1993/0223
## diff -e /n/bootesdump/1993/0216/sys/src/9/pc/ether2000.c /n/bootesdump/1993/0223/sys/src/9/pc/ether2000.c
20c
 * The NE2000 is really just a DP8390[12] plus a data port
.
## diffname pc/ether2000.c 1993/0915
## diff -e /n/bootesdump/1993/0223/sys/src/9/pc/ether2000.c /n/fornaxdump/1993/0915/sys/src/brazil/pc/ether2000.c
78,109c
void
ether2000link(void)
{
	addethercard("NE2000", ne2000reset);
}
.
65a

.
47,64c
	ctlr->card.reset = ne2000reset;
	ctlr->card.attach = dp8390attach;
	ctlr->card.mode = dp8390mode;
	ctlr->card.read = dp8390read;
	ctlr->card.write = dp8390write;
	ctlr->card.receive = dp8390receive;
	ctlr->card.transmit = dp8390transmit;
	ctlr->card.intr = dp8390intr;
	ctlr->card.watch = dp8390watch;
	ctlr->card.overflow = dp8390overflow;

	ctlr->card.bit16 = 1;
	ctlr->card.dp8390 = ctlr->card.port;
	ctlr->card.data = ctlr->card.port+Data;

	ctlr->card.tstart = HOWMANY(ctlr->card.mem, Dp8390BufSz);
	ctlr->card.pstart = ctlr->card.tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
	ctlr->card.pstop = ctlr->card.tstart + HOWMANY(ctlr->card.size, Dp8390BufSz);

	/*
	 * Reset the board. This is done by doing a read
	 * followed by a write to the Reset address.
	 */
	buf[0] = inb(ctlr->card.port+Reset);
	delay(2);
	outb(ctlr->card.port+Reset, buf[0]);
	
	/*
	 * Init the (possible) chip, then use the (possible)
	 * chip to read the (possible) PROM for ethernet address
	 * and a marker byte.
	 * We could just look at the DP8390 command register after
	 * initialisation has been tried, but that wouldn't be
	 * enough, there are other ethernet boards which could
	 * match.
	 */
	dp8390reset(ctlr);
	memset(buf, 0, sizeof(buf));
	dp8390read(ctlr, buf, 0, sizeof(buf));
	if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57)
.
38,45c
	if(ctlr->card.port == 0)
		ctlr->card.port = 0x300;
	if(ctlr->card.irq == 0)
		ctlr->card.irq = 2;
	if(ctlr->card.mem == 0)
		ctlr->card.mem = 0x4000;
	if(ctlr->card.size == 0)
		ctlr->card.size = 16*1024;
.
35,36c
	 * Set up the software configuration.
	 * Use defaults for port, irq, mem and size
	 * if not specified.
.
28,29c
int
ne2000reset(Ctlr *ctlr)
.
## diffname pc/ether2000.c 1994/0128
## diff -e /n/fornaxdump/1993/0915/sys/src/brazil/pc/ether2000.c /n/fornaxdump/1994/0128/sys/src/brazil/pc/ether2000.c
105c
	addethercard("NE2000", reset);
.
98a
	dp8390setea(ether);

.
95,97c
	if((ether->ea[0]|ether->ea[1]|ether->ea[2]|ether->ea[3]|ether->ea[4]|ether->ea[5]) == 0){
		for(i = 0; i < sizeof(ether->ea); i++)
			ether->ea[i] = buf[i];
	}
.
88a
	}
.
86,87c
	dp8390read(dp8390, buf, 0, sizeof(buf));
	if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57){
		free(ether->private);
.
84c
	dp8390reset(ether);
.
73c
	outb(port+Reset, buf[0]);
.
71c
	buf[0] = inb(port+Reset);
.
63,65c
	dp8390->tstart = HOWMANY(ether->mem, Dp8390BufSz);
	dp8390->pstart = dp8390->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
	dp8390->pstop = dp8390->tstart + HOWMANY(ether->size, Dp8390BufSz);
.
59,61c
	dp8390->dp8390 = port;
	dp8390->data = port+Data;
.
48,57c
	ether->private = malloc(sizeof(Dp8390));
	dp8390 = ether->private;
	dp8390->bit16 = 1;
	dp8390->ram = 0;
.
39,46c
	if(ether->port == 0)
		ether->port = 0x300;
	if(ether->irq == 0)
		ether->irq = 2;
	if(ether->mem == 0)
		ether->mem = 0x4000;
	if(ether->size == 0)
		ether->size = 16*1024;
	port = ether->port;
.
31a
	ulong port;
	Dp8390 *dp8390;
.
28,29c
static int
reset(Ether *ether)
.
10c
#include "etherif.h"
.
8c
#include "../port/error.h"
#include "../port/netif.h"
.
6d
## diffname pc/ether2000.c 1995/0721
## diff -e /n/fornaxdump/1994/0128/sys/src/brazil/pc/ether2000.c /n/fornaxdump/1995/0721/sys/src/brazil/pc/ether2000.c
84c
		free(ether->ctlr);
.
51,52c
	ether->ctlr = malloc(sizeof(Dp8390));
	dp8390 = ether->ctlr;
.
## diffname pc/ether2000.c 1995/0922
## diff -e /n/fornaxdump/1995/0721/sys/src/brazil/pc/ether2000.c /n/fornaxdump/1995/0922/sys/src/brazil/pc/ether2000.c
69a
	delay(2);
.
25c
	Reset		= 0x1F,		/* offset from I/O base of reset port */
.
## diffname pc/ether2000.c 1997/0327
## diff -e /n/fornaxdump/1995/0922/sys/src/brazil/pc/ether2000.c /n/emeliedump/1997/0327/sys/src/brazil/pc/ether2000.c
98d
94c
	memset(ea, 0, Eaddrlen);
	if(memcmp(ea, ether->ea, Eaddrlen) == 0){
.
90,92c
	 * Stupid machine. Shorts were asked for,
	 * shorts were delivered, although the PROM is a byte array.
	 * Set the ethernet address.
.
83c
	dp8390read(ctlr, buf, 0, sizeof(buf));
.
76c
	 * Could just look at the DP8390 command register after
.
62a
	ctlr->dummyrr = 1;
	for(i = 0; i < ether->nopt; i++){
		if(strcmp(ether->opt[i], "nodummyrr"))
			continue;
		ctlr->dummyrr = 0;
		break;
	}

.
59,61c
	ctlr->tstart = HOWMANY(ether->mem, Dp8390BufSz);
	ctlr->pstart = ctlr->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
	ctlr->pstop = ctlr->tstart + HOWMANY(ether->size, Dp8390BufSz);
.
56,57c
	ctlr->port = port;
	ctlr->data = port+Data;
.
52,54c
	ctlr = ether->ctlr;
	ctlr->width = 2;
	ctlr->ram = 0;
.
34a
	uchar ea[Eaddrlen];
.
33c
	Dp8390 *ctlr;
.
29c
reset(Ether* ether)
.
10a
#include "ether8390.h"
.
## diffname pc/ether2000.c 1999/0714
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/ether2000.c /n/emeliedump/1999/0714/sys/src/brazil/pc/ether2000.c
94a
		iofree(ether->port);
.
52a
	if(ioalloc(ether->port, 0x20, 0, "ne2000") < 0)
		return -1;

.
## diffname pc/ether2000.c 2002/0403
## diff -e /n/emeliedump/1999/0714/sys/src/brazil/pc/ether2000.c /n/emeliedump/2002/0403/sys/src/9/pc/ether2000.c
31a
	static int first;
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.