123229Smckusick /* 2*29302Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323229Smckusick * All rights reserved. The Berkeley software License Agreement 423229Smckusick * specifies the terms and conditions for redistribution. 523229Smckusick * 6*29302Smckusick * @(#)imptst.c 7.1 (Berkeley) 06/05/86 723229Smckusick */ 89805Ssam 97328Ssam #include "../h/param.h" 109186Ssam #include "../h/inode.h" 119186Ssam 129186Ssam #include "../vaxuba/ubareg.h" 139186Ssam #include "../netinet/in.h" 149186Ssam #include "../netinet/in_systm.h" 157328Ssam #define IMPLEADERS 169186Ssam #include "../netimp/if_imp.h" 179186Ssam #include "../vaxif/if_acc.h" 189186Ssam 197328Ssam #include "saio.h" 207328Ssam #include "savax.h" 217328Ssam 227328Ssam #define min(a,b) (a<b ? a : b) 237328Ssam #define BUFSIZ 512 247328Ssam 257328Ssam char input[132]; 267328Ssam struct imp_leader imps, *ip = &imps; 277328Ssam char inbuf[BUFSIZ]; 287328Ssam int writeflg = 0; 297328Ssam 307328Ssam main() 317328Ssam { 327328Ssam register error = 0, i, len; 337328Ssam short type, host, impno, link; 347328Ssam register struct accdevice *addr = 357328Ssam (struct accdevice *)ubamem(0, 0767700); 367328Ssam 377328Ssam printf("imp interface diagnostic\n"); 387328Ssam printf("read or write test(r or w)? "); 397328Ssam gets(input); 407328Ssam while (*input != 'r' && *input != 'w') { 417328Ssam printf("reply r or w: "); 427328Ssam gets(input); 437328Ssam } 447328Ssam if (*input == 'w') { 457328Ssam writeflg++; 467328Ssam printf("enter destination host number: "); 477328Ssam gets(input); 487328Ssam while ((host = (short)atol(input)) < 0 || host > 255) { 497328Ssam printf("range [0, 255], re-enter: "); 507328Ssam gets(input); 517328Ssam } 527328Ssam printf("imp number: "); 537328Ssam gets(input); 547328Ssam while ((impno = (short)atol(input)) < 0 || impno > 32767) { 557328Ssam printf("range [0, 32767], re-enter: "); 567328Ssam gets(input); 577328Ssam } 587328Ssam printf("link number: "); 597328Ssam gets(input); 607328Ssam while ((link = (short)atol(input)) < 0 || link > 255) { 617328Ssam printf("range [0, 255], re-enter: "); 627328Ssam gets(input); 637328Ssam } 647328Ssam } 657328Ssam printf("initialization starting...\n"); 667328Ssam impinit(); 677328Ssam /* send 3 noops and init imp leader buffer */ 687328Ssam impnoops((struct control_leader *)ip); 697328Ssam printf("initialization complete\n"); 707328Ssam if (writeflg) { 717328Ssam printf("starting write test...\n"); 727328Ssam ip->il_host = host; 737328Ssam ip->il_imp = htons((u_short)impno); 747328Ssam ip->il_link = link; 757328Ssam while (!error) 767328Ssam error = impwrite(ip, sizeof (*ip)); 777328Ssam printf("imp write error, ocsr=%b\n", (short)error, 787328Ssam ACC_OUTBITS); 797328Ssam } else { 807328Ssam printf("starting read test...\n"); 817328Ssam while (!error) { 827328Ssam printf("impread(%d)\n", sizeof (*ip)); 837328Ssam error = impread(ip, sizeof (*ip)); 847328Ssam printf("impread, error=%b\n", error, ACC_INBITS); 857328Ssam printleader(ip); 867328Ssam len = ntohs(ip->il_length); 877328Ssam printf("length=%d\n", len); 887328Ssam /* read any data */ 897328Ssam while ((error & IN_EOM) == 0 && 907328Ssam (error & ~IN_EOM) == 0 && len > 0) { 917328Ssam i = min(len, BUFSIZ); 927328Ssam printf("impread(%d)\n", i); 937328Ssam error = impread(inbuf, i); 947328Ssam len -= i; 957328Ssam printf("error=%b, len=%d\n", error, ACC_INBITS, len); 967328Ssam } 977328Ssam error &= ~IN_EOM; 987328Ssam if (error == 0 && (len > 0 || addr->iwc)) 997328Ssam printf("imp input length mismatch\n"); 1007328Ssam } 1017328Ssam printf("imp read error, icsr=%b\n", (short)error, ACC_INBITS); 1027328Ssam } 1037328Ssam printf("...imptest exiting\n"); 1047328Ssam } 1057328Ssam 1067328Ssam impnoops(cp) 1077328Ssam register struct control_leader *cp; 1087328Ssam { 1097328Ssam register i, error; 1107328Ssam 1117328Ssam bzero((caddr_t)cp, sizeof (struct control_leader)); 1127328Ssam cp->dl_format = IMP_NFF; 1137328Ssam cp->dl_mtype = IMPTYPE_NOOP; 1147328Ssam for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 1157328Ssam cp->dl_link = i; 1167328Ssam if ((error = impwrite(ip, sizeof (*ip))) != 0) { 1177328Ssam printf("imp init error, ocsr=%b\n", (short)error, 1187328Ssam ACC_OUTBITS); 1197328Ssam _stop(); 1207328Ssam } 1217328Ssam } 1227328Ssam } 1237328Ssam 1247328Ssam impwrite(buf, len) 1257328Ssam register struct imp *buf; 1267328Ssam register len; 1277328Ssam { 1287328Ssam register uba, error; 1297328Ssam struct iob io; 1307328Ssam register struct accdevice *addr = 1317328Ssam (struct accdevice *)ubamem(0, 0767600); 1327328Ssam 1337328Ssam /* set up uba mapping */ 1347328Ssam io.i_ma = (caddr_t)buf; 1357328Ssam io.i_cc = len; 1367328Ssam uba = ubasetup(&io, 0); 1377328Ssam 1387328Ssam /* set regs and perform i/o */ 1397328Ssam addr->oba = (u_short)uba; 1407328Ssam addr->owc = -((io.i_cc + 1) >> 1); 1417328Ssam addr->ocsr = ((short) ((uba & 0x30000) >> 12) | OUT_ENLB | ACC_GO); 1427328Ssam while ((addr->ocsr & ACC_RDY) == 0) 1437328Ssam ; 1447328Ssam error = addr->ocsr & (ACC_NXM|ACC_ERR); 1457328Ssam ubafree(uba); 1467328Ssam return(error); 1477328Ssam } 1487328Ssam 1497328Ssam impread(buf, len) 1507328Ssam register struct imp *buf; 1517328Ssam register len; 1527328Ssam { 1537328Ssam register uba, error; 1547328Ssam struct iob io; 1557328Ssam register struct accdevice *addr = 1567328Ssam (struct accdevice *)ubamem(0, 0767600); 1577328Ssam 1587328Ssam /* set up uba mapping */ 1597328Ssam io.i_ma = (caddr_t)buf; 1607328Ssam io.i_cc = len; 1617328Ssam uba = ubasetup(&io, 0); 1627328Ssam /* set regs and perform i/o */ 1637328Ssam addr->iba = (u_short)uba; 1647328Ssam addr->iwc = -(io.i_cc >> 1); 1657328Ssam addr->icsr = IN_MRDY | IN_WEN | ((uba & 0x30000) >> 12) | ACC_GO; 1667328Ssam while ((addr->icsr & ACC_RDY) == 0) 1677328Ssam ; 1687328Ssam error = addr->icsr & (IN_EOM|ACC_ERR|IN_RMR|ACC_NXM); 1697328Ssam ubafree(uba); 1707328Ssam return(error); 1717328Ssam } 1727328Ssam 1737328Ssam impinit() 1747328Ssam { 1757328Ssam register struct accdevice *addr = 1767328Ssam (struct accdevice *)ubamem(0, 0767600); 1777328Ssam register int i; 1787328Ssam 1797328Ssam /* 1807328Ssam * Reset the imp interface; 1817328Ssam * the delays are pure guesswork. 1827328Ssam */ 1837328Ssam addr->icsr = ACC_RESET; DELAY(5000); 1847328Ssam addr->ocsr = ACC_RESET; DELAY(5000); 1857328Ssam addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */ 1867328Ssam addr->ocsr = 0; 1877328Ssam addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ 1887328Ssam DELAY(10000); 1897328Ssam /* YECH!!! */ 1907328Ssam for (i = 0; i < 500; i++) { 1917328Ssam if ((addr->icsr & IN_HRDY) && 1927328Ssam (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) 1937328Ssam return; 1947328Ssam addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); 1957328Ssam /* keep turning IN_RMR off */ 1967328Ssam } 1977328Ssam printf("imp doesn't respond, icsr=%b, ocsr=%b\n", 1987328Ssam addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS); 1997328Ssam } 2007328Ssam 2017328Ssam /* 2027328Ssam * Convert null-terminated ascii string to binary 2037328Ssam * and return value. 2047328Ssam * 1st char in string : 2057328Ssam * 0 -> octal 2067328Ssam * x -> hex 2077328Ssam * else decimal 2087328Ssam */ 2097328Ssam atol(as) 2107328Ssam register char *as; 2117328Ssam { 2127328Ssam register value = 0; 2137328Ssam register base = 10; 2147328Ssam register sign = 1; 2157328Ssam register digit = 0; 2167328Ssam 2177328Ssam aloop : 2187328Ssam if ((digit = (*as++)) == 0) 2197328Ssam return(value) ; /* null */ 2207328Ssam if (digit == '-') { 2217328Ssam sign = -sign; 2227328Ssam goto aloop ; 2237328Ssam } 2247328Ssam if (digit == '0') 2257328Ssam base = 8 ; 2267328Ssam else if (digit == 'x') 2277328Ssam base = 16 ; 2287328Ssam else 2297328Ssam value = digit - '0'; 2307328Ssam while (digit = (*as++)) { 2317328Ssam if (digit < '0') 2327328Ssam return(0); 2337328Ssam switch (base) { 2347328Ssam 2357328Ssam case 8 : 2367328Ssam if (digit > '7') 2377328Ssam return(0); 2387328Ssam digit -= '0'; 2397328Ssam break; 2407328Ssam 2417328Ssam case 10 : 2427328Ssam if (digit > '9') 2437328Ssam return(0); 2447328Ssam digit -= '0'; 2457328Ssam break; 2467328Ssam 2477328Ssam case 16 : 2487328Ssam if (digit <= '9') { 2497328Ssam digit -= 060 ; 2507328Ssam break; 2517328Ssam } 2527328Ssam if ((digit >= 'A') && (digit <= 'F')) { 2537328Ssam digit -= 'A' + 10; 2547328Ssam break; 2557328Ssam } 2567328Ssam if ((digit >= 'a') && (digit <= 'f')) { 2577328Ssam digit -= 'a' + 10 ; 2587328Ssam break; 2597328Ssam } 2607328Ssam return(0); 2617328Ssam } 2627328Ssam value = (value * base) + digit; 2637328Ssam } 2647328Ssam return (value * sign); 2657328Ssam } 2667328Ssam 2677328Ssam printleader(ip) 2687328Ssam register struct imp_leader *ip; 2697328Ssam { 2707328Ssam printbyte((char *)ip, 12); 2717328Ssam printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, 2727328Ssam ip->il_flags); 2737328Ssam if (ip->il_mtype <= IMPTYPE_READY) 2747328Ssam printf("%s,", impleaders[ip->il_mtype]); 2757328Ssam else 2767328Ssam printf("%x,", ip->il_mtype); 2777328Ssam printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, 2787328Ssam ntohs(ip->il_imp)); 2797328Ssam if (ip->il_link == IMPLINK_IP) 2807328Ssam printf("ip,"); 2817328Ssam else 2827328Ssam printf("%x,", ip->il_link); 2837328Ssam printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); 2847328Ssam } 2857328Ssam 2867328Ssam printbyte(cp, n) 2877328Ssam register char *cp; 2887328Ssam int n; 2897328Ssam { 2907328Ssam register i, j, c; 2917328Ssam 2927328Ssam for (i=0; i<n; i++) { 2937328Ssam c = *cp++; 2947328Ssam for (j=0; j<2; j++) 2957328Ssam putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); 2967328Ssam putchar(' '); 2977328Ssam } 2987328Ssam putchar('\n'); 2997328Ssam } 300