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