1 /* if_css.c 6.3 85/06/03 */ 2 3 #include "css.h" 4 5 /* 6 * DEC/CSS IMP11-A ARPAnet IMP interface driver. 7 * Since "imp11a" is such a mouthful, it is called 8 * "css" after the LH/DH being called "acc". 9 * 10 * Configuration notes: 11 * 12 * As delivered from DEC/CSS, it 13 * is addressed and vectored as two DR11-B's. This makes 14 * Autoconfig almost IMPOSSIBLE. To make it work, the 15 * interrupt vectors must be restrapped to make the vectors 16 * consecutive. The 020 hole between the CSR addresses is 17 * tolerated, althought that could be cleaned-up also. 18 * 19 * Additionally, the TRANSMIT side of the IMP11-A has the 20 * lower address of the two subunits, so the vector ordering 21 * in the CONFIG file is reversed from most other devices. 22 * It should be: 23 * 24 * device css0 .... cssxint cssrint 25 * 26 * If you get it wrong, it will still autoconfig, but will just 27 * sit there with RECIEVE IDLE indicated on the front panel. 28 */ 29 #include "../machine/pte.h" 30 31 #include "param.h" 32 #include "systm.h" 33 #include "mbuf.h" 34 #include "buf.h" 35 #include "protosw.h" 36 #include "socket.h" 37 #include "vmmac.h" 38 39 #include "../net/if.h" 40 #include "../netimp/if_imp.h" 41 42 #include "../vax/cpu.h" 43 #include "../vax/mtpr.h" 44 #include "if_cssreg.h" 45 #include "if_uba.h" 46 #include "../vaxuba/ubareg.h" 47 #include "../vaxuba/ubavar.h" 48 49 int cssprobe(), cssattach(), cssrint(), cssxint(); 50 struct uba_device *cssinfo[NCSS]; 51 u_short cssstd[] = { 0 }; 52 struct uba_driver cssdriver = 53 { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo }; 54 #define CSSUNIT(x) minor(x) 55 56 int cssinit(), cssstart(), cssreset(); 57 58 /* 59 * "Lower half" of IMP interface driver. 60 * 61 * Each IMP interface is handled by a common module which handles 62 * the IMP-host protocol and a hardware driver which manages the 63 * hardware specific details of talking with the IMP. 64 * 65 * The hardware portion of the IMP driver handles DMA and related 66 * management of UNIBUS resources. The IMP protocol module interprets 67 * contents of these messages and "controls" the actions of the 68 * hardware module during IMP resets, but not, for instance, during 69 * UNIBUS resets. 70 * 71 * The two modules are coupled at "attach time", and ever after, 72 * through the imp interface structure. Higher level protocols, 73 * e.g. IP, interact with the IMP driver, rather than the CSS. 74 */ 75 struct css_softc { 76 struct ifnet *css_if; /* pointer to IMP's ifnet struct */ 77 struct impcb *css_ic; /* data structure shared with IMP */ 78 struct ifuba css_ifuba; /* UNIBUS resources */ 79 struct mbuf *css_iq; /* input reassembly queue */ 80 short css_olen; /* size of last message sent */ 81 char css_flush; /* flush remainder of message */ 82 } css_softc[NCSS]; 83 84 /* 85 * Reset the IMP and cause a transmitter interrupt by 86 * performing a null DMA. 87 */ 88 cssprobe(reg) 89 caddr_t reg; 90 { 91 register int br, cvec; /* r11, r10 value-result */ 92 register struct cssdevice *addr = (struct cssdevice *)reg; 93 94 #ifdef lint 95 br = 0; cvec = br; br = cvec; 96 cssrint(0); cssxint(0); 97 #endif 98 99 100 addr->css_icsr = CSS_CLR; 101 addr->css_ocsr = CSS_CLR; 102 DELAY(50000); 103 addr->css_icsr = 0; 104 addr->css_ocsr = 0; 105 DELAY(50000); 106 107 addr->css_oba = 0; 108 addr->css_owc = -1; 109 addr->css_ocsr = CSS_IE | CSS_GO; /* enable interrupts */ 110 DELAY(50000); 111 addr->css_ocsr = 0; 112 113 return (1); 114 } 115 116 /* 117 * Call the IMP module to allow it to set up its internal 118 * state, then tie the two modules together by setting up 119 * the back pointers to common data structures. 120 */ 121 cssattach(ui) 122 struct uba_device *ui; 123 { 124 register struct css_softc *sc = &css_softc[ui->ui_unit]; 125 register struct impcb *ip; 126 struct ifimpcb { 127 struct ifnet ifimp_if; 128 struct impcb ifimp_impcb; 129 } *ifimp; 130 131 if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0) 132 panic("cssattach"); /* XXX */ 133 sc->css_if = &ifimp->ifimp_if; 134 ip = &ifimp->ifimp_impcb; 135 sc->css_ic = ip; 136 ip->ic_init = cssinit; 137 ip->ic_start = cssstart; 138 sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16; 139 #ifdef notdef 140 sc->css_ifuba.ifu_flags =| UBA_NEEDBDP; 141 #endif 142 } 143 144 /* 145 * Reset interface after UNIBUS reset. 146 * If interface is on specified uba, reset its state. 147 */ 148 cssreset(unit, uban) 149 int unit, uban; 150 { 151 register struct uba_device *ui; 152 struct css_softc *sc; 153 154 if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 || 155 ui->ui_ubanum != uban) 156 return; 157 printf(" css%d", unit); 158 sc = &css_softc[unit]; 159 sc->css_if->if_flags &= ~IFF_RUNNING; 160 /* must go through IMP to allow it to set state */ 161 (*sc->css_if->if_init)(unit); 162 } 163 164 /* 165 * Initialize interface: clear recorded pending operations, 166 * and retrieve, and reinitialize UNIBUS resources. 167 */ 168 cssinit(unit) 169 int unit; 170 { 171 register struct css_softc *sc; 172 register struct uba_device *ui; 173 register struct cssdevice *addr; 174 int x, info; 175 176 if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) { 177 printf("css%d: not alive\n", unit); 178 return(0); 179 } 180 sc = &css_softc[unit]; 181 182 /* 183 * Header length is 0 to if_ubainit since we have to pass 184 * the IMP leader up to the protocol interpretaion 185 * routines. If we had the deader length as 186 * sizeof(struct imp_leader), then the if_ routines 187 * would assume we handle it on input and output. 188 */ 189 190 if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) { 191 printf("css%d: can't initialize\n", unit); 192 ui->ui_alive = 0; 193 return(0); 194 } 195 sc->css_if->if_flags |= IFF_RUNNING; 196 addr = (struct cssdevice *)ui->ui_addr; 197 198 /* reset the imp interface. */ 199 x = spl5(); 200 addr->css_icsr = CSS_CLR; 201 addr->css_ocsr = CSS_CLR; 202 DELAY(100); 203 addr->css_icsr = 0; 204 addr->css_ocsr = 0; 205 addr->css_icsr = IN_HRDY; /* close the relay */ 206 DELAY(5000); 207 splx(x); 208 209 /* 210 * This may hang if the imp isn't really there. 211 * Will test and verify safe operation. 212 */ 213 214 x = 500; 215 while (x-- > 0) { 216 if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY) 217 break; 218 addr->css_icsr = IN_HRDY; /* close the relay */ 219 DELAY(5000); 220 } 221 222 if (x <= 0) { 223 printf("css%d: imp doesn't respond, icsr=%b\n", unit, 224 CSS_INBITS, addr->css_icsr); 225 goto down; 226 } 227 228 /* 229 * Put up a read. We can't restart any outstanding writes 230 * until we're back in synch with the IMP (i.e. we've flushed 231 * the NOOPs it throws at us). 232 * Note: IMPMTU includes the leader. 233 */ 234 235 x = spl5(); 236 info = sc->css_ifuba.ifu_r.ifrw_info; 237 addr->css_iba = (u_short)info; 238 addr->css_iwc = -(IMPMTU >> 1); 239 addr->css_icsr = 240 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 241 splx(x); 242 return(1); 243 244 down: 245 ui->ui_alive = 0; 246 return(0); 247 } 248 249 /* 250 * Start output on an interface. 251 */ 252 cssstart(dev) 253 dev_t dev; 254 { 255 int unit = CSSUNIT(dev), info; 256 struct uba_device *ui = cssinfo[unit]; 257 register struct css_softc *sc = &css_softc[unit]; 258 register struct cssdevice *addr; 259 struct mbuf *m; 260 u_short cmd; 261 262 if (sc->css_ic->ic_oactive) 263 goto restart; 264 265 /* 266 * Not already active, deqeue a request and 267 * map it onto the UNIBUS. If no more 268 * requeusts, just return. 269 */ 270 IF_DEQUEUE(&sc->css_if->if_snd, m); 271 if (m == 0) { 272 sc->css_ic->ic_oactive = 0; 273 return; 274 } 275 sc->css_olen = if_wubaput(&sc->css_ifuba, m); 276 277 restart: 278 /* 279 * Have request mapped to UNIBUS for transmission. 280 * Purge any stale data from the BDP, and start the output. 281 */ 282 if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 283 UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp); 284 addr = (struct cssdevice *)ui->ui_addr; 285 info = sc->css_ifuba.ifu_w.ifrw_info; 286 addr->css_oba = (u_short)info; 287 addr->css_owc = -((sc->css_olen + 1) >> 1); 288 cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO; 289 addr->css_ocsr = cmd; 290 sc->css_ic->ic_oactive = 1; 291 } 292 293 /* 294 * Output interrupt handler. 295 */ 296 cssxint(unit) 297 { 298 register struct uba_device *ui = cssinfo[unit]; 299 register struct css_softc *sc = &css_softc[unit]; 300 register struct cssdevice *addr; 301 302 addr = (struct cssdevice *)ui->ui_addr; 303 if (sc->css_ic->ic_oactive == 0) { 304 printf("css%d: stray output interrupt csr=%b\n", 305 unit, addr->css_ocsr, CSS_OUTBITS); 306 return; 307 } 308 sc->css_if->if_opackets++; 309 sc->css_ic->ic_oactive = 0; 310 if (addr->css_ocsr & CSS_ERR){ 311 sc->css_if->if_oerrors++; 312 printf("css%d: output error, ocsr=%b icsr=%b\n", unit, 313 addr->css_ocsr, CSS_OUTBITS, 314 addr->css_icsr, CSS_INBITS); 315 } 316 if (sc->css_ifuba.ifu_xtofree) { 317 m_freem(sc->css_ifuba.ifu_xtofree); 318 sc->css_ifuba.ifu_xtofree = 0; 319 } 320 if (sc->css_if->if_snd.ifq_head) 321 cssstart(unit); 322 } 323 324 /* 325 * Input interrupt handler 326 */ 327 cssrint(unit) 328 { 329 register struct css_softc *sc = &css_softc[unit]; 330 register struct cssdevice *addr; 331 struct mbuf *m; 332 int len, info; 333 334 sc->css_if->if_ipackets++; 335 336 /* 337 * Purge BDP; flush message if error indicated. 338 */ 339 340 addr = (struct cssdevice *)cssinfo[unit]->ui_addr; 341 if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 342 UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp); 343 if (addr->css_icsr & CSS_ERR) { 344 printf("css%d: recv error, csr=%b\n", unit, 345 addr->css_icsr, CSS_INBITS); 346 sc->css_if->if_ierrors++; 347 sc->css_flush = 1; 348 } 349 350 if (sc->css_flush) { 351 if (addr->css_icsr & IN_EOM) 352 sc->css_flush = 0; 353 goto setup; 354 } 355 356 len = IMPMTU + (addr->css_iwc << 1); 357 if (len < 0 || len > IMPMTU) { 358 printf("css%d: bad length=%d\n", len); 359 sc->css_if->if_ierrors++; 360 goto setup; 361 } 362 363 /* 364 * The last parameter is always 0 since using 365 * trailers on the ARPAnet is insane. 366 */ 367 m = if_rubaget(&sc->css_ifuba, len, 0); 368 if (m == 0) 369 goto setup; 370 if ((addr->css_icsr & IN_EOM) == 0) { 371 if (sc->css_iq) 372 m_cat(sc->css_iq, m); 373 else 374 sc->css_iq = m; 375 goto setup; 376 } 377 if (sc->css_iq) { 378 m_cat(sc->css_iq, m); 379 m = sc->css_iq; 380 sc->css_iq = 0; 381 } 382 impinput(unit, m); 383 384 setup: 385 /* 386 * Setup for next message. 387 */ 388 info = sc->css_ifuba.ifu_r.ifrw_info; 389 addr->css_iba = (u_short)info; 390 addr->css_iwc = - (IMPMTU >> 1); 391 addr->css_icsr = 392 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 393 } 394