1 /* if_acc.c 4.14 82/04/16 */ 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 COUNT(ACCPROBE); 75 #ifdef lint 76 br = 0; cvec = br; br = cvec; 77 accrint(0); accxint(0); 78 #endif 79 addr->icsr = ACC_RESET; DELAY(5000); 80 addr->ocsr = ACC_RESET; DELAY(5000); 81 addr->ocsr = OUT_BBACK; DELAY(5000); 82 addr->owc = 0; 83 addr->ocsr = ACC_IE | ACC_GO; DELAY(5000); 84 addr->ocsr = 0; 85 if (cvec && cvec != 0x200) /* transmit -> receive */ 86 cvec -= 4; 87 br = 0x16; /* temporary ec hack */ 88 return (1); 89 } 90 91 /* 92 * Call the IMP module to allow it to set up its internal 93 * state, then tie the two modules together by setting up 94 * the back pointers to common data structures. 95 */ 96 accattach(ui) 97 struct uba_device *ui; 98 { 99 register struct acc_softc *sc = &acc_softc[ui->ui_unit]; 100 register struct impcb *ip; 101 struct ifimpcb { 102 struct ifnet ifimp_if; 103 struct impcb ifimp_impcb; 104 } *ifimp; 105 106 COUNT(ACCATTACH); 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 #ifdef notdef 115 sc->acc_ifuba.ifu_flags = UBA_NEEDBDP | UBA_CANTWAIT; 116 #endif 117 } 118 119 /* 120 * Reset interface after UNIBUS reset. 121 * If interface is on specified uba, reset its state. 122 */ 123 accreset(unit, uban) 124 int unit, uban; 125 { 126 register struct uba_device *ui; 127 struct acc_softc *sc; 128 129 COUNT(ACCRESET); 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 COUNT(ACCINIT); 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 goto down; 170 } 171 addr = (struct accdevice *)ui->ui_addr; 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 goto ok; 188 addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); 189 /* keep turning IN_RMR off */ 190 } 191 printf("acc%d: imp doesn't respond, icsr=%b\n", unit, 192 addr->icsr, ACC_INBITS); 193 down: 194 ui->ui_alive = 0; 195 return (0); 196 197 ok: 198 /* 199 * Put up a read. We can't restart any outstanding writes 200 * until we're back in synch with the IMP (i.e. we've flushed 201 * the NOOPs it throws at us). 202 * Note: IMPMTU includes the leader. 203 */ 204 info = sc->acc_ifuba.ifu_r.ifrw_info; 205 addr->iba = (u_short)info; 206 addr->iwc = -(IMPMTU >> 1); 207 #ifdef LOOPBACK 208 addr->ocsr |= OUT_BBACK; 209 #endif 210 addr->icsr = 211 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 212 return (1); 213 } 214 215 /* 216 * Start output on an interface. 217 */ 218 accstart(dev) 219 dev_t dev; 220 { 221 int unit = ACCUNIT(dev), info; 222 register struct acc_softc *sc = &acc_softc[unit]; 223 register struct accdevice *addr; 224 struct mbuf *m; 225 u_short cmd; 226 227 COUNT(ACCSTART); 228 if (sc->acc_ic->ic_oactive) 229 goto restart; 230 231 /* 232 * Not already active, deqeue a request and 233 * map it onto the UNIBUS. If no more 234 * requeusts, just return. 235 */ 236 IF_DEQUEUE(&sc->acc_if->if_snd, m); 237 if (m == 0) { 238 sc->acc_ic->ic_oactive = 0; 239 return; 240 } 241 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); 242 243 restart: 244 /* 245 * Have request mapped to UNIBUS for 246 * transmission; start the output. 247 */ 248 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 249 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp); 250 addr = (struct accdevice *)accinfo[unit]->ui_addr; 251 info = sc->acc_ifuba.ifu_w.ifrw_info; 252 addr->oba = (u_short)info; 253 addr->owc = -((sc->acc_olen + 1) >> 1); 254 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO; 255 #ifdef LOOPBACK 256 cmd |= OUT_BBACK; 257 #endif 258 addr->ocsr = cmd; 259 sc->acc_ic->ic_oactive = 1; 260 } 261 262 /* 263 * Output interrupt handler. 264 */ 265 accxint(unit) 266 { 267 register struct acc_softc *sc = &acc_softc[unit]; 268 register struct accdevice *addr; 269 270 COUNT(ACCXINT); 271 if (sc->acc_ic->ic_oactive == 0) { 272 printf("acc%d: stray xmit interrupt\n", unit); 273 return; 274 } 275 addr = (struct accdevice *)accinfo[unit]->ui_addr; 276 sc->acc_if->if_opackets++; 277 sc->acc_ic->ic_oactive = 0; 278 if (addr->ocsr & ACC_ERR) { 279 printf("acc%d: output error, csr=%b\n", unit, 280 addr->ocsr, ACC_OUTBITS); 281 sc->acc_if->if_oerrors++; 282 } 283 if (sc->acc_ifuba.ifu_xtofree) { 284 m_freem(sc->acc_ifuba.ifu_xtofree); 285 sc->acc_ifuba.ifu_xtofree = 0; 286 } 287 if (sc->acc_if->if_snd.ifq_head) 288 accstart(unit); 289 } 290 291 /* 292 * Input interrupt handler 293 */ 294 accrint(unit) 295 { 296 register struct acc_softc *sc = &acc_softc[unit]; 297 register struct accdevice *addr; 298 struct mbuf *m; 299 int len, info; 300 301 COUNT(ACCRINT); 302 sc->acc_if->if_ipackets++; 303 304 /* 305 * Purge BDP; flush message if error indicated. 306 */ 307 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) 308 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); 309 addr = (struct accdevice *)accinfo[unit]->ui_addr; 310 if (addr->icsr & ACC_ERR) { 311 printf("acc%d: input error, csr=%b\n", unit, 312 addr->icsr, ACC_INBITS); 313 sc->acc_if->if_ierrors++; 314 sc->acc_flush = 1; 315 } 316 317 if (sc->acc_flush) { 318 if (addr->icsr & IN_EOM) 319 sc->acc_flush = 0; 320 goto setup; 321 } 322 len = IMPMTU + (addr->iwc << 1); 323 if (len < 0 || len > IMPMTU) { 324 printf("acc%d: bad length=%d\n", len); 325 sc->acc_if->if_ierrors++; 326 goto setup; 327 } 328 329 /* 330 * The last parameter is always 0 since using 331 * trailers on the ARPAnet is insane. 332 */ 333 m = if_rubaget(&sc->acc_ifuba, len, 0); 334 if (m == 0) 335 goto setup; 336 if ((addr->icsr & IN_EOM) == 0) { 337 if (sc->acc_iq) 338 m_cat(sc->acc_iq, m); 339 else 340 sc->acc_iq = m; 341 goto setup; 342 } 343 if (sc->acc_iq) { 344 m_cat(sc->acc_iq, m); 345 m = sc->acc_iq; 346 sc->acc_iq = 0; 347 } 348 impinput(unit, m); 349 350 setup: 351 /* 352 * Setup for next message. 353 */ 354 info = sc->acc_ifuba.ifu_r.ifrw_info; 355 addr->iba = (u_short)info; 356 addr->iwc = -(IMPMTU >> 1); 357 addr->icsr = 358 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; 359 } 360 #endif 361