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