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