xref: /csrg-svn/sys/vax/stand/imptst.c (revision 7328)
1*7328Ssam #include "../h/param.h"
2*7328Ssam #include "../h/pte.h"
3*7328Ssam #include "../h/ubareg.h"
4*7328Ssam #include "../net/in.h"
5*7328Ssam #include "../net/in_systm.h"
6*7328Ssam #define	IMPLEADERS
7*7328Ssam #include "../net/if_imp.h"
8*7328Ssam #include "../net/if_acc.h"
9*7328Ssam #include "../h/inode.h"
10*7328Ssam #include "saio.h"
11*7328Ssam #include "savax.h"
12*7328Ssam 
13*7328Ssam #define min(a,b) (a<b ? a : b)
14*7328Ssam #define BUFSIZ 512
15*7328Ssam 
16*7328Ssam char	input[132];
17*7328Ssam struct	imp_leader imps, *ip = &imps;
18*7328Ssam char	inbuf[BUFSIZ];
19*7328Ssam int	writeflg = 0;
20*7328Ssam 
21*7328Ssam main()
22*7328Ssam {
23*7328Ssam 	register error = 0, i, len;
24*7328Ssam 	short type, host, impno, link;
25*7328Ssam 	register struct accdevice *addr =
26*7328Ssam 		(struct accdevice *)ubamem(0, 0767700);
27*7328Ssam 
28*7328Ssam 	printf("imp interface diagnostic\n");
29*7328Ssam 	printf("read or write test(r or w)? ");
30*7328Ssam 	gets(input);
31*7328Ssam 	while (*input != 'r' && *input != 'w') {
32*7328Ssam 		printf("reply r or w: ");
33*7328Ssam 		gets(input);
34*7328Ssam 	}
35*7328Ssam 	if (*input == 'w') {
36*7328Ssam 		writeflg++;
37*7328Ssam 		printf("enter destination host number: ");
38*7328Ssam 		gets(input);
39*7328Ssam 		while ((host = (short)atol(input)) < 0 || host > 255) {
40*7328Ssam 			printf("range [0, 255], re-enter: ");
41*7328Ssam 			gets(input);
42*7328Ssam 		}
43*7328Ssam 		printf("imp number: ");
44*7328Ssam 		gets(input);
45*7328Ssam 		while ((impno = (short)atol(input)) < 0 || impno > 32767) {
46*7328Ssam 			printf("range [0, 32767], re-enter: ");
47*7328Ssam 			gets(input);
48*7328Ssam 		}
49*7328Ssam 		printf("link number: ");
50*7328Ssam 		gets(input);
51*7328Ssam 		while ((link = (short)atol(input)) < 0 || link > 255) {
52*7328Ssam 			printf("range [0, 255], re-enter: ");
53*7328Ssam 			gets(input);
54*7328Ssam 		}
55*7328Ssam 	}
56*7328Ssam 	printf("initialization starting...\n");
57*7328Ssam 	impinit();
58*7328Ssam 	/* send 3 noops and init imp leader buffer */
59*7328Ssam 	impnoops((struct control_leader *)ip);
60*7328Ssam 	printf("initialization complete\n");
61*7328Ssam 	if (writeflg) {
62*7328Ssam 		printf("starting write test...\n");
63*7328Ssam 		ip->il_host = host;
64*7328Ssam 		ip->il_imp = htons((u_short)impno);
65*7328Ssam 		ip->il_link = link;
66*7328Ssam 		while (!error)
67*7328Ssam 			error = impwrite(ip, sizeof (*ip));
68*7328Ssam         	printf("imp write error, ocsr=%b\n", (short)error,
69*7328Ssam 			ACC_OUTBITS);
70*7328Ssam 	} else {
71*7328Ssam 		printf("starting read test...\n");
72*7328Ssam 		while (!error) {
73*7328Ssam printf("impread(%d)\n", sizeof (*ip));
74*7328Ssam 			error = impread(ip, sizeof (*ip));
75*7328Ssam printf("impread, error=%b\n", error, ACC_INBITS);
76*7328Ssam 			printleader(ip);
77*7328Ssam 			len = ntohs(ip->il_length);
78*7328Ssam printf("length=%d\n", len);
79*7328Ssam 			/* read any data */
80*7328Ssam 			while ((error & IN_EOM) == 0 &&
81*7328Ssam 			  (error & ~IN_EOM) == 0 && len > 0) {
82*7328Ssam 				i = min(len, BUFSIZ);
83*7328Ssam printf("impread(%d)\n", i);
84*7328Ssam 				error = impread(inbuf, i);
85*7328Ssam 				len -= i;
86*7328Ssam printf("error=%b, len=%d\n", error, ACC_INBITS, len);
87*7328Ssam 			}
88*7328Ssam 			error &= ~IN_EOM;
89*7328Ssam 			if (error == 0 && (len > 0 || addr->iwc))
90*7328Ssam 				printf("imp input length mismatch\n");
91*7328Ssam 		}
92*7328Ssam 		printf("imp read error, icsr=%b\n", (short)error, ACC_INBITS);
93*7328Ssam 	}
94*7328Ssam 	printf("...imptest exiting\n");
95*7328Ssam }
96*7328Ssam 
97*7328Ssam impnoops(cp)
98*7328Ssam 	register struct control_leader *cp;
99*7328Ssam {
100*7328Ssam 	register i, error;
101*7328Ssam 
102*7328Ssam 	bzero((caddr_t)cp, sizeof (struct control_leader));
103*7328Ssam 	cp->dl_format = IMP_NFF;
104*7328Ssam 	cp->dl_mtype = IMPTYPE_NOOP;
105*7328Ssam 	for (i = 0; i < IMP_DROPCNT + 1; i++ ) {
106*7328Ssam                 cp->dl_link = i;
107*7328Ssam 		if ((error = impwrite(ip, sizeof (*ip))) != 0) {
108*7328Ssam 			printf("imp init error, ocsr=%b\n", (short)error,
109*7328Ssam 				ACC_OUTBITS);
110*7328Ssam 			_stop();
111*7328Ssam 		}
112*7328Ssam 	}
113*7328Ssam }
114*7328Ssam 
115*7328Ssam impwrite(buf, len)
116*7328Ssam 	register struct imp *buf;
117*7328Ssam 	register len;
118*7328Ssam {
119*7328Ssam 	register uba, error;
120*7328Ssam 	struct iob io;
121*7328Ssam 	register struct accdevice *addr =
122*7328Ssam 	    (struct accdevice *)ubamem(0, 0767600);
123*7328Ssam 
124*7328Ssam 	/* set up uba mapping */
125*7328Ssam 	io.i_ma = (caddr_t)buf;
126*7328Ssam 	io.i_cc = len;
127*7328Ssam 	uba = ubasetup(&io, 0);
128*7328Ssam 
129*7328Ssam 	/* set regs and perform i/o */
130*7328Ssam 	addr->oba = (u_short)uba;
131*7328Ssam 	addr->owc = -((io.i_cc + 1) >> 1);
132*7328Ssam 	addr->ocsr = ((short) ((uba & 0x30000) >> 12) | OUT_ENLB | ACC_GO);
133*7328Ssam 	while ((addr->ocsr & ACC_RDY) == 0)
134*7328Ssam 		;
135*7328Ssam 	error = addr->ocsr & (ACC_NXM|ACC_ERR);
136*7328Ssam 	ubafree(uba);
137*7328Ssam 	return(error);
138*7328Ssam }
139*7328Ssam 
140*7328Ssam impread(buf, len)
141*7328Ssam 	register struct imp *buf;
142*7328Ssam 	register len;
143*7328Ssam {
144*7328Ssam 	register uba, error;
145*7328Ssam 	struct iob io;
146*7328Ssam 	register struct accdevice *addr =
147*7328Ssam 	    (struct accdevice *)ubamem(0, 0767600);
148*7328Ssam 
149*7328Ssam 	/* set up uba mapping */
150*7328Ssam 	io.i_ma = (caddr_t)buf;
151*7328Ssam 	io.i_cc = len;
152*7328Ssam 	uba = ubasetup(&io, 0);
153*7328Ssam 	/* set regs and perform i/o */
154*7328Ssam 	addr->iba = (u_short)uba;
155*7328Ssam 	addr->iwc = -(io.i_cc >> 1);
156*7328Ssam 	addr->icsr = IN_MRDY | IN_WEN | ((uba & 0x30000) >> 12) | ACC_GO;
157*7328Ssam 	while ((addr->icsr & ACC_RDY) == 0)
158*7328Ssam 		;
159*7328Ssam 	error = addr->icsr & (IN_EOM|ACC_ERR|IN_RMR|ACC_NXM);
160*7328Ssam 	ubafree(uba);
161*7328Ssam 	return(error);
162*7328Ssam }
163*7328Ssam 
164*7328Ssam impinit()
165*7328Ssam {
166*7328Ssam 	register struct accdevice *addr =
167*7328Ssam 		(struct accdevice *)ubamem(0, 0767600);
168*7328Ssam 	register int i;
169*7328Ssam 
170*7328Ssam 	/*
171*7328Ssam 	 * Reset the imp interface;
172*7328Ssam 	 * the delays are pure guesswork.
173*7328Ssam 	 */
174*7328Ssam 	addr->icsr = ACC_RESET; DELAY(5000);
175*7328Ssam         addr->ocsr = ACC_RESET; DELAY(5000);
176*7328Ssam 	addr->ocsr = OUT_BBACK;	DELAY(5000);	/* reset host master ready */
177*7328Ssam 	addr->ocsr = 0;
178*7328Ssam 	addr->icsr = IN_MRDY | IN_WEN;		/* close the relay */
179*7328Ssam 	DELAY(10000);
180*7328Ssam 	/* YECH!!! */
181*7328Ssam 	for (i = 0; i < 500; i++) {
182*7328Ssam 		if ((addr->icsr & IN_HRDY) &&
183*7328Ssam 		    (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0)
184*7328Ssam 			return;
185*7328Ssam 		addr->icsr = IN_MRDY | IN_WEN; DELAY(10000);
186*7328Ssam 		/* keep turning IN_RMR off */
187*7328Ssam 	}
188*7328Ssam 	printf("imp doesn't respond, icsr=%b, ocsr=%b\n",
189*7328Ssam 		addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS);
190*7328Ssam }
191*7328Ssam 
192*7328Ssam /*
193*7328Ssam  *  Convert null-terminated ascii string to binary
194*7328Ssam  *  and return value.
195*7328Ssam  *  1st char in string :
196*7328Ssam  *	0 -> octal
197*7328Ssam  *	x -> hex
198*7328Ssam  *	else decimal
199*7328Ssam  */
200*7328Ssam atol(as)
201*7328Ssam 	register char *as;
202*7328Ssam {
203*7328Ssam 	register value = 0;
204*7328Ssam 	register base = 10;
205*7328Ssam 	register sign = 1;
206*7328Ssam 	register digit = 0;
207*7328Ssam 
208*7328Ssam aloop :
209*7328Ssam 	if ((digit = (*as++)) == 0)
210*7328Ssam 		return(value) ; /* null */
211*7328Ssam 	if (digit == '-') {
212*7328Ssam 		sign = -sign;
213*7328Ssam 		goto aloop ;
214*7328Ssam 	}
215*7328Ssam 	if (digit == '0')
216*7328Ssam 		base = 8 ;
217*7328Ssam 	else if (digit == 'x')
218*7328Ssam 		base = 16 ;
219*7328Ssam 	else
220*7328Ssam 		value = digit - '0';
221*7328Ssam 	while (digit = (*as++)) {
222*7328Ssam 		if (digit < '0')
223*7328Ssam 			return(0);
224*7328Ssam 		switch (base) {
225*7328Ssam 
226*7328Ssam 		case 8 :
227*7328Ssam 			if (digit > '7')
228*7328Ssam 				return(0);
229*7328Ssam 			digit -= '0';
230*7328Ssam 			break;
231*7328Ssam 
232*7328Ssam 		case 10 :
233*7328Ssam 			if (digit > '9')
234*7328Ssam 				return(0);
235*7328Ssam 			digit -= '0';
236*7328Ssam 			break;
237*7328Ssam 
238*7328Ssam 		case 16 :
239*7328Ssam 			if (digit <= '9') {
240*7328Ssam 				digit -= 060 ;
241*7328Ssam 				break;
242*7328Ssam 			}
243*7328Ssam 			if ((digit >= 'A') && (digit <= 'F')) {
244*7328Ssam 				digit -= 'A' + 10;
245*7328Ssam 				break;
246*7328Ssam 			}
247*7328Ssam 			if ((digit >= 'a') && (digit <= 'f')) {
248*7328Ssam 				digit -= 'a' + 10 ;
249*7328Ssam 				break;
250*7328Ssam 			}
251*7328Ssam 			return(0);
252*7328Ssam 		}
253*7328Ssam 		value = (value * base) + digit;
254*7328Ssam 	}
255*7328Ssam 	return (value * sign);
256*7328Ssam }
257*7328Ssam 
258*7328Ssam printleader(ip)
259*7328Ssam 	register struct imp_leader *ip;
260*7328Ssam {
261*7328Ssam 	printbyte((char *)ip, 12);
262*7328Ssam 	printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network,
263*7328Ssam 		ip->il_flags);
264*7328Ssam 	if (ip->il_mtype <= IMPTYPE_READY)
265*7328Ssam 		printf("%s,", impleaders[ip->il_mtype]);
266*7328Ssam 	else
267*7328Ssam 		printf("%x,", ip->il_mtype);
268*7328Ssam 	printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host,
269*7328Ssam 		ntohs(ip->il_imp));
270*7328Ssam 	if (ip->il_link == IMPLINK_IP)
271*7328Ssam 		printf("ip,");
272*7328Ssam 	else
273*7328Ssam 		printf("%x,", ip->il_link);
274*7328Ssam 	printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3);
275*7328Ssam }
276*7328Ssam 
277*7328Ssam printbyte(cp, n)
278*7328Ssam 	register char *cp;
279*7328Ssam 	int n;
280*7328Ssam {
281*7328Ssam 	register i, j, c;
282*7328Ssam 
283*7328Ssam 	for (i=0; i<n; i++) {
284*7328Ssam 		c = *cp++;
285*7328Ssam 		for (j=0; j<2; j++)
286*7328Ssam 			putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]);
287*7328Ssam 		putchar(' ');
288*7328Ssam 	}
289*7328Ssam 	putchar('\n');
290*7328Ssam }
291