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