/* atp.c: Diagnostic program for the AT-Lan-Tec pocket ethernet adaptor.

   Written 1993 by Donald Becker.

   The Author may be reached as becker@super.org or
   C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715

   This is a diagnostic program for the AT-Lan-Tec pocket ethernet adaptor.
   It doesn't test for specific hardware faults, but rather verifies the basic
   functionality of the board.  I wrote this primarily to get hands-on
   experience to understand how the hardware works.
*/

static char *version =
    "atp.c:v0.00 11/6/93 Donald Becker (becker@super.org)\n";

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <asm/io.h>
#include <sys/time.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include "/usr/src/linux/net/inet/dev.h"

struct option longopts[] = {
 /* { name  has_arg  *flag  val } */
    {"base-address", 1, 0, 'p'},
    {"all",	   0, 0, 'a'},	/* Print all registers. */
    {"dump",       0, 0, 'd'},	/* Dump the first page. */
    {"examine",    1, 0, 'e'},	/* Examine a specified page. */
    {"help",       0, 0, 'h'},	/* Give help */
    {"interface",  0, 0, 'f'},	/* Interface number (built-in, AUI) */
    {"irq",	   	   1, 0, 'i'},	/* Interrupt number */
    {"reset ASIC", 0, 0, 'r'},	/* Reset the ASIC before doing anything. */
    {"verbose",    0, 0, 'v'},	/* Verbose mode */
    {"version",    0, 0, 'V'},	/* Display version number */
    {"write-EEPROM", 1, 0, 'w'},/* Write the EEPROM with the specified vals */
    { 0, 0, 0, 0 }
};

#define printk printf

int verbose = 0;
#ifdef notdef
struct device {
    char *name;
    short base_addr;
    unsigned char irq;
    unsigned char if_port;
    unsigned char dev_addr[6];	/* Hardware station address. */
    unsigned int tbusy:1, interrupt:1, start:1;
	void *priv;
} devs, *dev = &devs;
#else
struct device devs, *dev = &devs;
#endif
struct device *irq2dev_map[16] = {0, /* ... */};

int net_debug = 7;
int jiffies;

#ifdef notdef
struct net_local {
    struct enet_statistics stats;
	long open_time;
} lps, *lp = &lps;
#endif

unsigned char fake_packet[100];

void get_node_ID(struct device *dev);
int ram_test_0(short ioaddr, int num_words);


int
main(int argc, char **argv)
{
    int port_base = 0x378, irq = -1;
    int errflag = 0, shared_mode = 0;
    int write_eeprom = 0, interface = -1, all_regs = 0, dump = 0;
	int examine = -1, reset_asic = 0;
    int c, longind;
    extern char *optarg;
	short ioaddr;
	int i;

    while ((c = getopt_long(argc, argv, "ae:f:i:p:rsdvw", longopts, &longind))
	   != -1)
	switch (c) {
	case 'e':
	    examine = atoi(optarg);
	    break;
	case 'f':
	    interface = atoi(optarg);
	    break;
	case 'i':
	    irq = atoi(optarg);
	    break;
	case 'p':
	    port_base = strtol(optarg, NULL, 16);
	    break;
	case 'd': dump++; break;
	case 'r': reset_asic++; break;
	case 's': shared_mode++; break;
	case 'v': verbose++;		 break;
	case 'w': write_eeprom++;	 break;
	case 'a': all_regs++;		 break;
	case '?':
	    errflag++;
	}
    if (errflag) {
		fprintf(stderr, "usage:");
		return 2;
    }

    if (verbose)
		printf(version);

    dev->name = "ATP";
	dev->base_addr = ioaddr = port_base;
/*    dev->priv = lp;*/
    
    if (ioperm(port_base, 4, 1) < 0
		|| ioperm(0x80, 1, 1)) { 		/* Needed for SLOW_DOWN_IO */
		perror("ethertest: ioperm()");
		return 1;
    }

	printf("  AT-Lan-Tec Pocket Ethernet adaptor test at %#x.\n",
		   dev->base_addr);
    atp_probe(ioaddr);
	ram_test_0(ioaddr, 0x4004);
    get_node_ID(dev);
	return 0;
}


/*
 * Local variables:
 *  compile-command: "cc -N -O -Wall -o atp atp.c"
 *  tab-width: 4
 * End:
 */
