1*21778Skarels /* if_css.c 6.3 85/06/03 */ 27468Ssam 37468Ssam #include "css.h" 47468Ssam 57468Ssam /* 67468Ssam * DEC/CSS IMP11-A ARPAnet IMP interface driver. 77468Ssam * Since "imp11a" is such a mouthful, it is called 87468Ssam * "css" after the LH/DH being called "acc". 97468Ssam * 107468Ssam * Configuration notes: 117468Ssam * 127468Ssam * As delivered from DEC/CSS, it 137468Ssam * is addressed and vectored as two DR11-B's. This makes 147468Ssam * Autoconfig almost IMPOSSIBLE. To make it work, the 157468Ssam * interrupt vectors must be restrapped to make the vectors 167468Ssam * consecutive. The 020 hole between the CSR addresses is 177468Ssam * tolerated, althought that could be cleaned-up also. 187468Ssam * 197468Ssam * Additionally, the TRANSMIT side of the IMP11-A has the 207468Ssam * lower address of the two subunits, so the vector ordering 217468Ssam * in the CONFIG file is reversed from most other devices. 227468Ssam * It should be: 237468Ssam * 247468Ssam * device css0 .... cssxint cssrint 257468Ssam * 267468Ssam * If you get it wrong, it will still autoconfig, but will just 277468Ssam * sit there with RECIEVE IDLE indicated on the front panel. 287468Ssam */ 299794Ssam #include "../machine/pte.h" 307468Ssam 3117110Sbloom #include "param.h" 3217110Sbloom #include "systm.h" 3317110Sbloom #include "mbuf.h" 3417110Sbloom #include "buf.h" 3517110Sbloom #include "protosw.h" 3617110Sbloom #include "socket.h" 3717110Sbloom #include "vmmac.h" 388459Sroot 397468Ssam #include "../net/if.h" 408415Swnj #include "../netimp/if_imp.h" 418459Sroot 428459Sroot #include "../vax/cpu.h" 438459Sroot #include "../vax/mtpr.h" 4417110Sbloom #include "if_cssreg.h" 4517110Sbloom #include "if_uba.h" 468459Sroot #include "../vaxuba/ubareg.h" 478459Sroot #include "../vaxuba/ubavar.h" 487468Ssam 497468Ssam int cssprobe(), cssattach(), cssrint(), cssxint(); 507468Ssam struct uba_device *cssinfo[NCSS]; 517468Ssam u_short cssstd[] = { 0 }; 527468Ssam struct uba_driver cssdriver = 537468Ssam { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo }; 547468Ssam #define CSSUNIT(x) minor(x) 557468Ssam 567468Ssam int cssinit(), cssstart(), cssreset(); 577468Ssam 587468Ssam /* 597468Ssam * "Lower half" of IMP interface driver. 607468Ssam * 617468Ssam * Each IMP interface is handled by a common module which handles 627468Ssam * the IMP-host protocol and a hardware driver which manages the 637468Ssam * hardware specific details of talking with the IMP. 647468Ssam * 657468Ssam * The hardware portion of the IMP driver handles DMA and related 667468Ssam * management of UNIBUS resources. The IMP protocol module interprets 677468Ssam * contents of these messages and "controls" the actions of the 687468Ssam * hardware module during IMP resets, but not, for instance, during 697468Ssam * UNIBUS resets. 707468Ssam * 717468Ssam * The two modules are coupled at "attach time", and ever after, 727468Ssam * through the imp interface structure. Higher level protocols, 737468Ssam * e.g. IP, interact with the IMP driver, rather than the CSS. 747468Ssam */ 757468Ssam struct css_softc { 767468Ssam struct ifnet *css_if; /* pointer to IMP's ifnet struct */ 777468Ssam struct impcb *css_ic; /* data structure shared with IMP */ 787468Ssam struct ifuba css_ifuba; /* UNIBUS resources */ 797468Ssam struct mbuf *css_iq; /* input reassembly queue */ 807468Ssam short css_olen; /* size of last message sent */ 817468Ssam char css_flush; /* flush remainder of message */ 827468Ssam } css_softc[NCSS]; 837468Ssam 847468Ssam /* 857468Ssam * Reset the IMP and cause a transmitter interrupt by 867468Ssam * performing a null DMA. 877468Ssam */ 887468Ssam cssprobe(reg) 897468Ssam caddr_t reg; 907468Ssam { 917468Ssam register int br, cvec; /* r11, r10 value-result */ 927468Ssam register struct cssdevice *addr = (struct cssdevice *)reg; 937468Ssam 947468Ssam #ifdef lint 957468Ssam br = 0; cvec = br; br = cvec; 967468Ssam cssrint(0); cssxint(0); 977468Ssam #endif 987468Ssam 997468Ssam 1007468Ssam addr->css_icsr = CSS_CLR; 1017468Ssam addr->css_ocsr = CSS_CLR; 1027468Ssam DELAY(50000); 1037468Ssam addr->css_icsr = 0; 1047468Ssam addr->css_ocsr = 0; 1057468Ssam DELAY(50000); 1067468Ssam 1077468Ssam addr->css_oba = 0; 1087468Ssam addr->css_owc = -1; 1097468Ssam addr->css_ocsr = CSS_IE | CSS_GO; /* enable interrupts */ 1107468Ssam DELAY(50000); 1117468Ssam addr->css_ocsr = 0; 1127468Ssam 1137468Ssam return (1); 1147468Ssam } 1157468Ssam 1167468Ssam /* 1177468Ssam * Call the IMP module to allow it to set up its internal 1187468Ssam * state, then tie the two modules together by setting up 1197468Ssam * the back pointers to common data structures. 1207468Ssam */ 1217468Ssam cssattach(ui) 1227468Ssam struct uba_device *ui; 1237468Ssam { 1247468Ssam register struct css_softc *sc = &css_softc[ui->ui_unit]; 1257468Ssam register struct impcb *ip; 1267468Ssam struct ifimpcb { 1277468Ssam struct ifnet ifimp_if; 1287468Ssam struct impcb ifimp_impcb; 1297468Ssam } *ifimp; 1307468Ssam 1318831Sroot if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0) 1327468Ssam panic("cssattach"); /* XXX */ 1337468Ssam sc->css_if = &ifimp->ifimp_if; 1347468Ssam ip = &ifimp->ifimp_impcb; 1357468Ssam sc->css_ic = ip; 1367468Ssam ip->ic_init = cssinit; 1377468Ssam ip->ic_start = cssstart; 1387468Ssam sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16; 1397468Ssam #ifdef notdef 1407468Ssam sc->css_ifuba.ifu_flags =| UBA_NEEDBDP; 1417468Ssam #endif 1427468Ssam } 1437468Ssam 1447468Ssam /* 1457468Ssam * Reset interface after UNIBUS reset. 1467468Ssam * If interface is on specified uba, reset its state. 1477468Ssam */ 1487468Ssam cssreset(unit, uban) 1497468Ssam int unit, uban; 1507468Ssam { 1517468Ssam register struct uba_device *ui; 1527468Ssam struct css_softc *sc; 1537468Ssam 1547468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 || 1557468Ssam ui->ui_ubanum != uban) 1567468Ssam return; 1577468Ssam printf(" css%d", unit); 1587468Ssam sc = &css_softc[unit]; 159*21778Skarels sc->css_if->if_flags &= ~IFF_RUNNING; 1607468Ssam /* must go through IMP to allow it to set state */ 1617468Ssam (*sc->css_if->if_init)(unit); 1627468Ssam } 1637468Ssam 1647468Ssam /* 1657468Ssam * Initialize interface: clear recorded pending operations, 1667468Ssam * and retrieve, and reinitialize UNIBUS resources. 1677468Ssam */ 1687468Ssam cssinit(unit) 1697468Ssam int unit; 1707468Ssam { 1717468Ssam register struct css_softc *sc; 1727468Ssam register struct uba_device *ui; 1737468Ssam register struct cssdevice *addr; 1747468Ssam int x, info; 1757468Ssam 1767468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) { 1777468Ssam printf("css%d: not alive\n", unit); 1787468Ssam return(0); 1797468Ssam } 1807468Ssam sc = &css_softc[unit]; 1817468Ssam 1827468Ssam /* 1837468Ssam * Header length is 0 to if_ubainit since we have to pass 1847468Ssam * the IMP leader up to the protocol interpretaion 1857468Ssam * routines. If we had the deader length as 1867468Ssam * sizeof(struct imp_leader), then the if_ routines 1877468Ssam * would assume we handle it on input and output. 1887468Ssam */ 1897468Ssam 1907468Ssam if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) { 1917468Ssam printf("css%d: can't initialize\n", unit); 1927468Ssam ui->ui_alive = 0; 1937468Ssam return(0); 1947468Ssam } 195*21778Skarels sc->css_if->if_flags |= IFF_RUNNING; 1967468Ssam addr = (struct cssdevice *)ui->ui_addr; 1977468Ssam 1987468Ssam /* reset the imp interface. */ 1997468Ssam x = spl5(); 2007468Ssam addr->css_icsr = CSS_CLR; 2017468Ssam addr->css_ocsr = CSS_CLR; 2027468Ssam DELAY(100); 2037468Ssam addr->css_icsr = 0; 2047468Ssam addr->css_ocsr = 0; 2057468Ssam addr->css_icsr = IN_HRDY; /* close the relay */ 2067468Ssam DELAY(5000); 2077468Ssam splx(x); 2087468Ssam 2097468Ssam /* 2107468Ssam * This may hang if the imp isn't really there. 2117468Ssam * Will test and verify safe operation. 2127468Ssam */ 2137468Ssam 2147468Ssam x = 500; 2157468Ssam while (x-- > 0) { 2167468Ssam if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY) 2177468Ssam break; 2187468Ssam addr->css_icsr = IN_HRDY; /* close the relay */ 2197468Ssam DELAY(5000); 2207468Ssam } 2217468Ssam 2227468Ssam if (x <= 0) { 2237468Ssam printf("css%d: imp doesn't respond, icsr=%b\n", unit, 2247468Ssam CSS_INBITS, addr->css_icsr); 2257468Ssam goto down; 2267468Ssam } 2277468Ssam 2287468Ssam /* 2297468Ssam * Put up a read. We can't restart any outstanding writes 2307468Ssam * until we're back in synch with the IMP (i.e. we've flushed 2317468Ssam * the NOOPs it throws at us). 2327468Ssam * Note: IMPMTU includes the leader. 2337468Ssam */ 2347468Ssam 2357468Ssam x = spl5(); 2367468Ssam info = sc->css_ifuba.ifu_r.ifrw_info; 2377468Ssam addr->css_iba = (u_short)info; 2387468Ssam addr->css_iwc = -(IMPMTU >> 1); 2397468Ssam addr->css_icsr = 2407468Ssam IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 2417468Ssam splx(x); 2427468Ssam return(1); 2437468Ssam 2447468Ssam down: 2457468Ssam ui->ui_alive = 0; 2467468Ssam return(0); 2477468Ssam } 2487468Ssam 2497468Ssam /* 2507468Ssam * Start output on an interface. 2517468Ssam */ 2527468Ssam cssstart(dev) 2537468Ssam dev_t dev; 2547468Ssam { 2557468Ssam int unit = CSSUNIT(dev), info; 2567468Ssam struct uba_device *ui = cssinfo[unit]; 2577468Ssam register struct css_softc *sc = &css_softc[unit]; 2587468Ssam register struct cssdevice *addr; 2597468Ssam struct mbuf *m; 2607468Ssam u_short cmd; 2617468Ssam 2627468Ssam if (sc->css_ic->ic_oactive) 2637468Ssam goto restart; 2647468Ssam 2657468Ssam /* 2667468Ssam * Not already active, deqeue a request and 2677468Ssam * map it onto the UNIBUS. If no more 2687468Ssam * requeusts, just return. 2697468Ssam */ 2707468Ssam IF_DEQUEUE(&sc->css_if->if_snd, m); 2717468Ssam if (m == 0) { 2727468Ssam sc->css_ic->ic_oactive = 0; 2737468Ssam return; 2747468Ssam } 2757468Ssam sc->css_olen = if_wubaput(&sc->css_ifuba, m); 2767468Ssam 2777468Ssam restart: 2787468Ssam /* 2797468Ssam * Have request mapped to UNIBUS for transmission. 2807468Ssam * Purge any stale data from the BDP, and start the output. 2817468Ssam */ 2827468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 2837468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp); 2847468Ssam addr = (struct cssdevice *)ui->ui_addr; 2857468Ssam info = sc->css_ifuba.ifu_w.ifrw_info; 2867468Ssam addr->css_oba = (u_short)info; 2877468Ssam addr->css_owc = -((sc->css_olen + 1) >> 1); 2887468Ssam cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO; 2897468Ssam addr->css_ocsr = cmd; 2907468Ssam sc->css_ic->ic_oactive = 1; 2917468Ssam } 2927468Ssam 2937468Ssam /* 2947468Ssam * Output interrupt handler. 2957468Ssam */ 2967468Ssam cssxint(unit) 2977468Ssam { 2987468Ssam register struct uba_device *ui = cssinfo[unit]; 2997468Ssam register struct css_softc *sc = &css_softc[unit]; 3007468Ssam register struct cssdevice *addr; 3017468Ssam 3027468Ssam addr = (struct cssdevice *)ui->ui_addr; 3037468Ssam if (sc->css_ic->ic_oactive == 0) { 3047468Ssam printf("css%d: stray output interrupt csr=%b\n", 3057468Ssam unit, addr->css_ocsr, CSS_OUTBITS); 3067468Ssam return; 3077468Ssam } 3087468Ssam sc->css_if->if_opackets++; 3097468Ssam sc->css_ic->ic_oactive = 0; 3107468Ssam if (addr->css_ocsr & CSS_ERR){ 3117468Ssam sc->css_if->if_oerrors++; 3127468Ssam printf("css%d: output error, ocsr=%b icsr=%b\n", unit, 3137468Ssam addr->css_ocsr, CSS_OUTBITS, 3147468Ssam addr->css_icsr, CSS_INBITS); 3157468Ssam } 3167468Ssam if (sc->css_ifuba.ifu_xtofree) { 3177468Ssam m_freem(sc->css_ifuba.ifu_xtofree); 3187468Ssam sc->css_ifuba.ifu_xtofree = 0; 3197468Ssam } 3207468Ssam if (sc->css_if->if_snd.ifq_head) 3217468Ssam cssstart(unit); 3227468Ssam } 3237468Ssam 3247468Ssam /* 3257468Ssam * Input interrupt handler 3267468Ssam */ 3277468Ssam cssrint(unit) 3287468Ssam { 3297468Ssam register struct css_softc *sc = &css_softc[unit]; 3307468Ssam register struct cssdevice *addr; 3317468Ssam struct mbuf *m; 3327468Ssam int len, info; 3337468Ssam 3347468Ssam sc->css_if->if_ipackets++; 3357468Ssam 3367468Ssam /* 3377468Ssam * Purge BDP; flush message if error indicated. 3387468Ssam */ 3397468Ssam 3407468Ssam addr = (struct cssdevice *)cssinfo[unit]->ui_addr; 3417468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 3427468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp); 3437468Ssam if (addr->css_icsr & CSS_ERR) { 3447468Ssam printf("css%d: recv error, csr=%b\n", unit, 3457468Ssam addr->css_icsr, CSS_INBITS); 3467468Ssam sc->css_if->if_ierrors++; 3477468Ssam sc->css_flush = 1; 3487468Ssam } 3497468Ssam 3507468Ssam if (sc->css_flush) { 3517468Ssam if (addr->css_icsr & IN_EOM) 3527468Ssam sc->css_flush = 0; 3537468Ssam goto setup; 3547468Ssam } 3557468Ssam 3567468Ssam len = IMPMTU + (addr->css_iwc << 1); 3577468Ssam if (len < 0 || len > IMPMTU) { 3587468Ssam printf("css%d: bad length=%d\n", len); 3597468Ssam sc->css_if->if_ierrors++; 3607468Ssam goto setup; 3617468Ssam } 3627468Ssam 3637468Ssam /* 3647468Ssam * The last parameter is always 0 since using 3657468Ssam * trailers on the ARPAnet is insane. 3667468Ssam */ 3677468Ssam m = if_rubaget(&sc->css_ifuba, len, 0); 3687468Ssam if (m == 0) 3697468Ssam goto setup; 3707468Ssam if ((addr->css_icsr & IN_EOM) == 0) { 3717468Ssam if (sc->css_iq) 3727468Ssam m_cat(sc->css_iq, m); 3737468Ssam else 3747468Ssam sc->css_iq = m; 3757468Ssam goto setup; 3767468Ssam } 3777468Ssam if (sc->css_iq) { 3787468Ssam m_cat(sc->css_iq, m); 3797468Ssam m = sc->css_iq; 3807468Ssam sc->css_iq = 0; 3817468Ssam } 3827468Ssam impinput(unit, m); 3837468Ssam 3847468Ssam setup: 3857468Ssam /* 3867468Ssam * Setup for next message. 3877468Ssam */ 3887468Ssam info = sc->css_ifuba.ifu_r.ifrw_info; 3897468Ssam addr->css_iba = (u_short)info; 3907468Ssam addr->css_iwc = - (IMPMTU >> 1); 3917468Ssam addr->css_icsr = 3927468Ssam IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 3937468Ssam } 394