1 /* if_acc.c 4.24 82/10/21 */ 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/vmmac.h" 18 19 #include "../net/if.h" 20 #include "../netimp/if_imp.h" 21 22 #include "../vax/cpu.h" 23 #include "../vax/mtpr.h" 24 #include "../vaxif/if_acc.h" 25 #include "../vaxif/if_uba.h" 26 #include "../vaxuba/ubareg.h" 27 #include "../vaxuba/ubavar.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 /* 65 * Reset the IMP and cause a transmitter interrupt by 66 * performing a null DMA. 67 */ 68 accprobe(reg) 69 caddr_t reg; 70 { 71 register int br, cvec; /* r11, r10 value-result */ 72 register struct accdevice *addr = (struct accdevice *)reg; 73 74 #ifdef lint 75 br = 0; cvec = br; br = cvec; 76 accrint(0); accxint(0); 77 #endif 78 addr->icsr = ACC_RESET; DELAY(5000); 79 addr->ocsr = ACC_RESET; DELAY(5000); 80 addr->ocsr = OUT_BBACK; DELAY(5000); 81 addr->owc = 0; 82 addr->ocsr = ACC_IE | ACC_GO; DELAY(5000); 83 addr->ocsr = 0; 84 if (cvec && cvec != 0x200) /* transmit -> receive */ 85 cvec -= 4; 86 #ifdef ECHACK 87 br = 0x16; 88 #endif 89 return (1); 90 } 91 92 /* 93 * Call the IMP module to allow it to set up its internal 94 * state, then tie the two modules together by setting up 95 * the back pointers to common data structures. 96 */ 97 accattach(ui) 98 struct uba_device *ui; 99 { 100 register struct acc_softc *sc = &acc_softc[ui->ui_unit]; 101 register struct impcb *ip; 102 struct ifimpcb { 103 struct ifnet ifimp_if; 104 struct impcb ifimp_impcb; 105 } *ifimp; 106 107 if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0) 108 panic("accattach"); 109 sc->acc_if = &ifimp->ifimp_if; 110 ip = &ifimp->ifimp_impcb; 111 sc->acc_ic = ip; 112 ip->ic_init = accinit; 113 ip->ic_start = accstart; 114 sc->acc_ifuba.ifu_ubareset = accreset; 115 sc->acc_ifuba.ifu_flags = UBA_CANTWAIT; 116 #ifdef notdef 117 sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP; 118 #endif 119 } 120 121 /* 122 * Reset interface after UNIBUS reset. 123 * If interface is on specified uba, reset its state. 124 */ 125 accreset(unit, uban) 126 int unit, uban; 127 { 128 register struct uba_device *ui; 129 struct acc_softc *sc; 130 131 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 || 132 ui->ui_ubanum != uban) 133 return; 134 printf(" acc%d", unit); 135 sc = &acc_softc[unit]; 136 /* must go through IMP to allow it to set state */ 137 (*sc->acc_if->if_init)(unit); 138 } 139 140 /* 141 * Initialize interface: clear recorded pending operations, 142 * and retrieve, and initialize UNIBUS resources. Note 143 * return value is used by IMP init routine to mark IMP 144 * unavailable for outgoing traffic. 145 */ 146 accinit(unit) 147 int unit; 148 { 149 register struct acc_softc *sc; 150 register struct uba_device *ui; 151 register struct accdevice *addr; 152 int info; 153 154 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) { 155 printf("acc%d: not alive\n", unit); 156 return (0); 157 } 158 sc = &acc_softc[unit]; 159 /* 160 * Header length is 0 since we have to passs 161 * the IMP leader up to the protocol interpretation 162 * routines. If we had the header length as 163 * sizeof(struct imp_leader), then the if_ routines 164 * would asssume we handle it on input and output. 165 */ 166 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0, 167 (int)btoc(IMPMTU)) == 0) { 168 printf("acc%d: can't initialize\n", unit); 169 ui->ui_alive = 0; 170 return (0); 171 } 172 addr = (struct accdevice *)ui->ui_addr; 173 174 /* 175 * Reset the imp interface; 176 * the delays are pure guesswork. 177 */ 178 addr->ocsr = ACC_RESET; DELAY(5000); 179 addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */ 180 addr->ocsr = 0; 181 if (accinputreset(addr, unit) == 0) { 182 ui->ui_alive = 0; 183 return (0); 184 } 185 186 /* 187 * Put up a read. We can't restart any outstanding writes 188 * until we're back in synch with the IMP (i.e. we've flushed 189 * the NOOPs it throws at us). 190 * Note: IMPMTU includes the leader. 191 */ 192 info = sc->acc_ifuba.ifu_r.ifrw_info; 193 addr->iba = (u_short)info; 194 addr->iwc = -(IMPMTU >> 1); 195 #ifdef LOOPBACK 196 addr->ocsr |= OUT_BBACK; 197 #endif 198 addr->icsr = 199 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 200 return (1); 201 } 202 203 accinputreset(addr, unit) 204 register struct accdevice *addr; 205 register int unit; 206 { 207 register int i; 208 209 addr->icsr = ACC_RESET; DELAY(5000); 210 addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ 211 DELAY(10000); 212 /* YECH!!! */ 213 for (i = 0; i < 500; i++) { 214 if ((addr->icsr & IN_HRDY) || 215 (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) 216 return (1); 217 addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); 218 /* keep turning IN_RMR off */ 219 } 220 printf("acc%d: imp doesn't respond, icsr=%b\n", unit, 221 addr->icsr, ACC_INBITS); 222 return (0); 223 } 224 225 /* 226 * Start output on an interface. 227 */ 228 accstart(dev) 229 dev_t dev; 230 { 231 int unit = ACCUNIT(dev), info; 232 register struct acc_softc *sc = &acc_softc[unit]; 233 register struct accdevice *addr; 234 struct mbuf *m; 235 u_short cmd; 236 237 if (sc->acc_ic->ic_oactive) 238 goto restart; 239 240 /* 241 * Not already active, deqeue a request and 242 * map it onto the UNIBUS. If no more 243 * requeusts, just return. 244 */ 245 IF_DEQUEUE(&sc->acc_if->if_snd, m); 246 if (m == 0) { 247 sc->acc_ic->ic_oactive = 0; 248 return; 249 } 250 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); 251 252 restart: 253 /* 254 * Have request mapped to UNIBUS for 255 * transmission; start the output. 256 */ 257 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 258 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp); 259 addr = (struct accdevice *)accinfo[unit]->ui_addr; 260 info = sc->acc_ifuba.ifu_w.ifrw_info; 261 addr->oba = (u_short)info; 262 addr->owc = -((sc->acc_olen + 1) >> 1); 263 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO; 264 #ifdef LOOPBACK 265 cmd |= OUT_BBACK; 266 #endif 267 addr->ocsr = cmd; 268 sc->acc_ic->ic_oactive = 1; 269 } 270 271 /* 272 * Output interrupt handler. 273 */ 274 accxint(unit) 275 int unit; 276 { 277 register struct acc_softc *sc = &acc_softc[unit]; 278 register struct accdevice *addr; 279 280 addr = (struct accdevice *)accinfo[unit]->ui_addr; 281 if (sc->acc_ic->ic_oactive == 0) { 282 printf("acc%d: stray xmit interrupt, csr=%b\n", unit, 283 addr->ocsr, ACC_OUTBITS); 284 return; 285 } 286 sc->acc_if->if_opackets++; 287 sc->acc_ic->ic_oactive = 0; 288 if (addr->ocsr & ACC_ERR) { 289 printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit, 290 addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS); 291 sc->acc_if->if_oerrors++; 292 } 293 if (sc->acc_ifuba.ifu_xtofree) { 294 m_freem(sc->acc_ifuba.ifu_xtofree); 295 sc->acc_ifuba.ifu_xtofree = 0; 296 } 297 if (sc->acc_if->if_snd.ifq_head) 298 accstart(unit); 299 } 300 301 /* 302 * Input interrupt handler 303 */ 304 accrint(unit) 305 int unit; 306 { 307 register struct acc_softc *sc = &acc_softc[unit]; 308 register struct accdevice *addr; 309 struct mbuf *m; 310 int len, info; 311 312 addr = (struct accdevice *)accinfo[unit]->ui_addr; 313 sc->acc_if->if_ipackets++; 314 315 /* 316 * Purge BDP; flush message if error indicated. 317 */ 318 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 319 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); 320 if (addr->icsr & ACC_ERR) { 321 printf("acc%d: input error, csr=%b\n", unit, 322 addr->icsr, ACC_INBITS); 323 sc->acc_if->if_ierrors++; 324 sc->acc_flush = 1; 325 } 326 327 if (sc->acc_flush) { 328 if (addr->icsr & IN_EOM) 329 sc->acc_flush = 0; 330 goto setup; 331 } 332 len = IMPMTU + (addr->iwc << 1); 333 if (len < 0 || len > IMPMTU) { 334 printf("acc%d: bad length=%d\n", len); 335 sc->acc_if->if_ierrors++; 336 goto setup; 337 } 338 339 /* 340 * The last parameter is always 0 since using 341 * trailers on the ARPAnet is insane. 342 */ 343 m = if_rubaget(&sc->acc_ifuba, len, 0); 344 if (m == 0) 345 goto setup; 346 if ((addr->icsr & IN_EOM) == 0) { 347 if (sc->acc_iq) 348 m_cat(sc->acc_iq, m); 349 else 350 sc->acc_iq = m; 351 goto setup; 352 } 353 if (sc->acc_iq) { 354 m_cat(sc->acc_iq, m); 355 m = sc->acc_iq; 356 sc->acc_iq = 0; 357 } 358 impinput(unit, m); 359 360 setup: 361 /* 362 * Setup for next message. 363 */ 364 info = sc->acc_ifuba.ifu_r.ifrw_info; 365 addr->iba = (u_short)info; 366 addr->iwc = -(IMPMTU >> 1); 367 addr->icsr = 368 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 369 } 370 #endif 371