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