1 /* if_acc.c 4.19 82/06/20 */ 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 /* 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_flags = UBA_CANTWAIT; 115 #ifdef notdef 116 sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP; 117 #endif 118 } 119 120 /* 121 * Reset interface after UNIBUS reset. 122 * If interface is on specified uba, reset its state. 123 */ 124 accreset(unit, uban) 125 int unit, uban; 126 { 127 register struct uba_device *ui; 128 struct acc_softc *sc; 129 130 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 || 131 ui->ui_ubanum != uban) 132 return; 133 printf(" acc%d", unit); 134 sc = &acc_softc[unit]; 135 /* must go through IMP to allow it to set state */ 136 (*sc->acc_if->if_init)(unit); 137 } 138 139 /* 140 * Initialize interface: clear recorded pending operations, 141 * and retrieve, and initialize UNIBUS resources. Note 142 * return value is used by IMP init routine to mark IMP 143 * unavailable for outgoing traffic. 144 */ 145 accinit(unit) 146 int unit; 147 { 148 register struct acc_softc *sc; 149 register struct uba_device *ui; 150 register struct accdevice *addr; 151 int info, i; 152 153 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) { 154 printf("acc%d: not alive\n", unit); 155 return (0); 156 } 157 sc = &acc_softc[unit]; 158 /* 159 * Header length is 0 since we have to passs 160 * the IMP leader up to the protocol interpretation 161 * routines. If we had the header length as 162 * sizeof(struct imp_leader), then the if_ routines 163 * would asssume we handle it on input and output. 164 */ 165 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0, 166 (int)btoc(IMPMTU)) == 0) { 167 printf("acc%d: can't initialize\n", unit); 168 ui->ui_alive = 0; 169 return (0); 170 } 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: IMPMTU includes the leader. 190 */ 191 info = sc->acc_ifuba.ifu_r.ifrw_info; 192 addr->iba = (u_short)info; 193 addr->iwc = -(IMPMTU >> 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 * Start output on an interface. 226 */ 227 accstart(dev) 228 dev_t dev; 229 { 230 int unit = ACCUNIT(dev), info; 231 register struct acc_softc *sc = &acc_softc[unit]; 232 register struct accdevice *addr; 233 struct mbuf *m; 234 u_short cmd; 235 236 if (sc->acc_ic->ic_oactive) 237 goto restart; 238 239 /* 240 * Not already active, deqeue a request and 241 * map it onto the UNIBUS. If no more 242 * requeusts, just return. 243 */ 244 IF_DEQUEUE(&sc->acc_if->if_snd, m); 245 if (m == 0) { 246 sc->acc_ic->ic_oactive = 0; 247 return; 248 } 249 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); 250 251 restart: 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_ic->ic_oactive = 1; 268 } 269 270 /* 271 * Output interrupt handler. 272 */ 273 accxint(unit) 274 { 275 register struct acc_softc *sc = &acc_softc[unit]; 276 register struct accdevice *addr; 277 278 addr = (struct accdevice *)accinfo[unit]->ui_addr; 279 if (sc->acc_ic->ic_oactive == 0) { 280 printf("acc%d: stray xmit interrupt, csr=%b\n", unit, 281 addr->ocsr, ACC_OUTBITS); 282 return; 283 } 284 sc->acc_if->if_opackets++; 285 sc->acc_ic->ic_oactive = 0; 286 if (addr->ocsr & ACC_ERR) { 287 printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit, 288 addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS); 289 sc->acc_if->if_oerrors++; 290 } 291 if (sc->acc_ifuba.ifu_xtofree) { 292 m_freem(sc->acc_ifuba.ifu_xtofree); 293 sc->acc_ifuba.ifu_xtofree = 0; 294 } 295 if (sc->acc_if->if_snd.ifq_head) 296 accstart(unit); 297 } 298 299 /* 300 * Input interrupt handler 301 */ 302 accrint(unit) 303 { 304 register struct acc_softc *sc = &acc_softc[unit]; 305 register struct accdevice *addr; 306 struct mbuf *m; 307 int len, info; 308 309 addr = (struct accdevice *)accinfo[unit]->ui_addr; 310 sc->acc_if->if_ipackets++; 311 312 /* 313 * Purge BDP; flush message if error indicated. 314 */ 315 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 316 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); 317 if (addr->icsr & ACC_ERR) { 318 printf("acc%d: input error, csr=%b\n", unit, 319 addr->icsr, ACC_INBITS); 320 sc->acc_if->if_ierrors++; 321 sc->acc_flush = 1; 322 } 323 324 if (sc->acc_flush) { 325 if (addr->icsr & IN_EOM) 326 sc->acc_flush = 0; 327 goto setup; 328 } 329 len = IMPMTU + (addr->iwc << 1); 330 if (len < 0 || len > IMPMTU) { 331 printf("acc%d: bad length=%d\n", len); 332 sc->acc_if->if_ierrors++; 333 goto setup; 334 } 335 336 /* 337 * The last parameter is always 0 since using 338 * trailers on the ARPAnet is insane. 339 */ 340 m = if_rubaget(&sc->acc_ifuba, len, 0); 341 if (m == 0) 342 goto setup; 343 if ((addr->icsr & IN_EOM) == 0) { 344 if (sc->acc_iq) 345 m_cat(sc->acc_iq, m); 346 else 347 sc->acc_iq = m; 348 goto setup; 349 } 350 if (sc->acc_iq) { 351 m_cat(sc->acc_iq, m); 352 m = sc->acc_iq; 353 sc->acc_iq = 0; 354 } 355 impinput(unit, m); 356 357 setup: 358 /* 359 * Setup for next message. 360 */ 361 info = sc->acc_ifuba.ifu_r.ifrw_info; 362 addr->iba = (u_short)info; 363 addr->iwc = -(IMPMTU >> 1); 364 addr->icsr = 365 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 366 } 367 #endif 368