File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / etc / nstat / enpstat.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:30 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21


/*	if_enp: ACC VERSAbus Ethernet controler (v/eiu)		*/
/*								*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>

#include <net/if.h>
#include <net/netisr.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/ip_var.h>
#include <netinet/if_ether.h>

#include <machine/mtpr.h>
#include <tahoeif/if_enp.h> 
#include <sys/buf.h>
#include <vba/vbavar.h>
#include <nlist.h>
#include "nstat.h"

struct	nlist	enpnl[] = {
#			define	N_ENPSOFTC	0	
	{ "_enp_softc"},
#			define	N_STATADDR	1
	{ "_stat_addr"},
#			define	N_NUMENP	2
	{ "_numenp" },
	{ "" },
};

#define NENP		6
struct 	enp_softc	enpsoftc[NENP];

extern	int	kmem;
extern	int	vmem;
extern	char	*system;
char	*vmemf = "/dev/vmem";
int	vmem;
ENPSTAT	enp_stats;

#define	STARTENP() sin = (struct sockaddr_in *)&(f->if_addr);\
		   if (sin->sin_addr.s_addr == 0) { \
			printf("enpstat: enp%d is not configured.\n", kk);\
			continue; \
		   }
#define ENDENP 	   putchar('\n');

enpstat(unit, from)
int unit, from;
{
	int	i, j, num;

	ENPSTAT			*s;
	long			stat_addr[NENP]; /* addrs of stat areas */
	struct 	enp_softc	*p;
	struct	ifnet		*f;
	struct	sockaddr_in	*sin;

	off_t	numdev_memaddr;
	off_t	stat_memaddr;
	off_t	enpsoftc_memaddr;

	int	kk;
	static	int	getvm = 0;

	if (!getvm) {
		nlist(system, enpnl);
		getvm = 1;
	}

	numdev_memaddr = enpnl[N_NUMENP].n_value;
	stat_memaddr = enpnl[N_STATADDR].n_value; /* versa bus address */
	enpsoftc_memaddr = enpnl[N_ENPSOFTC].n_value;

	if (numdev_memaddr==0 || stat_memaddr == 0 || enpsoftc_memaddr == 0) {
		printf("enpstat: symbol not in namelist\n");
		return(1);
	}

	klseek(kmem, numdev_memaddr, 0);
	read(kmem, (char *)&num, sizeof (num));

	if ((num < 0) || (num > NENP)) {  
		printf("enpstat: invalid number of devices (num = %d)\n", num);
		return(1);
	}
	if (num == 0) {  
		printf("enpstat: no enp (driver) installed.\n");
		return(1);
	}

	if (unit > num)
		if (unit == WILDCARD)
			unit = 0;	/* print all	*/
		else {
			printf("enpstat: invalid device no.(unit=%d)\n", unit);
			return;
		}
	else
		num = unit + 1;		/* print only once for dev-> unit */

	if (!from) {
		klseek(kmem, enpsoftc_memaddr, 0);
		read(kmem, enpsoftc, sizeof(struct enp_softc)*num);
	}

	klseek(kmem, stat_memaddr, 0);
	read(kmem, (char *)stat_addr, sizeof(long)*num);

	vmem = open(vmemf, 0);
	if (vmem < 0) {
		printf("enpstat: cannot open ");
		perror(vmemf);
		return(1);
	}

	if (from)
		return(0);	/* don't output */

	for (kk = unit; kk < num; kk++) {
		lseek(vmem, (off_t)stat_addr[kk], 0);
		read(vmem, (char *)&enp_stats, sizeof(ENPSTAT));
		p = &enpsoftc[kk];
		f = &p->es_if;
		s = (ENPSTAT *)&enp_stats;

		printf("--------------------------------\n");
		STARTENP();
			printf("Device Name: %s%d", "enp", f->if_unit);
			printf("\t\tEthernet Station Address: ");
			for (j=0; j<6; j++)
				printf("%x.",p->es_enaddr[j] & 0xff);
			printf("   ");
		ENDENP
	
		lseek(vmem, (off_t)stat_addr[kk], 0);
		read(vmem, (char *)&enp_stats, sizeof(ENPSTAT));

		STARTENP();
			printf("Transmit:%20d", s->e_xmit_successful);
			printf("\tReceive:%25d", s->e_rcv_successful);
		ENDENP

		STARTENP();
			printf("Multiple Retries:%12d", s->e_mult_retry);
			printf("\tMissed Packets(out of buf):%6d",
				s->e_rcv_missed);
		ENDENP
	
		STARTENP();
			printf("Single Retries:%14d", s->e_one_retry);
			printf("\tCRC Errors:%22d", s->e_crc_err);
		ENDENP
	
		STARTENP();
			printf("Retry Failures:%14d", s->e_fail_retry);
			printf("\tFraming Errors:%18d", s->e_frame_err);
		ENDENP
	
		STARTENP();
			printf("Late Collision:%14d", s->e_late_coll);
		ENDENP

		STARTENP();
			printf("No. of Collisions:%11d",
			 	s->e_mult_retry+s->e_one_retry+s->e_late_coll);
		ENDENP
	
		STARTENP();
			printf("Deferals on Xmit:%12d", s->e_deferrals);
		ENDENP
	
		STARTENP();
			printf("Transmit BUF Errors*:%8d", s->e_xmit_buff_err);
			printf("\tReceive BUF Errors*:%13d", s->e_rcv_buff_err);
		ENDENP

		STARTENP();
			printf("Underrun Errors:%13d", s->e_silo_underrun);
			printf("\tOverrun Errors:%18d", s->e_silo_overrun);
		ENDENP

		STARTENP();
			printf("Carriers Losses*:%12d", s->e_lost_carrier);
		ENDENP
	
		STARTENP();
			printf("Babbling Xmitter Errors:%5d", s->e_babble);
		ENDENP
	
		STARTENP();
			printf("Memory Errors* (Xmit):%7d", s->e_xmit_mem_err);
			printf("\tMemory Errors* (Recv):%11d", 
				s->e_rcv_mem_err);
		ENDENP
		printf("--------------------------------\n");
		printf("* Fatal Errors. Controller has to be reloaded.\n");
	}
	close(vmem);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.