123283Smckusick /* 2*33452Skarels * Copyright (c) 1982,1986,1988 Regents of the University of California. 3*33452Skarels * All rights reserved. 423283Smckusick * 5*33452Skarels * Redistribution and use in source and binary forms are permitted 6*33452Skarels * provided that this notice is preserved and that due credit is given 7*33452Skarels * to the University of California at Berkeley. The name of the University 8*33452Skarels * may not be used to endorse or promote products derived from this 9*33452Skarels * software without specific prior written permission. This software 10*33452Skarels * is provided ``as is'' without express or implied warranty. 11*33452Skarels * 12*33452Skarels * @(#)if_css.c 7.3 (Berkeley) 02/08/88 1323283Smckusick */ 147468Ssam 157468Ssam #include "css.h" 1625270Sbloom #if NCSS > 0 177468Ssam 187468Ssam /* 197468Ssam * DEC/CSS IMP11-A ARPAnet IMP interface driver. 207468Ssam * Since "imp11a" is such a mouthful, it is called 217468Ssam * "css" after the LH/DH being called "acc". 227468Ssam * 237468Ssam * Configuration notes: 247468Ssam * 257468Ssam * As delivered from DEC/CSS, it 267468Ssam * is addressed and vectored as two DR11-B's. This makes 277468Ssam * Autoconfig almost IMPOSSIBLE. To make it work, the 287468Ssam * interrupt vectors must be restrapped to make the vectors 297468Ssam * consecutive. The 020 hole between the CSR addresses is 307468Ssam * tolerated, althought that could be cleaned-up also. 317468Ssam * 327468Ssam * Additionally, the TRANSMIT side of the IMP11-A has the 337468Ssam * lower address of the two subunits, so the vector ordering 347468Ssam * in the CONFIG file is reversed from most other devices. 357468Ssam * It should be: 367468Ssam * 377468Ssam * device css0 .... cssxint cssrint 387468Ssam * 397468Ssam * If you get it wrong, it will still autoconfig, but will just 4024800Skarels * sit there with RECEIVE IDLE indicated on the front panel. 417468Ssam */ 4217110Sbloom #include "param.h" 4317110Sbloom #include "systm.h" 4417110Sbloom #include "mbuf.h" 4517110Sbloom #include "buf.h" 4617110Sbloom #include "protosw.h" 4717110Sbloom #include "socket.h" 4817110Sbloom #include "vmmac.h" 498459Sroot 50*33452Skarels #include "../machine/pte.h" 51*33452Skarels 527468Ssam #include "../net/if.h" 538415Swnj #include "../netimp/if_imp.h" 548459Sroot 558459Sroot #include "../vax/cpu.h" 568459Sroot #include "../vax/mtpr.h" 5717110Sbloom #include "if_cssreg.h" 5817110Sbloom #include "if_uba.h" 598459Sroot #include "../vaxuba/ubareg.h" 608459Sroot #include "../vaxuba/ubavar.h" 617468Ssam 627468Ssam int cssprobe(), cssattach(), cssrint(), cssxint(); 637468Ssam struct uba_device *cssinfo[NCSS]; 647468Ssam u_short cssstd[] = { 0 }; 657468Ssam struct uba_driver cssdriver = 667468Ssam { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo }; 677468Ssam 68*33452Skarels int cssinit(), cssoutput(), cssdown(), cssreset(); 697468Ssam 707468Ssam /* 717468Ssam * "Lower half" of IMP interface driver. 727468Ssam * 737468Ssam * Each IMP interface is handled by a common module which handles 747468Ssam * the IMP-host protocol and a hardware driver which manages the 757468Ssam * hardware specific details of talking with the IMP. 767468Ssam * 777468Ssam * The hardware portion of the IMP driver handles DMA and related 787468Ssam * management of UNIBUS resources. The IMP protocol module interprets 797468Ssam * contents of these messages and "controls" the actions of the 807468Ssam * hardware module during IMP resets, but not, for instance, during 817468Ssam * UNIBUS resets. 827468Ssam * 837468Ssam * The two modules are coupled at "attach time", and ever after, 847468Ssam * through the imp interface structure. Higher level protocols, 857468Ssam * e.g. IP, interact with the IMP driver, rather than the CSS. 867468Ssam */ 877468Ssam struct css_softc { 88*33452Skarels struct imp_softc *css_imp; /* pointer to IMP's imp_softc struct */ 89*33452Skarels struct ifuba css_ifuba; /* UNIBUS resources */ 90*33452Skarels struct mbuf *css_iq; /* input reassembly queue */ 91*33452Skarels short css_olen; /* size of last message sent */ 92*33452Skarels char css_flush; /* flush remainder of message */ 937468Ssam } css_softc[NCSS]; 947468Ssam 957468Ssam /* 967468Ssam * Reset the IMP and cause a transmitter interrupt by 977468Ssam * performing a null DMA. 987468Ssam */ 997468Ssam cssprobe(reg) 1007468Ssam caddr_t reg; 1017468Ssam { 1027468Ssam register int br, cvec; /* r11, r10 value-result */ 1037468Ssam register struct cssdevice *addr = (struct cssdevice *)reg; 1047468Ssam 1057468Ssam #ifdef lint 1067468Ssam br = 0; cvec = br; br = cvec; 1077468Ssam cssrint(0); cssxint(0); 1087468Ssam #endif 1097468Ssam 1107468Ssam addr->css_icsr = CSS_CLR; 1117468Ssam addr->css_ocsr = CSS_CLR; 1127468Ssam DELAY(50000); 1137468Ssam addr->css_icsr = 0; 1147468Ssam addr->css_ocsr = 0; 1157468Ssam DELAY(50000); 1167468Ssam 1177468Ssam addr->css_oba = 0; 1187468Ssam addr->css_owc = -1; 1197468Ssam addr->css_ocsr = CSS_IE | CSS_GO; /* enable interrupts */ 1207468Ssam DELAY(50000); 1217468Ssam addr->css_ocsr = 0; 1227468Ssam 1237468Ssam return (1); 1247468Ssam } 1257468Ssam 1267468Ssam /* 1277468Ssam * Call the IMP module to allow it to set up its internal 1287468Ssam * state, then tie the two modules together by setting up 1297468Ssam * the back pointers to common data structures. 1307468Ssam */ 1317468Ssam cssattach(ui) 1327468Ssam struct uba_device *ui; 1337468Ssam { 1347468Ssam register struct css_softc *sc = &css_softc[ui->ui_unit]; 1357468Ssam register struct impcb *ip; 1367468Ssam 137*33452Skarels if ((sc->css_imp = impattach(ui, cssreset)) == 0) 13824800Skarels return; 139*33452Skarels ip = &sc->css_imp->imp_cb; 1407468Ssam ip->ic_init = cssinit; 141*33452Skarels ip->ic_output = cssoutput; 142*33452Skarels ip->ic_down = cssdown; 1437468Ssam sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16; 1447468Ssam #ifdef notdef 14532775Sbostic sc->css_ifuba.ifu_flags |= UBA_NEEDBDP; 1467468Ssam #endif 1477468Ssam } 1487468Ssam 1497468Ssam /* 1507468Ssam * Reset interface after UNIBUS reset. 1517468Ssam * If interface is on specified uba, reset its state. 1527468Ssam */ 1537468Ssam cssreset(unit, uban) 1547468Ssam int unit, uban; 1557468Ssam { 1567468Ssam register struct uba_device *ui; 157*33452Skarels register struct css_softc *sc; 1587468Ssam 1597468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 || 1607468Ssam ui->ui_ubanum != uban) 1617468Ssam return; 1627468Ssam printf(" css%d", unit); 1637468Ssam sc = &css_softc[unit]; 164*33452Skarels sc->css_imp->imp_if.if_flags &= ~IFF_RUNNING; 1657468Ssam /* must go through IMP to allow it to set state */ 166*33452Skarels (*sc->css_imp->imp_if.if_init)(sc->css_imp->imp_if.if_unit); 1677468Ssam } 1687468Ssam 1697468Ssam /* 1707468Ssam * Initialize interface: clear recorded pending operations, 1717468Ssam * and retrieve, and reinitialize UNIBUS resources. 1727468Ssam */ 1737468Ssam cssinit(unit) 1747468Ssam int unit; 1757468Ssam { 1767468Ssam register struct css_softc *sc; 1777468Ssam register struct uba_device *ui; 1787468Ssam register struct cssdevice *addr; 1797468Ssam int x, info; 1807468Ssam 1817468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) { 1827468Ssam printf("css%d: not alive\n", unit); 1837468Ssam return(0); 1847468Ssam } 1857468Ssam sc = &css_softc[unit]; 1867468Ssam 1877468Ssam /* 1887468Ssam * Header length is 0 to if_ubainit since we have to pass 1897468Ssam * the IMP leader up to the protocol interpretaion 1907468Ssam * routines. If we had the deader length as 1917468Ssam * sizeof(struct imp_leader), then the if_ routines 1927468Ssam * would assume we handle it on input and output. 1937468Ssam */ 1947468Ssam 195*33452Skarels if ((sc->css_imp->imp_if.if_flags & IFF_RUNNING) == 0 && 196*33452Skarels if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0, 197*33452Skarels (int)btoc(IMP_RCVBUF)) == 0) { 1987468Ssam printf("css%d: can't initialize\n", unit); 1997468Ssam ui->ui_alive = 0; 200*33452Skarels sc->css_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING); 2017468Ssam return(0); 2027468Ssam } 203*33452Skarels sc->css_imp->imp_if.if_flags |= IFF_RUNNING; 2047468Ssam addr = (struct cssdevice *)ui->ui_addr; 2057468Ssam 2067468Ssam /* reset the imp interface. */ 2077468Ssam x = spl5(); 2087468Ssam addr->css_icsr = CSS_CLR; 2097468Ssam addr->css_ocsr = CSS_CLR; 2107468Ssam DELAY(100); 2117468Ssam addr->css_icsr = 0; 2127468Ssam addr->css_ocsr = 0; 2137468Ssam addr->css_icsr = IN_HRDY; /* close the relay */ 2147468Ssam DELAY(5000); 2157468Ssam splx(x); 2167468Ssam 2177468Ssam /* 2187468Ssam * This may hang if the imp isn't really there. 2197468Ssam * Will test and verify safe operation. 2207468Ssam */ 2217468Ssam 2227468Ssam x = 500; 2237468Ssam while (x-- > 0) { 2247468Ssam if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY) 2257468Ssam break; 2267468Ssam addr->css_icsr = IN_HRDY; /* close the relay */ 2277468Ssam DELAY(5000); 2287468Ssam } 2297468Ssam 2307468Ssam if (x <= 0) { 2317468Ssam printf("css%d: imp doesn't respond, icsr=%b\n", unit, 2327468Ssam CSS_INBITS, addr->css_icsr); 2337468Ssam goto down; 2347468Ssam } 2357468Ssam 2367468Ssam /* 2377468Ssam * Put up a read. We can't restart any outstanding writes 2387468Ssam * until we're back in synch with the IMP (i.e. we've flushed 2397468Ssam * the NOOPs it throws at us). 240*33452Skarels * Note: IMP_RCVBUF includes the leader. 2417468Ssam */ 2427468Ssam 2437468Ssam x = spl5(); 2447468Ssam info = sc->css_ifuba.ifu_r.ifrw_info; 2457468Ssam addr->css_iba = (u_short)info; 246*33452Skarels addr->css_iwc = -(IMP_RCVBUF >> 1); 2477468Ssam addr->css_icsr = 2487468Ssam IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 2497468Ssam splx(x); 2507468Ssam return(1); 2517468Ssam 2527468Ssam down: 2537468Ssam ui->ui_alive = 0; 2547468Ssam return(0); 2557468Ssam } 2567468Ssam 2577468Ssam /* 258*33452Skarels * Drop the host ready line to mark host down. 259*33452Skarels * UNTESTED. 260*33452Skarels */ 261*33452Skarels cssdown(unit) 262*33452Skarels int unit; 263*33452Skarels { 264*33452Skarels register struct cssdevice *addr; 265*33452Skarels int x; 266*33452Skarels 267*33452Skarels addr = (struct cssdevice *)(cssinfo[unit]->ui_addr); 268*33452Skarels /* reset the imp interface. */ 269*33452Skarels x = spl5(); 270*33452Skarels addr->css_icsr = CSS_CLR; 271*33452Skarels addr->css_ocsr = CSS_CLR; 272*33452Skarels DELAY(100); 273*33452Skarels addr->css_icsr = 0; 274*33452Skarels addr->css_ocsr = 0; 275*33452Skarels splx(x); 276*33452Skarels return (1); 277*33452Skarels } 278*33452Skarels 279*33452Skarels /* 2807468Ssam * Start output on an interface. 2817468Ssam */ 282*33452Skarels cssoutput(unit, m) 283*33452Skarels int unit; 284*33452Skarels struct mbuf *m; 2857468Ssam { 286*33452Skarels int info; 2877468Ssam struct uba_device *ui = cssinfo[unit]; 2887468Ssam register struct css_softc *sc = &css_softc[unit]; 2897468Ssam register struct cssdevice *addr; 2907468Ssam 2917468Ssam sc->css_olen = if_wubaput(&sc->css_ifuba, m); 2927468Ssam /* 2937468Ssam * Have request mapped to UNIBUS for transmission. 2947468Ssam * Purge any stale data from the BDP, and start the output. 2957468Ssam */ 2967468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 2977468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp); 2987468Ssam addr = (struct cssdevice *)ui->ui_addr; 2997468Ssam info = sc->css_ifuba.ifu_w.ifrw_info; 3007468Ssam addr->css_oba = (u_short)info; 3017468Ssam addr->css_owc = -((sc->css_olen + 1) >> 1); 302*33452Skarels addr->css_ocsr = 303*33452Skarels (u_short)(CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO); 304*33452Skarels sc->css_imp->imp_cb.ic_oactive = 1; 3057468Ssam } 3067468Ssam 3077468Ssam /* 3087468Ssam * Output interrupt handler. 3097468Ssam */ 3107468Ssam cssxint(unit) 3117468Ssam { 3127468Ssam register struct uba_device *ui = cssinfo[unit]; 3137468Ssam register struct css_softc *sc = &css_softc[unit]; 3147468Ssam register struct cssdevice *addr; 3157468Ssam 3167468Ssam addr = (struct cssdevice *)ui->ui_addr; 317*33452Skarels if (sc->css_imp->imp_cb.ic_oactive == 0) { 3187468Ssam printf("css%d: stray output interrupt csr=%b\n", 3197468Ssam unit, addr->css_ocsr, CSS_OUTBITS); 3207468Ssam return; 3217468Ssam } 322*33452Skarels sc->css_imp->imp_if.if_opackets++; 323*33452Skarels sc->css_imp->imp_cb.ic_oactive = 0; 3247468Ssam if (addr->css_ocsr & CSS_ERR){ 325*33452Skarels sc->css_imp->imp_if.if_oerrors++; 3267468Ssam printf("css%d: output error, ocsr=%b icsr=%b\n", unit, 3277468Ssam addr->css_ocsr, CSS_OUTBITS, 3287468Ssam addr->css_icsr, CSS_INBITS); 3297468Ssam } 3307468Ssam if (sc->css_ifuba.ifu_xtofree) { 3317468Ssam m_freem(sc->css_ifuba.ifu_xtofree); 3327468Ssam sc->css_ifuba.ifu_xtofree = 0; 3337468Ssam } 334*33452Skarels impstart(sc->css_imp); 3357468Ssam } 3367468Ssam 3377468Ssam /* 3387468Ssam * Input interrupt handler 3397468Ssam */ 3407468Ssam cssrint(unit) 3417468Ssam { 3427468Ssam register struct css_softc *sc = &css_softc[unit]; 3437468Ssam register struct cssdevice *addr; 3447468Ssam struct mbuf *m; 3457468Ssam int len, info; 3467468Ssam 347*33452Skarels sc->css_imp->imp_if.if_ipackets++; 3487468Ssam 3497468Ssam /* 3507468Ssam * Purge BDP; flush message if error indicated. 3517468Ssam */ 3527468Ssam 3537468Ssam addr = (struct cssdevice *)cssinfo[unit]->ui_addr; 3547468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 3557468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp); 3567468Ssam if (addr->css_icsr & CSS_ERR) { 3577468Ssam printf("css%d: recv error, csr=%b\n", unit, 3587468Ssam addr->css_icsr, CSS_INBITS); 359*33452Skarels sc->css_imp->imp_if.if_ierrors++; 3607468Ssam sc->css_flush = 1; 3617468Ssam } 3627468Ssam 3637468Ssam if (sc->css_flush) { 3647468Ssam if (addr->css_icsr & IN_EOM) 3657468Ssam sc->css_flush = 0; 3667468Ssam goto setup; 3677468Ssam } 3687468Ssam 369*33452Skarels len = IMP_RCVBUF + (addr->css_iwc << 1); 370*33452Skarels if (len < 0 || len > IMP_RCVBUF) { 3717468Ssam printf("css%d: bad length=%d\n", len); 372*33452Skarels sc->css_imp->imp_if.if_ierrors++; 3737468Ssam goto setup; 3747468Ssam } 3757468Ssam 3767468Ssam /* 37724800Skarels * The offset parameter is always 0 since using 3787468Ssam * trailers on the ARPAnet is insane. 3797468Ssam */ 380*33452Skarels m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_imp->imp_if); 3817468Ssam if (m == 0) 3827468Ssam goto setup; 3837468Ssam if ((addr->css_icsr & IN_EOM) == 0) { 3847468Ssam if (sc->css_iq) 3857468Ssam m_cat(sc->css_iq, m); 3867468Ssam else 3877468Ssam sc->css_iq = m; 3887468Ssam goto setup; 3897468Ssam } 3907468Ssam if (sc->css_iq) { 3917468Ssam m_cat(sc->css_iq, m); 3927468Ssam m = sc->css_iq; 3937468Ssam sc->css_iq = 0; 3947468Ssam } 3957468Ssam impinput(unit, m); 3967468Ssam 3977468Ssam setup: 3987468Ssam /* 3997468Ssam * Setup for next message. 4007468Ssam */ 4017468Ssam info = sc->css_ifuba.ifu_r.ifrw_info; 4027468Ssam addr->css_iba = (u_short)info; 403*33452Skarels addr->css_iwc = - (IMP_RCVBUF >> 1); 4047468Ssam addr->css_icsr = 4057468Ssam IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 4067468Ssam } 40725270Sbloom #endif 408