| 1 | /* if_acc.c 4.8 82/03/12 */ |
| 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 | return (1); |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Call the IMP module to allow it to set up its internal |
| 92 | * state, then tie the two modules together by setting up |
| 93 | * the back pointers to common data structures. |
| 94 | */ |
| 95 | accattach(ui) |
| 96 | struct uba_device *ui; |
| 97 | { |
| 98 | register struct acc_softc *sc = &acc_softc[ui->ui_unit]; |
| 99 | register struct impcb *ip; |
| 100 | struct ifimpcb { |
| 101 | struct ifnet ifimp_if; |
| 102 | struct impcb ifimp_impcb; |
| 103 | } *ifimp; |
| 104 | |
| 105 | COUNT(ACCATTACH); |
| 106 | if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0) |
| 107 | panic("accattach"); |
| 108 | sc->acc_if = &ifimp->ifimp_if; |
| 109 | ip = &ifimp->ifimp_impcb; |
| 110 | sc->acc_ic = ip; |
| 111 | ip->ic_init = accinit; |
| 112 | ip->ic_start = accstart; |
| 113 | #ifdef notdef |
| 114 | sc->acc_ifuba.ifu_flags = UBA_NEEDBDP; |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Reset interface after UNIBUS reset. |
| 120 | * If interface is on specified uba, reset its state. |
| 121 | */ |
| 122 | accreset(unit, uban) |
| 123 | int unit, uban; |
| 124 | { |
| 125 | register struct uba_device *ui; |
| 126 | struct acc_softc *sc; |
| 127 | |
| 128 | COUNT(ACCRESET); |
| 129 | if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 || |
| 130 | ui->ui_ubanum != uban) |
| 131 | return; |
| 132 | printf(" acc%d", unit); |
| 133 | sc = &acc_softc[unit]; |
| 134 | /* must go through IMP to allow it to set state */ |
| 135 | (*sc->acc_if->if_init)(unit); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Initialize interface: clear recorded pending operations, |
| 140 | * and retrieve, and initialize UNIBUS resources. Note |
| 141 | * return value is used by IMP init routine to mark IMP |
| 142 | * unavailable for outgoing traffic. |
| 143 | */ |
| 144 | accinit(unit) |
| 145 | int unit; |
| 146 | { |
| 147 | register struct acc_softc *sc; |
| 148 | register struct uba_device *ui; |
| 149 | register struct accdevice *addr; |
| 150 | int x, info; |
| 151 | |
| 152 | COUNT(ACCINIT); |
| 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, btoc(IMP_MTU)) == 0) { |
| 166 | printf("acc%d: can't initialize\n", unit); |
| 167 | goto down; |
| 168 | } |
| 169 | addr = (struct accdevice *)ui->ui_addr; |
| 170 | |
| 171 | /* |
| 172 | * Reset the imp interface; |
| 173 | * the delays are pure guesswork. |
| 174 | */ |
| 175 | x = spl5(); |
| 176 | addr->icsr = ACC_RESET; DELAY(5000); |
| 177 | addr->ocsr = ACC_RESET; DELAY(5000); |
| 178 | addr->ocsr = OUT_BBACK; DELAY(1000); /* reset host master ready */ |
| 179 | addr->ocsr = 0; |
| 180 | splx(x); |
| 181 | addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ |
| 182 | DELAY(5000); |
| 183 | /* YECH!!! */ |
| 184 | x = 500; |
| 185 | while (x-- > 0) { |
| 186 | if ((addr->icsr & IN_HRDY) || |
| 187 | (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) |
| 188 | break; |
| 189 | addr->icsr = IN_MRDY | IN_WEN; |
| 190 | DELAY(5000); /* keep turning IN_RMR off */ |
| 191 | } |
| 192 | if (x <= 0) { |
| 193 | printf("acc%d: imp doesn't respond, icsr=%b\n", unit, |
| 194 | addr->icsr, ACC_INBITS); |
| 195 | goto down; |
| 196 | } |
| 197 | |
| 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: IMP_MTU includes the leader. |
| 203 | */ |
| 204 | x = spl5(); |
| 205 | info = sc->acc_ifuba.ifu_r.ifrw_info; |
| 206 | addr->iba = (u_short)info; |
| 207 | addr->iwc = -(IMP_MTU >> 1); |
| 208 | #ifdef LOOPBACK |
| 209 | addr->ocsr |= OUT_BBACK; |
| 210 | #endif |
| 211 | addr->icsr = |
| 212 | IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; |
| 213 | splx(x); |
| 214 | return (1); |
| 215 | down: |
| 216 | ui->ui_alive = 0; |
| 217 | return (0); |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Start output on an interface. |
| 222 | */ |
| 223 | accstart(dev) |
| 224 | dev_t dev; |
| 225 | { |
| 226 | int unit = ACCUNIT(dev), info; |
| 227 | register struct acc_softc *sc = &acc_softc[unit]; |
| 228 | register struct accdevice *addr; |
| 229 | struct mbuf *m; |
| 230 | u_short cmd; |
| 231 | |
| 232 | COUNT(ACCSTART); |
| 233 | if (sc->acc_ic->ic_oactive) |
| 234 | goto restart; |
| 235 | |
| 236 | /* |
| 237 | * Not already active, deqeue a request and |
| 238 | * map it onto the UNIBUS. If no more |
| 239 | * requeusts, just return. |
| 240 | */ |
| 241 | IF_DEQUEUE(&sc->acc_if->if_snd, m); |
| 242 | if (m == 0) { |
| 243 | sc->acc_ic->ic_oactive = 0; |
| 244 | return; |
| 245 | } |
| 246 | sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); |
| 247 | |
| 248 | restart: |
| 249 | /* |
| 250 | * Have request mapped to UNIBUS for |
| 251 | * transmission; start the output. |
| 252 | */ |
| 253 | if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) |
| 254 | UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp); |
| 255 | addr = (struct accdevice *)accinfo[unit]->ui_addr; |
| 256 | info = sc->acc_ifuba.ifu_w.ifrw_info; |
| 257 | addr->oba = (u_short)info; |
| 258 | addr->owc = -((sc->acc_olen + 1) >> 1); |
| 259 | cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO; |
| 260 | #ifdef LOOPBACK |
| 261 | cmd |= OUT_BBACK; |
| 262 | #endif |
| 263 | addr->ocsr = cmd; |
| 264 | sc->acc_ic->ic_oactive = 1; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Output interrupt handler. |
| 269 | */ |
| 270 | accxint(unit) |
| 271 | { |
| 272 | register struct acc_softc *sc = &acc_softc[unit]; |
| 273 | register struct accdevice *addr; |
| 274 | |
| 275 | COUNT(ACCXINT); |
| 276 | if (sc->acc_ic->ic_oactive == 0) { |
| 277 | printf("acc%d: stray xmit interrupt\n", unit); |
| 278 | return; |
| 279 | } |
| 280 | addr = (struct accdevice *)accinfo[unit]->ui_addr; |
| 281 | sc->acc_if->if_opackets++; |
| 282 | sc->acc_ic->ic_oactive = 0; |
| 283 | if (addr->ocsr & ACC_ERR) { |
| 284 | printf("acc%d: output error, csr=%b\n", unit, |
| 285 | addr->ocsr, ACC_OUTBITS); |
| 286 | sc->acc_if->if_oerrors++; |
| 287 | } |
| 288 | if (sc->acc_ifuba.ifu_xtofree) { |
| 289 | m_freem(sc->acc_ifuba.ifu_xtofree); |
| 290 | sc->acc_ifuba.ifu_xtofree = 0; |
| 291 | } |
| 292 | if (sc->acc_if->if_snd.ifq_head) |
| 293 | accstart(unit); |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * Input interrupt handler |
| 298 | */ |
| 299 | accrint(unit) |
| 300 | { |
| 301 | register struct acc_softc *sc = &acc_softc[unit]; |
| 302 | register struct accdevice *addr; |
| 303 | register struct ifqueue *inq; |
| 304 | struct mbuf *m; |
| 305 | int len, info; |
| 306 | |
| 307 | COUNT(ACCRINT); |
| 308 | sc->acc_if->if_ipackets++; |
| 309 | |
| 310 | /* |
| 311 | * Purge BDP; flush message if error indicated. |
| 312 | */ |
| 313 | if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) |
| 314 | UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); |
| 315 | addr = (struct accdevice *)accinfo[unit]->ui_addr; |
| 316 | if (addr->icsr & ACC_ERR) { |
| 317 | printf("acc%d: input error, csr=%b\n", unit, |
| 318 | addr->icsr, ACC_INBITS); |
| 319 | sc->acc_if->if_ierrors++; |
| 320 | sc->acc_flush = 1; |
| 321 | } |
| 322 | |
| 323 | if (sc->acc_flush) { |
| 324 | if (addr->icsr & IN_EOM) |
| 325 | sc->acc_flush = 0; |
| 326 | goto setup; |
| 327 | } |
| 328 | len = IMP_MTU + (addr->iwc << 1); |
| 329 | if (len < 0 || len > IMP_MTU) { |
| 330 | printf("acc%d: bad length=%d\n", len); |
| 331 | sc->acc_if->if_ierrors++; |
| 332 | goto setup; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * The last parameter is always 0 since using |
| 337 | * trailers on the ARPAnet is insane. |
| 338 | */ |
| 339 | m = if_rubaget(&sc->acc_ifuba, len, 0); |
| 340 | if (m == 0) |
| 341 | goto setup; |
| 342 | if ((addr->icsr & IN_EOM) == 0) { |
| 343 | if (sc->acc_iq) |
| 344 | m_cat(sc->acc_iq, m); |
| 345 | else |
| 346 | sc->acc_iq = m; |
| 347 | goto setup; |
| 348 | } |
| 349 | if (sc->acc_iq) { |
| 350 | m_cat(sc->acc_iq, m); |
| 351 | m = sc->acc_iq; |
| 352 | sc->acc_iq = 0; |
| 353 | } |
| 354 | impinput(unit, m); |
| 355 | |
| 356 | setup: |
| 357 | /* |
| 358 | * Setup for next message. |
| 359 | */ |
| 360 | info = sc->acc_ifuba.ifu_r.ifrw_info; |
| 361 | addr->iba = (u_short)info; |
| 362 | addr->iwc = -(IMP_MTU >> 1); |
| 363 | addr->icsr = |
| 364 | IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO; |
| 365 | } |
| 366 | #endif |