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

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


## diffname pc/etherec2t.c 2000/0524
## diff -e /dev/null /n/emeliedump/2000/0524/sys/src/9/pc/etherec2t.c
0a
/*
 * Linksys Combo PCMCIA EthernetCard (EC2T).
 * Supposedly an NE2000 clone, see the comments in ether2000.c
 */
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"
#include "../port/netif.h"

#include "etherif.h"
#include "ether8390.h"
enum {
	Data		= 0x10,		/* offset from I/O base of data port */
	Reset		= 0x1F,		/* offset from I/O base of reset port */
};

static int
reset(Ether* ether)
{
	ushort buf[16];
	ulong port;
	Dp8390 *ctlr;
	int i, slot;
	uchar ea[Eaddrlen];

	/*
	 * Set up the software configuration.
	 * Use defaults for port, irq, mem and size
	 * if not specified.
	 * The manual says 16KB memory, the box
	 * says 32KB. The manual seems to be correct.
	 */
	if(ether->port == 0)
		ether->port = 0x300;
	if(ether->irq == 0)
		ether->irq = 9;
	if(ether->mem == 0)
		ether->mem = 0x4000;
	if(ether->size == 0)
		ether->size = 16*1024;
	port = ether->port;

	if(ioalloc(ether->port, 0x20, 0, "ec2t") < 0)
		return -1;
	if((slot = pcmspecial(ether->type, ether)) < 0){
		iofree(port);
		return -1;
	}

	ether->ctlr = malloc(sizeof(Dp8390));
	ctlr = ether->ctlr;
	ctlr->width = 2;
	ctlr->ram = 0;

	ctlr->port = port;
	ctlr->data = port+Data;

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

	ctlr->dummyrr = 1;
	for(i = 0; i < ether->nopt; i++){
		if(strcmp(ether->opt[i], "nodummyrr"))
			continue;
		ctlr->dummyrr = 0;
		break;
	}

	/*
	 * Reset the board. This is done by doing a read
	 * followed by a write to the Reset address.
	 */
	buf[0] = inb(port+Reset);
	delay(2);
	outb(port+Reset, buf[0]);
	delay(2);
	
	/*
	 * Init the (possible) chip, then use the (possible)
	 * chip to read the (possible) PROM for ethernet address
	 * and a marker byte.
	 * 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(ether);
	memset(buf, 0, sizeof(buf));
	dp8390read(ctlr, buf, 0, sizeof(buf));
	if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57){
		pcmspecialclose(slot);
		iofree(ether->port);
		free(ether->ctlr);
		return -1;
	}

	/*
	 * Stupid machine. Shorts were asked for,
	 * shorts were delivered, although the PROM is a byte array.
	 * Set the ethernet address.
	 */
	memset(ea, 0, Eaddrlen);
	if(memcmp(ea, ether->ea, Eaddrlen) == 0){
		for(i = 0; i < sizeof(ether->ea); i++)
			ether->ea[i] = buf[i];
	}
	dp8390setea(ether);

	return 0;
}

void
etherec2tlink(void)
{
	addethercard("EC2T", reset);
}
.
## diffname pc/etherec2t.c 2000/0604
## diff -e /n/emeliedump/2000/0524/sys/src/9/pc/etherec2t.c /n/emeliedump/2000/0604/sys/src/9/pc/etherec2t.c
93,95c
	sum = 0;
	if(strcmp(type, "PCMPC100")){
		memset(buf, 0, sizeof(buf));
		dp8390read(ctlr, buf, 0, sizeof(buf));
		if((buf[0x0E] & 0xFF) == 0x57 && (buf[0x0F] & 0xFF) == 0x57)
			sum = 0xFF;
	}
	else{
		/*
		 * The PCMPC100 has the ethernet address in I/O space.
		 * There's a checksum over 8 bytes which sums to 0xFF.
		 */
		for(i = 0; i < 8; i++){
			x = inb(port+0x14+i);
			sum += x;
			buf[i] = (x<<8)|x;
		}
	}
	if(sum != 0xFF){
.
82c

.
49c
	slot = -1;
	type = nil;
	for(i = 0; ec2tpcmcia[i] != nil; i++){
		type = ec2tpcmcia[i];
		if((slot = pcmspecial(type, ether)) >= 0)
			break;
	}
	if(slot < 0){
.
28c
	uchar ea[Eaddrlen], sum, x;
	char *type;
.
20a
static char* ec2tpcmcia[] = {
	"EC2T",
	"PCMPC100",
	nil,
};

.
15a

.
2,3c
 * Linksys Combo PCMCIA EthernetCard (EC2T)
 * and EtherFast 10/100 PC Card (PCMPC100).
 * Supposedly NE2000 clones, see the comments in ether2000.c
.
## diffname pc/etherec2t.c 2000/0605
## diff -e /n/emeliedump/2000/0604/sys/src/9/pc/etherec2t.c /n/emeliedump/2000/0605/sys/src/9/pc/etherec2t.c
82,88c
	ctlr->dummyrr = 0;
.
## diffname pc/etherec2t.c 2000/0615
## diff -e /n/emeliedump/2000/0605/sys/src/9/pc/etherec2t.c /n/emeliedump/2000/0615/sys/src/9/pc/etherec2t.c
119a
	}
	else{
		memset(buf, 0, sizeof(buf));
		dp8390read(ctlr, buf, 0, sizeof(buf));
		if((buf[0x0E] & 0xFF) == 0x57 && (buf[0x0F] & 0xFF) == 0x57)
			sum = 0xFF;
.
104,110c
	if(cistrcmp(type, "PCMPC100") == 0){
.
82a
	for(i = 0; i < ether->nopt; i++){
		if(cistrcmp(ether->opt[i], "nodummyrr") == 0)
			ctlr->dummyrr = 0;
		else if(cistrncmp(ether->opt[i], "dummyrr=", 8) == 0)
			ctlr->dummyrr = strtol(&ether->opt[i][8], nil, 0);
	}
.
64a
	if(ec2tpcmcia[i] == nil){
		for(i = 0; i < ether->nopt; i++){
			if(cistrncmp(ether->opt[i], "id=", 3))
				continue;
			type = &ether->opt[i][3];
			if((slot = pcmspecial(type, ether)) >= 0)
				break;
		}
	}
.
24,25c
	"EC2T",				/* Linksys Combo PCMCIA EthernetCard */
	"PCMPC100",			/* EtherFast 10/100 PC Card */
	"EN2216",			/* Accton EtherPair-PCMCIA */
.
2,4c
 * Supposed NE2000 PCMCIA clones, see the comments in ether2000.c
.
## diffname pc/etherec2t.c 2000/0825
## diff -e /n/emeliedump/2000/0615/sys/src/9/pc/etherec2t.c /n/emeliedump/2000/0825/sys/src/9/pc/etherec2t.c
118c
	if(cistrcmp(type, "PCMPC100") == 0 || cistrcmp(type, "FA410TX") == 0){
.
24a
	"FA410TX",			/* Netgear FA410TX */
.
## diffname pc/etherec2t.c 2001/0503
## diff -e /n/emeliedump/2000/0825/sys/src/9/pc/etherec2t.c /n/emeliedump/2001/0503/sys/src/9/pc/etherec2t.c
121c
		 * These NICs have the ethernet address in I/O space.
.
119c
	if(cistrcmp(type, "PCMPC100") == 0 || cistrcmp(type, "PCM100") == 0 || cistrcmp(type, "FA410TX") == 0){
.
23a
	"PCM100",			/* EtherFast 10/100 Integrated PC Card */
.
## diffname pc/etherec2t.c 2001/0527
## diff -e /n/emeliedump/2001/0503/sys/src/9/pc/etherec2t.c /n/emeliedump/2001/0527/sys/src/9/pc/etherec2t.c
122c
		 * The PCMPC100 has the ethernet address in I/O space.
.
120c
	if(cistrcmp(type, "PCMPC100") == 0 || cistrcmp(type, "FA410TX") == 0){
.
24d
## diffname pc/etherec2t.c 2001/0726
## diff -e /n/emeliedump/2001/0527/sys/src/9/pc/etherec2t.c /n/emeliedump/2001/0726/sys/src/9/pc/etherec2t.c
25a
	"Network Everywhere",		/* Linksys NP10T 10BaseT Card */
.
## diffname pc/etherec2t.c 2001/1005
## diff -e /n/emeliedump/2001/0726/sys/src/9/pc/etherec2t.c /n/emeliedump/2001/1005/sys/src/9/pc/etherec2t.c
122c
		 * These cards have the ethernet address in I/O space.
.
120c
	if(ec2t->iochecksum){
.
68,72c
			if(cistrncmp(ether->opt[i], "id=", 3) == 0){
				ec2t->name = &ether->opt[i][3];
				slot = pcmspecial(ec2t->name, ether);
			}
			else if(cistrncmp(ether->opt[i], "iochecksum", 10) == 0)
				ec2t->iochecksum = 1;
.
66c
	if(ec2t->name == nil){
		ec2t = &tmpec2t;
		ec2t->name = nil;
		ec2t->iochecksum = 0;
.
60,63c
	for(ec2t = ec2tpcmcia; ec2t->name != nil; ec2t++){
		if((slot = pcmspecial(ec2t->name, ether)) >= 0)
.
38c
	Ec2t *ec2t, tmpec2t;
.
21,27c
typedef struct Ec2t {
	char*	name;
	int	iochecksum;
} Ec2t;

static Ec2t ec2tpcmcia[] = {
	{ "EC2T", 0, },			/* Linksys Combo PCMCIA EthernetCard */
	{ "PCMPC100", 1, },		/* EtherFast 10/100 PC Card */
	{ "EN2216", 0, },		/* Accton EtherPair-PCMCIA */
	{ "FA410TX", 1, },		/* Netgear FA410TX */
	{ "Network Everywhere", 0, },	/* Linksys NP10T 10BaseT Card */
	{ "10/100 Port Attached", 1, },	/* SMC 8040TX */
	{ nil, 0, },
.
## diffname pc/etherec2t.c 2001/1019
## diff -e /n/emeliedump/2001/1005/sys/src/9/pc/etherec2t.c /n/emeliedump/2001/1019/sys/src/9/pc/etherec2t.c
32a
	{ "FA411", 0 },			/* Netgear FA411 PCMCIA */
.
## diffname pc/etherec2t.c 2002/0429
## diff -e /n/emeliedump/2001/1019/sys/src/9/pc/etherec2t.c /n/emeliedump/2002/0429/sys/src/9/pc/etherec2t.c
28a
	{ "PCM100", 1, },	/* EtherFast PCM100 Card */
.

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.