1 /* if_acc.c 4.17 82/06/14 */ 2 3 #include "acc.h" 4 #ifdef NACC > 0 5 6 /* 7 * ACC LH/DH ARPAnet IMP interface driver. 8 */ 9 10 #include "../h/param.h" 11 #include "../h/systm.h" 12 #include "../h/mbuf.h" 13 #include "../h/pte.h" 14 #include "../h/buf.h" 15 #include "../h/protosw.h" 16 #include "../h/socket.h" 17 #include "../h/ubareg.h" 18 #include "../h/ubavar.h" 19 #include "../h/cpu.h" 20 #include "../h/mtpr.h" 21 #include "../h/vmmac.h" 22 #include "../net/in.h" 23 #include "../net/in_systm.h" 24 #include "../net/if.h" 25 #include "../net/if_acc.h" 26 #include "../net/if_imp.h" 27 #include "../net/if_uba.h" 28 29 int accprobe(), accattach(), accrint(), accxint(); 30 struct uba_device *accinfo[NACC]; 31 u_short accstd[] = { 0 }; 32 struct uba_driver accdriver = 33 { accprobe, 0, accattach, 0, accstd, "acc", accinfo }; 34 #define ACCUNIT(x) minor(x) 35 36 int accinit(), accstart(), accreset(); 37 38 /* 39 * "Lower half" of IMP interface driver. 40 * 41 * Each IMP interface is handled by a common module which handles 42 * the IMP-host protocol and a hardware driver which manages the 43 * hardware specific details of talking with the IMP. 44 * 45 * The hardware portion of the IMP driver handles DMA and related 46 * management of UNIBUS resources. The IMP protocol module interprets 47 * contents of these messages and "controls" the actions of the 48 * hardware module during IMP resets, but not, for instance, during 49 * UNIBUS resets. 50 * 51 * The two modules are coupled at "attach time", and ever after, 52 * through the imp interface structure. Higher level protocols, 53 * e.g. IP, interact with the IMP driver, rather than the ACC. 54 */ 55 struct acc_softc { 56 struct ifnet *acc_if; /* pointer to IMP's ifnet struct */ 57 struct impcb *acc_ic; /* data structure shared with IMP */ 58 struct ifuba acc_ifuba; /* UNIBUS resources */ 59 struct mbuf *acc_iq; /* input reassembly queue */ 60 short acc_olen; /* size of last message sent */ 61 char acc_flush; /* flush remainder of message */ 62 } acc_softc[NACC]; 63 64 #define NACCDEBUG 10000 65 char accdebug[NACCDEBUG]; 66 int accdebugx; 67 68 /* 69 * Reset the IMP and cause a transmitter interrupt by 70 * performing a null DMA. 71 */ 72 accprobe(reg) 73 caddr_t reg; 74 { 75 register int br, cvec; /* r11, r10 value-result */ 76 register struct accdevice *addr = (struct accdevice *)reg; 77 78 COUNT(ACCPROBE); 79 #ifdef lint 80 br = 0; cvec = br; br = cvec; 81 accrint(0); accxint(0); 82 #endif 83 addr->icsr = ACC_RESET; DELAY(5000); 84 addr->ocsr = ACC_RESET; DELAY(5000); 85 addr->ocsr = OUT_BBACK; DELAY(5000); 86 addr->owc = 0; 87 addr->ocsr = ACC_IE | ACC_GO; DELAY(5000); 88 addr->ocsr = 0; 89 if (cvec && cvec != 0x200) /* transmit -> receive */ 90 cvec -= 4; 91 #ifdef ECHACK 92 br = 0x16; 93 #endif 94 return (1); 95 } 96 97 /* 98 * Call the IMP module to allow it to set up its internal 99 * state, then tie the two modules together by setting up 100 * the back pointers to common data structures. 101 */ 102 accattach(ui) 103 struct uba_device *ui; 104 { 105 register struct acc_softc *sc = &acc_softc[ui->ui_unit]; 106 register struct impcb *ip; 107 struct ifimpcb { 108 struct ifnet ifimp_if; 109 struct impcb ifimp_impcb; 110 } *ifimp; 111 112 COUNT(ACCATTACH); 113 if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0) 114 panic("accattach"); 115 sc->acc_if = &ifimp->ifimp_if; 116 ip = &ifimp->ifimp_impcb; 117 sc->acc_ic = ip; 118 ip->ic_init = accinit; 119 ip->ic_start = accstart; 120 sc->acc_ifuba.ifu_flags = UBA_CANTWAIT; 121 #ifdef notdef 122 sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP; 123 #endif 124 } 125 126 /* 127 * Reset interface after UNIBUS reset. 128 * If interface is on specified uba, reset its state. 129 */ 130 accreset(unit, uban) 131 int unit, uban; 132 { 133 register struct uba_device *ui; 134 struct acc_softc *sc; 135 136 COUNT(ACCRESET); 137 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 || 138 ui->ui_ubanum != uban) 139 return; 140 printf(" acc%d", unit); 141 sc = &acc_softc[unit]; 142 /* must go through IMP to allow it to set state */ 143 (*sc->acc_if->if_init)(unit); 144 } 145 146 /* 147 * Initialize interface: clear recorded pending operations, 148 * and retrieve, and initialize UNIBUS resources. Note 149 * return value is used by IMP init routine to mark IMP 150 * unavailable for outgoing traffic. 151 */ 152 accinit(unit) 153 int unit; 154 { 155 register struct acc_softc *sc; 156 register struct uba_device *ui; 157 register struct accdevice *addr; 158 int info, i; 159 160 COUNT(ACCINIT); 161 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) { 162 printf("acc%d: not alive\n", unit); 163 return (0); 164 } 165 sc = &acc_softc[unit]; 166 /* 167 * Header length is 0 since we have to passs 168 * the IMP leader up to the protocol interpretation 169 * routines. If we had the header length as 170 * sizeof(struct imp_leader), then the if_ routines 171 * would asssume we handle it on input and output. 172 */ 173 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0, 174 (int)btoc(IMPMTU)) == 0) { 175 printf("acc%d: can't initialize\n", unit); 176 ui->ui_alive = 0; 177 return (0); 178 } 179 addr = (struct accdevice *)ui->ui_addr; 180 181 /* 182 * Reset the imp interface; 183 * the delays are pure guesswork. 184 */ 185 addr->ocsr = ACC_RESET; DELAY(5000); 186 addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */ 187 addr->ocsr = 0; 188 if (accinputreset(addr, unit) == 0) { 189 ui->ui_alive = 0; 190 return (0); 191 } 192 193 /* 194 * Put up a read. We can't restart any outstanding writes 195 * until we're back in synch with the IMP (i.e. we've flushed 196 * the NOOPs it throws at us). 197 * Note: IMPMTU includes the leader. 198 */ 199 acctrace("init", addr->icsr); 200 info = sc->acc_ifuba.ifu_r.ifrw_info; 201 addr->iba = (u_short)info; 202 addr->iwc = -(IMPMTU >> 1); 203 #ifdef LOOPBACK 204 addr->ocsr |= OUT_BBACK; 205 #endif 206 addr->icsr = 207 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 208 return (1); 209 } 210 211 accinputreset(addr, unit) 212 register struct accdevice *addr; 213 register int unit; 214 { 215 register int i; 216 217 addr->icsr = ACC_RESET; DELAY(5000); 218 addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ 219 DELAY(10000); 220 /* YECH!!! */ 221 for (i = 0; i < 500; i++) { 222 if ((addr->icsr & IN_HRDY) || 223 (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) 224 return (1); 225 addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); 226 /* keep turning IN_RMR off */ 227 } 228 printf("acc%d: imp doesn't respond, icsr=%b\n", unit, 229 addr->icsr, ACC_INBITS); 230 return (0); 231 } 232 233 /* 234 * Start output on an interface. 235 */ 236 accstart(dev) 237 dev_t dev; 238 { 239 int unit = ACCUNIT(dev), info; 240 register struct acc_softc *sc = &acc_softc[unit]; 241 register struct accdevice *addr; 242 struct mbuf *m; 243 u_short cmd; 244 245 COUNT(ACCSTART); 246 acctrace("start", sc->acc_ic->ic_oactive); 247 if (sc->acc_ic->ic_oactive) 248 goto restart; 249 250 /* 251 * Not already active, deqeue a request and 252 * map it onto the UNIBUS. If no more 253 * requeusts, just return. 254 */ 255 IF_DEQUEUE(&sc->acc_if->if_snd, m); 256 if (m == 0) { 257 acctrace("q empty", 0); 258 sc->acc_ic->ic_oactive = 0; 259 return; 260 } 261 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); 262 263 restart: 264 /* 265 * Have request mapped to UNIBUS for 266 * transmission; start the output. 267 */ 268 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 269 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp); 270 addr = (struct accdevice *)accinfo[unit]->ui_addr; 271 info = sc->acc_ifuba.ifu_w.ifrw_info; 272 addr->oba = (u_short)info; 273 addr->owc = -((sc->acc_olen + 1) >> 1); 274 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO; 275 #ifdef LOOPBACK 276 cmd |= OUT_BBACK; 277 #endif 278 addr->ocsr = cmd; 279 sc->acc_ic->ic_oactive = 1; 280 } 281 282 /* 283 * Output interrupt handler. 284 */ 285 accxint(unit) 286 { 287 register struct acc_softc *sc = &acc_softc[unit]; 288 register struct accdevice *addr; 289 290 COUNT(ACCXINT); 291 acctrace("xint", sc->acc_ic->ic_oactive); 292 addr = (struct accdevice *)accinfo[unit]->ui_addr; 293 if (sc->acc_ic->ic_oactive == 0) { 294 printf("acc%d: stray xmit interrupt, csr=%b\n", unit, 295 addr->ocsr, ACC_OUTBITS); 296 return; 297 } 298 acctrace("ocsr", addr->ocsr); 299 sc->acc_if->if_opackets++; 300 sc->acc_ic->ic_oactive = 0; 301 if (addr->ocsr & ACC_ERR) { 302 printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit, 303 addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS); 304 sc->acc_if->if_oerrors++; 305 } 306 if (sc->acc_ifuba.ifu_xtofree) { 307 m_freem(sc->acc_ifuba.ifu_xtofree); 308 sc->acc_ifuba.ifu_xtofree = 0; 309 } 310 if (sc->acc_if->if_snd.ifq_head == 0) { 311 addr->ocsr &= ~ACC_IE; /* hardware funky? */ 312 return; 313 } 314 accstart(unit); 315 } 316 317 /* 318 * Input interrupt handler 319 */ 320 accrint(unit) 321 { 322 register struct acc_softc *sc = &acc_softc[unit]; 323 register struct accdevice *addr; 324 struct mbuf *m; 325 int len, info; 326 327 COUNT(ACCRINT); 328 addr = (struct accdevice *)accinfo[unit]->ui_addr; 329 sc->acc_if->if_ipackets++; 330 331 /* 332 * Purge BDP; flush message if error indicated. 333 */ 334 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 335 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); 336 acctrace("rint", addr->icsr); 337 if (addr->icsr & ACC_ERR) { 338 printf("acc%d: input error, icsr=%b, ocsr=%b\n", unit, 339 addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS); 340 sc->acc_if->if_ierrors++; 341 sc->acc_flush = 1; 342 } 343 344 acctrace("flush", sc->acc_flush); 345 if (sc->acc_flush) { 346 if (addr->icsr & IN_EOM) 347 sc->acc_flush = 0; 348 goto setup; 349 } 350 len = IMPMTU + (addr->iwc << 1); 351 acctrace("length", len); 352 if (len < 0 || len > IMPMTU) { 353 printf("acc%d: bad length=%d\n", len); 354 sc->acc_if->if_ierrors++; 355 goto setup; 356 } 357 358 /* 359 * The last parameter is always 0 since using 360 * trailers on the ARPAnet is insane. 361 */ 362 m = if_rubaget(&sc->acc_ifuba, len, 0); 363 if (m == 0) 364 goto setup; 365 if ((addr->icsr & IN_EOM) == 0) { 366 if (sc->acc_iq) 367 m_cat(sc->acc_iq, m); 368 else 369 sc->acc_iq = m; 370 goto setup; 371 } 372 if (sc->acc_iq) { 373 m_cat(sc->acc_iq, m); 374 m = sc->acc_iq; 375 sc->acc_iq = 0; 376 } 377 acctrace("impinput", 0); 378 impinput(unit, m); 379 380 setup: 381 /* 382 * Setup for next message. 383 */ 384 info = sc->acc_ifuba.ifu_r.ifrw_info; 385 addr->iba = (u_short)info; 386 addr->iwc = -(IMPMTU >> 1); 387 addr->icsr = 388 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 389 } 390 391 int accprintf = 0; 392 393 acctrace(cmd, value) 394 char *cmd; 395 int value; 396 { 397 register int i; 398 register char *p = (char *)&value; 399 400 if (accprintf) 401 printf("%s: %x", cmd, value); 402 do { 403 if (accdebugx >= NACCDEBUG) 404 accdebugx = 0; 405 accdebug[accdebugx++] = *cmd; 406 } while (*cmd++); 407 for (i = 0; i < sizeof (int); i++) { 408 if (accdebugx >= NACCDEBUG) 409 accdebugx = 0; 410 accdebug[accdebugx++] = *p++; 411 } 412 } 413 #endif 414