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