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