1*8415Swnj /* if_css.c 4.2 82/10/09 */ 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 */ 297468Ssam 307468Ssam #include "../h/param.h" 317468Ssam #include "../h/systm.h" 327468Ssam #include "../h/mbuf.h" 337468Ssam #include "../h/pte.h" 347468Ssam #include "../h/buf.h" 357468Ssam #include "../h/protosw.h" 367468Ssam #include "../h/socket.h" 377468Ssam #include "../h/ubareg.h" 387468Ssam #include "../h/ubavar.h" 397468Ssam #include "../h/cpu.h" 407468Ssam #include "../h/mtpr.h" 417468Ssam #include "../h/vmmac.h" 42*8415Swnj #include "../vaxif/if_css.h" 437468Ssam #include "../net/if.h" 44*8415Swnj #include "../netimp/if_imp.h" 45*8415Swnj #include "../vaxif/if_uba.h" 467468Ssam 477468Ssam int cssprobe(), cssattach(), cssrint(), cssxint(); 487468Ssam struct uba_device *cssinfo[NCSS]; 497468Ssam u_short cssstd[] = { 0 }; 507468Ssam struct uba_driver cssdriver = 517468Ssam { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo }; 527468Ssam #define CSSUNIT(x) minor(x) 537468Ssam 547468Ssam int cssinit(), cssstart(), cssreset(); 557468Ssam 567468Ssam /* 577468Ssam * "Lower half" of IMP interface driver. 587468Ssam * 597468Ssam * Each IMP interface is handled by a common module which handles 607468Ssam * the IMP-host protocol and a hardware driver which manages the 617468Ssam * hardware specific details of talking with the IMP. 627468Ssam * 637468Ssam * The hardware portion of the IMP driver handles DMA and related 647468Ssam * management of UNIBUS resources. The IMP protocol module interprets 657468Ssam * contents of these messages and "controls" the actions of the 667468Ssam * hardware module during IMP resets, but not, for instance, during 677468Ssam * UNIBUS resets. 687468Ssam * 697468Ssam * The two modules are coupled at "attach time", and ever after, 707468Ssam * through the imp interface structure. Higher level protocols, 717468Ssam * e.g. IP, interact with the IMP driver, rather than the CSS. 727468Ssam */ 737468Ssam struct css_softc { 747468Ssam struct ifnet *css_if; /* pointer to IMP's ifnet struct */ 757468Ssam struct impcb *css_ic; /* data structure shared with IMP */ 767468Ssam struct ifuba css_ifuba; /* UNIBUS resources */ 777468Ssam struct mbuf *css_iq; /* input reassembly queue */ 787468Ssam short css_olen; /* size of last message sent */ 797468Ssam char css_flush; /* flush remainder of message */ 807468Ssam } css_softc[NCSS]; 817468Ssam 827468Ssam /* 837468Ssam * Reset the IMP and cause a transmitter interrupt by 847468Ssam * performing a null DMA. 857468Ssam */ 867468Ssam cssprobe(reg) 877468Ssam caddr_t reg; 887468Ssam { 897468Ssam register int br, cvec; /* r11, r10 value-result */ 907468Ssam register struct cssdevice *addr = (struct cssdevice *)reg; 917468Ssam 927468Ssam COUNT(CSSPROBE); 937468Ssam #ifdef lint 947468Ssam br = 0; cvec = br; br = cvec; 957468Ssam cssrint(0); cssxint(0); 967468Ssam #endif 977468Ssam 987468Ssam 997468Ssam addr->css_icsr = CSS_CLR; 1007468Ssam addr->css_ocsr = CSS_CLR; 1017468Ssam DELAY(50000); 1027468Ssam addr->css_icsr = 0; 1037468Ssam addr->css_ocsr = 0; 1047468Ssam DELAY(50000); 1057468Ssam 1067468Ssam addr->css_oba = 0; 1077468Ssam addr->css_owc = -1; 1087468Ssam addr->css_ocsr = CSS_IE | CSS_GO; /* enable interrupts */ 1097468Ssam DELAY(50000); 1107468Ssam addr->css_ocsr = 0; 1117468Ssam 1127468Ssam return (1); 1137468Ssam } 1147468Ssam 1157468Ssam /* 1167468Ssam * Call the IMP module to allow it to set up its internal 1177468Ssam * state, then tie the two modules together by setting up 1187468Ssam * the back pointers to common data structures. 1197468Ssam */ 1207468Ssam cssattach(ui) 1217468Ssam struct uba_device *ui; 1227468Ssam { 1237468Ssam register struct css_softc *sc = &css_softc[ui->ui_unit]; 1247468Ssam register struct impcb *ip; 1257468Ssam struct ifimpcb { 1267468Ssam struct ifnet ifimp_if; 1277468Ssam struct impcb ifimp_impcb; 1287468Ssam } *ifimp; 1297468Ssam 1307468Ssam COUNT(CSSATTACH); 1317468Ssam if ((ifimp = (struct ifimpcb *)impattach(ui)) == 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 COUNT(CSSCLR); 1557468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 || 1567468Ssam ui->ui_ubanum != uban) 1577468Ssam return; 1587468Ssam printf(" css%d", unit); 1597468Ssam sc = &css_softc[unit]; 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 COUNT(CSSINIT); 1777468Ssam if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) { 1787468Ssam printf("css%d: not alive\n", unit); 1797468Ssam return(0); 1807468Ssam } 1817468Ssam sc = &css_softc[unit]; 1827468Ssam 1837468Ssam /* 1847468Ssam * Header length is 0 to if_ubainit since we have to pass 1857468Ssam * the IMP leader up to the protocol interpretaion 1867468Ssam * routines. If we had the deader length as 1877468Ssam * sizeof(struct imp_leader), then the if_ routines 1887468Ssam * would assume we handle it on input and output. 1897468Ssam */ 1907468Ssam 1917468Ssam if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) { 1927468Ssam printf("css%d: can't initialize\n", unit); 1937468Ssam ui->ui_alive = 0; 1947468Ssam return(0); 1957468Ssam } 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 COUNT(CSSSTART); 2637468Ssam if (sc->css_ic->ic_oactive) 2647468Ssam goto restart; 2657468Ssam 2667468Ssam /* 2677468Ssam * Not already active, deqeue a request and 2687468Ssam * map it onto the UNIBUS. If no more 2697468Ssam * requeusts, just return. 2707468Ssam */ 2717468Ssam IF_DEQUEUE(&sc->css_if->if_snd, m); 2727468Ssam if (m == 0) { 2737468Ssam sc->css_ic->ic_oactive = 0; 2747468Ssam return; 2757468Ssam } 2767468Ssam sc->css_olen = if_wubaput(&sc->css_ifuba, m); 2777468Ssam 2787468Ssam restart: 2797468Ssam /* 2807468Ssam * Have request mapped to UNIBUS for transmission. 2817468Ssam * Purge any stale data from the BDP, and start the output. 2827468Ssam */ 2837468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 2847468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp); 2857468Ssam addr = (struct cssdevice *)ui->ui_addr; 2867468Ssam info = sc->css_ifuba.ifu_w.ifrw_info; 2877468Ssam addr->css_oba = (u_short)info; 2887468Ssam addr->css_owc = -((sc->css_olen + 1) >> 1); 2897468Ssam cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO; 2907468Ssam addr->css_ocsr = cmd; 2917468Ssam sc->css_ic->ic_oactive = 1; 2927468Ssam } 2937468Ssam 2947468Ssam /* 2957468Ssam * Output interrupt handler. 2967468Ssam */ 2977468Ssam cssxint(unit) 2987468Ssam { 2997468Ssam register struct uba_device *ui = cssinfo[unit]; 3007468Ssam register struct css_softc *sc = &css_softc[unit]; 3017468Ssam register struct cssdevice *addr; 3027468Ssam 3037468Ssam COUNT(CSSXINT); 3047468Ssam addr = (struct cssdevice *)ui->ui_addr; 3057468Ssam if (sc->css_ic->ic_oactive == 0) { 3067468Ssam printf("css%d: stray output interrupt csr=%b\n", 3077468Ssam unit, addr->css_ocsr, CSS_OUTBITS); 3087468Ssam return; 3097468Ssam } 3107468Ssam sc->css_if->if_opackets++; 3117468Ssam sc->css_ic->ic_oactive = 0; 3127468Ssam if (addr->css_ocsr & CSS_ERR){ 3137468Ssam sc->css_if->if_oerrors++; 3147468Ssam printf("css%d: output error, ocsr=%b icsr=%b\n", unit, 3157468Ssam addr->css_ocsr, CSS_OUTBITS, 3167468Ssam addr->css_icsr, CSS_INBITS); 3177468Ssam } 3187468Ssam if (sc->css_ifuba.ifu_xtofree) { 3197468Ssam m_freem(sc->css_ifuba.ifu_xtofree); 3207468Ssam sc->css_ifuba.ifu_xtofree = 0; 3217468Ssam } 3227468Ssam if (sc->css_if->if_snd.ifq_head) 3237468Ssam cssstart(unit); 3247468Ssam } 3257468Ssam 3267468Ssam /* 3277468Ssam * Input interrupt handler 3287468Ssam */ 3297468Ssam cssrint(unit) 3307468Ssam { 3317468Ssam register struct css_softc *sc = &css_softc[unit]; 3327468Ssam register struct cssdevice *addr; 3337468Ssam register struct ifqueue *inq; 3347468Ssam struct mbuf *m; 3357468Ssam int len, info; 3367468Ssam 3377468Ssam COUNT(CSSRINT); 3387468Ssam sc->css_if->if_ipackets++; 3397468Ssam 3407468Ssam /* 3417468Ssam * Purge BDP; flush message if error indicated. 3427468Ssam */ 3437468Ssam 3447468Ssam addr = (struct cssdevice *)cssinfo[unit]->ui_addr; 3457468Ssam if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP) 3467468Ssam UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp); 3477468Ssam if (addr->css_icsr & CSS_ERR) { 3487468Ssam printf("css%d: recv error, csr=%b\n", unit, 3497468Ssam addr->css_icsr, CSS_INBITS); 3507468Ssam sc->css_if->if_ierrors++; 3517468Ssam sc->css_flush = 1; 3527468Ssam } 3537468Ssam 3547468Ssam if (sc->css_flush) { 3557468Ssam if (addr->css_icsr & IN_EOM) 3567468Ssam sc->css_flush = 0; 3577468Ssam goto setup; 3587468Ssam } 3597468Ssam 3607468Ssam len = IMPMTU + (addr->css_iwc << 1); 3617468Ssam if (len < 0 || len > IMPMTU) { 3627468Ssam printf("css%d: bad length=%d\n", len); 3637468Ssam sc->css_if->if_ierrors++; 3647468Ssam goto setup; 3657468Ssam } 3667468Ssam 3677468Ssam /* 3687468Ssam * The last parameter is always 0 since using 3697468Ssam * trailers on the ARPAnet is insane. 3707468Ssam */ 3717468Ssam m = if_rubaget(&sc->css_ifuba, len, 0); 3727468Ssam if (m == 0) 3737468Ssam goto setup; 3747468Ssam if ((addr->css_icsr & IN_EOM) == 0) { 3757468Ssam if (sc->css_iq) 3767468Ssam m_cat(sc->css_iq, m); 3777468Ssam else 3787468Ssam sc->css_iq = m; 3797468Ssam goto setup; 3807468Ssam } 3817468Ssam if (sc->css_iq) { 3827468Ssam m_cat(sc->css_iq, m); 3837468Ssam m = sc->css_iq; 3847468Ssam sc->css_iq = 0; 3857468Ssam } 3867468Ssam impinput(unit, m); 3877468Ssam 3887468Ssam setup: 3897468Ssam /* 3907468Ssam * Setup for next message. 3917468Ssam */ 3927468Ssam info = sc->css_ifuba.ifu_r.ifrw_info; 3937468Ssam addr->css_iba = (u_short)info; 3947468Ssam addr->css_iwc = - (IMPMTU >> 1); 3957468Ssam addr->css_icsr = 3967468Ssam IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO; 3977468Ssam } 398