1*8492Sroot /* lpa.c 4.7 82/10/10 */ 28476Sroot 36968Ssam #include "lpa.h" 46968Ssam #if NLPA > 0 56968Ssam 66968Ssam #include "../h/param.h" 76968Ssam #include "../h/dir.h" 86968Ssam #include "../h/user.h" 96968Ssam #include "../h/buf.h" 106968Ssam #include "../h/proc.h" 116968Ssam #include "../h/ioctl.h" 127729Sroot #include "../h/uio.h" 136968Ssam 148476Sroot #include "../vaxuba/ubavar.h" 158476Sroot 166968Ssam /* 17*8492Sroot * LPA driver for -- Asa Romberger 18*8492Sroot * 196968Ssam * open 206968Ssam * write microcode 216968Ssam * write dedicated mode dispatch table 226968Ssam * ioctl TIOCSETP to set parameters 236968Ssam * struct iocb { 246968Ssam * short *baddr; buffer address 256968Ssam * short rate; - 1,000,000 / frequency in Hz 266968Ssam * short wc; 15-13 = number of buffers - 1 276968Ssam * 12-0 = buffer size in words 286968Ssam * } iocb; 296968Ssam * read - 1 character indicating buffer index 306968Ssam * fill or empty buffer 316968Ssam * minor device number = DDCCCCCC where: 326968Ssam * DD = 00 for analog input 336968Ssam * = 01 for analog output 346968Ssam * CCCCCC = channel number 356968Ssam */ 366968Ssam * define NOMCODE to eliminate the microcode download check 376968Ssam */ 38*8492Sroot /* #define TRACELPA */ 39*8492Sroot /* #define NOMCODE */ 406968Ssam 416968Ssam #ifdef TRACELPA 426968Ssam # define TRACER(x) printf(x) 436968Ssam # define TRACERN(x, d) printf(x, d) 446968Ssam #else 456968Ssam # define TRACER(x) 466968Ssam # define TRACERN(x, d) 476968Ssam #endif 486968Ssam 496968Ssam /* PRIORITY AT WHICH PROGRAM SHOULD RUN */ 506968Ssam /* THIS SHOULD EVENTUALLY TELL UNIX THIS IS A REAL-TIME DEVICE */ 516968Ssam 526968Ssam #define NICE 0 536968Ssam 54*8492Sroot #define inc(v) (sc->v = ((sc->v + 1) % sc->sc_nbuf)) 556968Ssam 56*8492Sroot #define LPAPRI (PZERO + 0) 576968Ssam #define LPAUNIT(dev) 0 586968Ssam #define LPADEVICE(dev) (((dev) >> 6) & 03) 596968Ssam #define LPACHANNEL(dev) ((dev) & 077) 606968Ssam 61*8492Sroot int lpaprobe(), lpaattach(), lpaiintr(), lpaointr(); 62*8492Sroot u_short lpastd[] = {0170460, 0}; 63*8492Sroot struct uba_device *lpadinfo[NLPA]; 646968Ssam struct uba_driver lpadriver = 65*8492Sroot {lpaprobe, 0, lpaattach, 0, lpastd, "lpa", lpadinfo, 0, 0, 0 }; 666968Ssam 676968Ssam struct lpa_softc { 686968Ssam int sc_flag; /* flags, as defined below */ 696968Ssam int sc_device; /* device: 0 = analog in, 1 = analog out */ 706968Ssam int sc_channel; /* device channel number */ 716968Ssam struct buf sc_ubuffer; /* user buffer header */ 726968Ssam int sc_ubabuf; /* uba allocation pointer for buffer */ 736968Ssam int sc_ubufn; /* present buffer that user is accessing */ 746968Ssam int sc_lbufn; /* present buffer that lpa is accessing */ 756968Ssam int sc_lbufnx; /* next buffer for lpa (value in ustat) */ 766968Ssam int sc_nbuf; /* number of buffers */ 776968Ssam int sc_count; /* buffer size in words */ 786968Ssam short sc_ustat; /* user status word */ 796968Ssam struct buf sc_ustatbuf; /* dummy user status word buffer for ubasetup */ 806968Ssam int sc_ubaustat; /* uba allocation pointer for ustat */ 816968Ssam struct buf *sc_buffer; /* scratch buffer header */ 826968Ssam int sc_start; /* 0 if lpa operation has been started */ 836968Ssam } lpa_softc[NLPA]; 84*8492Sroot 85*8492Sroot /* flags for sc_flag */ 866968Ssam #define OPEN 01 /* device is open */ 876968Ssam #define MCODE 02 /* microcode has been loaded */ 886968Ssam #define DMDT 04 /* dedicated mode dispatch table loaded */ 896968Ssam #define STTY 010 /* stty call and device initialized */ 906968Ssam #define SLEEP 020 /* sleeping */ 91*8492Sroot 92*8492Sroot /* bits for ustat */ 936968Ssam #define DONE 0100000 /* done */ 946968Ssam #define STOP 0040000 /* stop data transfer */ 956968Ssam #define NBI 0003400 /* next buffer index */ 966968Ssam #define LBI 0000003 /* last buffer index */ 976968Ssam 986968Ssam struct lpadevice { 996968Ssam short lcim; /* control in and maintenance */ 1006968Ssam short lcos; /* control and status out */ 1016968Ssam short lrda; /* request description array address word */ 1026968Ssam short lms; /* maintenance status */ 1036968Ssam }; 104*8492Sroot 105*8492Sroot /* control in and maintenance register bits */ 1066968Ssam #define READYI 0000200 /* ready in */ 1076968Ssam #define IIE 0000100 /* in interrupt enable */ 1086968Ssam #define RDAEXT 0000014 /* rda address extension */ 1096968Ssam #define RDAEXTOFFSET 2 /* offset of RDAEXT from right side */ 1106968Ssam #define GO 0000001 /* go */ 1116968Ssam #define RUN 0100000 /* run */ 1126968Ssam #define RESET 0040000 /* reset */ 1136968Ssam #define CWRITE 0020000 /* cram write */ 1146968Ssam #define EA 0004000 /* enable arbitration */ 1156968Ssam #define ROMO 0002000 /* rom O */ 1166968Ssam #define ROMI 0001000 /* rom I */ 1176968Ssam #define SMICRO 0000400 /* step microprocessor */ 118*8492Sroot 119*8492Sroot /* control and status out register bits */ 1206968Ssam #define READYO 0200 /* ready out */ 1216968Ssam #define OIE 0100 /* out interrupt enable */ 1226968Ssam #define UINDEX 0007 /* user index */ 1236968Ssam #define ERROR 0100000 /* error */ 1246968Ssam #define ESTAT 0060000 /* error status */ 1256968Ssam #define ESCODE 0017400 /* error sub code */ 1266968Ssam #define ECODE 0077400 /* error status + error sub code */ 1276968Ssam #define OVERRUN 0243 /* overrun error */ 1286968Ssam 129*8492Sroot /* LPA COMMAND DESCRIPTION AREA */ 1306968Ssam 131*8492Sroot /* INIT COMMAND */ 1326968Ssam #define INIT 0 /* mode */ 1336968Ssam #define MCVERS 4 /* microcode version */ 1346968Ssam #define ACLOCKA 0170404 /* LPA bus addresses */ 1356968Ssam #define ACLOCKB 0170432 1366968Ssam #define AAD1 0170400 1376968Ssam #define AAD2 1 /* 0170440 - DOES NOT EXIST */ 1386968Ssam #define ADA 0170420 1396968Ssam #define ADIO1 1 /* 0167770 - DOES NOT EXIST */ 1406968Ssam #define ADIO2 1 /* 0167760 - DOES NOT EXIST */ 1416968Ssam #define ADIO3 1 /* 0167750 - DOES NOT EXIST */ 1426968Ssam #define ADIO4 1 /* 0167740 - DOES NOT EXIST */ 1436968Ssam #define ADIO5 1 /* 0167730 - DOES NOT EXIST */ 144*8492Sroot 145*8492Sroot /* CLOCK START COMMAND */ 1466968Ssam #define CLOCK 1 /* mode */ 1476968Ssam #define CLOCKA 0<<4 /* clock A */ 148*8492Sroot /* clock status word */ 1496968Ssam #define ENACTR 1 /* enable counter */ 1506968Ssam #define R1M 1<<1 /* 1 MHz rate */ 1516968Ssam #define R100K 2<<1 /* 100 KHz rate */ 1526968Ssam #define R10K 3<<1 /* 10 KHz rate */ 1536968Ssam #define R1K 4<<1 /* 1 KHz rate */ 1546968Ssam #define R100 5<<1 /* 100 Hz rate */ 1556968Ssam #define REXT 6<<1 /* external rate (from st1 input) */ 1566968Ssam #define R60 7<<1 /* line frequency rate */ 1576968Ssam #define MFIE 0100 /* mode flag interrupt enable */ 1586968Ssam #define MSI 0<<8 /* single interval mode */ 1596968Ssam #define MRI 1<<8 /* repeat interval mode */ 1606968Ssam #define MEET 2<<8 /* external event time mode */ 1616968Ssam #define MEETZ 3<<8 /* external event time mode from zero base */ 1626968Ssam #define ST1EC 020000 /* st1 enable counter */ 1636968Ssam #define ST1IE 040000 /* st1 interrupt enable */ 164*8492Sroot 165*8492Sroot /* DATA TRANSFER START COMMAND */ 1666968Ssam #define DTS 2 /* mode */ 1676968Ssam #define SCHAN 1<<8 /* single channel */ 1686968Ssam 1696968Ssam lpaprobe(reg) 170*8492Sroot caddr_t reg; 1716968Ssam { 172*8492Sroot register int br, cvec; /* value result */ 173*8492Sroot register struct lpadevice *lpaaddr = (struct lpadevice *)reg; 1746968Ssam 1756968Ssam #ifdef lint 1766968Ssam br = 0; cvec = br; br = cvec; 1776968Ssam #endif 1786968Ssam /* this should force an interrupt, stall, clear the lpa */ 1796968Ssam br = 0x15; 1806968Ssam cvec = 0330; 1816968Ssam TRACER("PROBE\n"); 1827413Skre return (sizeof (struct lpadevice)); 1836968Ssam } 1846968Ssam 1856968Ssam lpaattach(ui) 186*8492Sroot register struct upa_device *ui; 1876968Ssam { 188*8492Sroot 1896968Ssam } 1906968Ssam 1916968Ssam lpaopen(dev, flag) 192*8492Sroot dev_t dev; 193*8492Sroot int flag; 1946968Ssam { 1956968Ssam register int unit = LPAUNIT(dev); 1966968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 1976968Ssam register struct uba_device *ui = lpadinfo[unit]; 1986968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 1996968Ssam 2006968Ssam TRACER("OPEN\n"); 2016968Ssam if (unit >= NLPA || sc->sc_flag & OPEN || ui == 0 || 2026968Ssam ui->ui_alive == 0) { 2036968Ssam u.u_error = ENXIO; 2046968Ssam return; 2056968Ssam } 2066968Ssam (void) spl7(); 2076968Ssam lpaaddr->lcim = RESET; 2086968Ssam lpaaddr->lcim = 0; 2096968Ssam (void) spl0(); 2106968Ssam lpaaddr->lcos = 0; /* clear the registers as a precaution */ 2116968Ssam lpaaddr->lrda = 0; 2126968Ssam lpaaddr->lms = 0; 2136968Ssam sc->sc_flag = OPEN; 2146968Ssam sc->sc_device = LPADEVICE(dev); 2156968Ssam sc->sc_channel = LPACHANNEL(dev); 2166968Ssam sc->sc_buffer = geteblk(); 2176968Ssam sc->sc_buffer->b_error = 0; 2186968Ssam sc->sc_buffer->b_proc = u.u_procp; 2196968Ssam sc->sc_ubufn = -1; 2206968Ssam /* THIS SHOULD EVENTUALLY SPECIFY "REAL-TIME" */ 2216968Ssam u.u_procp->p_nice = NICE; 2226968Ssam } 2236968Ssam 2246968Ssam lpaclose(dev, flag) 225*8492Sroot dev_t dev; 226*8492Sroot int flag; 2276968Ssam { 2286968Ssam register int unit = LPAUNIT(dev); 2296968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 2306968Ssam register struct uba_device *ui = lpadinfo[unit]; 2316968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 2326968Ssam 2336968Ssam if (sc->sc_device && sc->sc_ubufn >= 0 && (sc->sc_flag & ERROR) == 0) { 2346968Ssam if (sc->sc_start) 2356968Ssam lpacmd(sc->sc_buffer, lpaaddr, sc, ui->ui_ubanum); 2366968Ssam sc->sc_flag |= STOP; 2376968Ssam (void) spl5(); 2386968Ssam while (sc->sc_flag & STOP) { 2396968Ssam TRACER("SLEEP\n"); 2406968Ssam sc->sc_flag |= SLEEP; 2416968Ssam sleep((caddr_t)sc, LPAPRI); 2426968Ssam } 2436968Ssam } 2446968Ssam (void) spl7(); 2456968Ssam lpaaddr->lcim = RESET; 2466968Ssam lpaaddr->lcim = 0; 2476968Ssam (void) spl0(); 2486968Ssam if (sc->sc_ubabuf) { 2496968Ssam ubarelse(ui->ui_ubanum, &sc->sc_ubabuf); 2506968Ssam sc->sc_ubabuf = 0; 2516968Ssam (void) spl6(); 2526968Ssam vsunlock(sc->sc_ubuffer.b_un.b_addr, sc->sc_ubuffer.b_bcount, 2536968Ssam (sc->sc_device)? B_READ : B_WRITE); 2546968Ssam u.u_procp->p_flag &= ~SPHYSIO; 2556968Ssam (void) spl0(); 2566968Ssam } 2576968Ssam if (sc->sc_ubaustat) { 2586968Ssam ubarelse(ui->ui_ubanum, &sc->sc_ubaustat); 2596968Ssam sc->sc_ubaustat = 0; 2606968Ssam } 2616968Ssam if (sc->sc_buffer) { 2626968Ssam brelse(sc->sc_buffer); 2636968Ssam sc->sc_buffer = 0; 2646968Ssam } 2656968Ssam sc->sc_flag = 0; 2666968Ssam TRACER("CLOSE\n"); 2676968Ssam } 2686968Ssam 2697835Sroot lpawrite(dev, uio) 2707835Sroot dev_t dev; 2717835Sroot struct uio *uio; 2726968Ssam { 2736968Ssam register int unit = LPAUNIT(dev); 2746968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 2756968Ssam register struct uba_device *ui = lpadinfo[unit]; 2766968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 2776968Ssam register int f; 2786968Ssam 2796968Ssam TRACER("WRITE\n"); 2806968Ssam f = sc->sc_flag; 281*8492Sroot if ((f & OPEN) == 0) 282*8492Sroot return (ENXIO); 283*8492Sroot if ((f & MCODE) == 0) /* first write is the microcode */ 284*8492Sroot return (lpamcode(lpaaddr, sc, uio)); 285*8492Sroot if ((f & DMDT) == 0) /* second write is the dispatch table */ 286*8492Sroot return (lpadmdt(lpaaddr, sc, ui->ui_ubanum, uio)); 287*8492Sroot return (ENXIO); 2886968Ssam } 2896968Ssam 2907835Sroot lpamcode(lpaaddr, sc, uio) 2917835Sroot register struct lpadevice *lpaaddr; 2927835Sroot register struct lpa_softc *sc; 2937835Sroot struct uio *uio; 2946968Ssam { 2956968Ssam short v, r; 2966968Ssam register int mcaddr; 2976968Ssam 2986968Ssam mcaddr = 0; 2997835Sroot while (uio->uio_resid) { 3007835Sroot uiomove(&v, 2, UIO_WRITE, uio); /* get next microcode word */ 3016968Ssam lpaaddr->lcim = 0; /* load microcode word */ 3026968Ssam lpaaddr->lrda = mcaddr; 3036968Ssam lpaaddr->lms = v; 3046968Ssam lpaaddr->lcim = ROMO; 3056968Ssam lpaaddr->lcim |= CWRITE; 3066968Ssam lpaaddr->lcim = 0; /* verify microcode word */ 3076968Ssam lpaaddr->lrda = mcaddr; 3086968Ssam lpaaddr->lcim = ROMO; 3096968Ssam if ((r = lpaaddr->lms) != v) { 3106968Ssam /* download failure */ 3116968Ssam printf("LPA MICROCODE FAIL: exp:%o got:%o\n", v, r); 312*8492Sroot return (ENXIO); 3136968Ssam } 3146968Ssam mcaddr++; 3156968Ssam } 3166968Ssam lpaaddr->lcim = RUN | EA; /* turn it on */ 3176968Ssam sc->sc_flag |= MCODE; 3186968Ssam lpaaddr->lcim |= IIE; 3196968Ssam lpaaddr->lcos |= OIE; 320*8492Sroot return (0); 3216968Ssam TRACER("MCODE\n"); 3226968Ssam } 3236968Ssam 3247835Sroot lpadmdt(lpaaddr, sc, ubanum, uio) 3257835Sroot register struct lpadevice *lpaaddr; 3267835Sroot register struct lpa_softc *sc; 3277835Sroot register short ubanum; 3287835Sroot struct uio *uio; 3296968Ssam { 3306968Ssam register short *p; 3316968Ssam register int n; 332*8492Sroot int error; 3336968Ssam 3346968Ssam p = (short *) sc->sc_buffer->b_un.b_addr; /* INIT */ 3356968Ssam *p++ = (MCVERS << 8) | INIT; /* mode */ 3366968Ssam *p++ = ACLOCKA; /* LPA bus device addresses */ 3376968Ssam *p++ = ACLOCKB; 3386968Ssam *p++ = AAD1; 3396968Ssam *p++ = AAD2; 3406968Ssam *p++ = ADA; 3416968Ssam *p++ = ADIO1; 3426968Ssam *p++ = ADIO2; 3436968Ssam *p++ = ADIO3; 3446968Ssam *p++ = ADIO4; 3456968Ssam *p++ = ADIO5; 3467835Sroot n = min(uio->uio_resid, 256); /* dedicated mode dispatch table */ 347*8492Sroot error = uiomove((char *)p, n, UIO_WRITE, uio); 348*8492Sroot if (error) 349*8492Sroot return (error); 3506968Ssam n >>= 1; 3516968Ssam p += n; 3526968Ssam while (n++ < 128) 3536968Ssam *p++ = 0; 3546968Ssam lpacmd(sc->sc_buffer, lpaaddr, sc, ubanum); 3556968Ssam sc->sc_flag |= DMDT; 356*8492Sroot return (0); 3576968Ssam TRACER("DMDT\n"); 3586968Ssam } 3596968Ssam 3607632Ssam lpaioctl(dev, cmd, data, flag) 3617632Ssam dev_t dev; 3627632Ssam caddr_t data; 3636968Ssam { 3646968Ssam register int unit = LPAUNIT(dev); 3656968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 3666968Ssam register struct uba_device *ui = lpadinfo[unit]; 3676968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 3686968Ssam register short *p; 3696968Ssam register int i; 3706968Ssam register int v; 3716968Ssam struct iocb { 3726968Ssam short *baddr; 3736968Ssam short rate; 3746968Ssam short wc; 3757632Ssam } *iocb; 3766968Ssam 3776968Ssam TRACER("IOCTL IN\n"); 3786968Ssam if (cmd != TIOCSETP) { 3796968Ssam TRACER("NOT TIOCSETP\n"); 3806968Ssam /* not valid */ 3816968Ssam u.u_error = ENXIO; 3826968Ssam return; 3836968Ssam } 3846968Ssam #ifndef NOMCODE 3856968Ssam if ((sc->sc_flag & DMDT) == 0) { 3866968Ssam TRACER("NO DMDT\n"); 3876968Ssam u.u_error = ENXIO; 3886968Ssam return; 3896968Ssam } 3906968Ssam #endif 3917632Ssam iocb = (struct iocb *)data; 3926968Ssam p = (short *) sc->sc_buffer->b_un.b_addr; /* CLOCK START */ 3936968Ssam *p++ = CLOCK | CLOCKA; /* mode */ 3946968Ssam *p++ = ENACTR | R1M | MFIE | MRI; /* clock status */ 3957632Ssam *p = iocb->rate; /* clock preset */ 3966968Ssam lpacmd(sc->sc_buffer, lpaaddr, sc, ui->ui_ubanum); 3976968Ssam TRACER("CLOCK STARTED\n"); 3986968Ssam p = (short *) sc->sc_buffer->b_un.b_addr; /* DATA TRANSFER START*/ 3996968Ssam *p++ = (sc->sc_device << 7) | DTS | SCHAN; /* mode */ 4007632Ssam sc->sc_count = iocb->wc & 017777; /* word count per buffer */ 4016968Ssam *p++ = sc->sc_count; 4026968Ssam /* user status word */ 4036968Ssam sc->sc_ustatbuf.b_un.b_addr = (caddr_t) &sc->sc_ustat; 4046968Ssam sc->sc_ustatbuf.b_flags = 0; 4056968Ssam sc->sc_ustatbuf.b_bcount = 2; 4066968Ssam sc->sc_ustatbuf.b_proc = u.u_procp; 4076968Ssam sc->sc_ubaustat = ubasetup(ui->ui_ubanum, &sc->sc_ustatbuf, 0); 4086968Ssam v = sc->sc_ubaustat; 4096968Ssam *p++ = v; 4106968Ssam *p = (v >> 16) & 03; /* into low portion of word */ 4117632Ssam sc->sc_nbuf = (iocb->wc >> 13) & 07; /* number of buffers */ 4126968Ssam *p++ |= sc->sc_nbuf++ << 8; /* into high portion of word */ 4136968Ssam /* buffer addresses */ 4147632Ssam if (useracc(sc->sc_ubuffer.b_un.b_addr = (caddr_t) iocb->baddr, 4156968Ssam sc->sc_ubuffer.b_bcount = sc->sc_count * sc->sc_nbuf * 2, 4166968Ssam (i = (sc->sc_device)? B_READ : B_WRITE) ) == NULL) { 4176968Ssam TRACER("USER BUFFER FAULT\n"); 4186968Ssam u.u_error = EFAULT; 4196968Ssam return; 4206968Ssam } 4216968Ssam sc->sc_ubuffer.b_flags = B_PHYS | B_BUSY | i; 4226968Ssam sc->sc_ubuffer.b_proc = u.u_procp; 4236968Ssam u.u_procp->p_flag |= SPHYSIO; 4246968Ssam vslock(sc->sc_ubuffer.b_un.b_addr, sc->sc_ubuffer.b_bcount); 4256968Ssam /* sc->sc_ubabuf = ubasetup(ui->ui_ubanum, &sc->sc_ubuffer, UBA_NEEDBDP);*/ 4266968Ssam sc->sc_ubabuf = ubasetup(ui->ui_ubanum, &sc->sc_ubuffer, 0); 4276968Ssam v = sc->sc_ubabuf; 4286968Ssam for (i = 0; i < sc->sc_nbuf; i++) { 4296968Ssam *p++ = v; 4306968Ssam *p++ = (v >> 16) & 03; 4316968Ssam v += sc->sc_count * 2; 4326968Ssam } 4336968Ssam for ( ; i <= 7; i++) { 4346968Ssam *p++ = 0; 4356968Ssam *p++ = 0; 4366968Ssam } 4376968Ssam *p++ = 0; *p++ = 0; /* random channel list address */ 4386968Ssam *p++ = 0; /* delay */ 4396968Ssam *p++ = sc->sc_channel; /* start channel, channel inc */ 4406968Ssam *p++ = 1; /* number of samples in a sequence */ 4416968Ssam *p++ = 0; /* dwell */ 4426968Ssam *p++ = 0; /* start word no., event mark word */ 4436968Ssam *p++ = 0; /* start word mask */ 4446968Ssam *p = 0; /* event mark mask */ 4456968Ssam sc->sc_ustat = 0; 4466968Ssam sc->sc_start = (sc->sc_device)? sc->sc_nbuf+1 : 1; 4476968Ssam sc->sc_lbufn = 0; 4486968Ssam sc->sc_lbufnx = 0; 4496968Ssam sc->sc_flag |= STTY; 4506968Ssam TRACER("IOCTL OUT\n"); 4516968Ssam } 4526968Ssam 4537729Sroot lparead(dev, uio) 4547835Sroot dev_t dev; 4557835Sroot struct uio *uio; 4566968Ssam { 4576968Ssam register int unit = LPAUNIT(dev); 4586968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 4596968Ssam register struct uba_device *ui = lpadinfo[unit]; 4606968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 4616968Ssam 4626968Ssam TRACER("READ\n"); 463*8492Sroot if ((sc->sc_flag & STTY) == 0) 464*8492Sroot return (ENXIO); 465*8492Sroot if (sc->sc_flag & ERROR) 466*8492Sroot return (ENXIO); 4676968Ssam if (sc->sc_start) 4686968Ssam if (--sc->sc_start == 0) { 4696968Ssam lpacmd(sc->sc_buffer, lpaaddr, sc, ui->ui_ubanum); 4706968Ssam TRACER("START\n"); 4716968Ssam } 4726968Ssam inc(sc_ubufn); 4736968Ssam if (sc->sc_start == 0) { 4746968Ssam (void) spl5(); 4756968Ssam while (sc->sc_ubufn == sc->sc_lbufn) { 476*8492Sroot if (sc->sc_flag & ERROR) 477*8492Sroot return (ENXIO); 4786968Ssam TRACER("SLEEP\n"); 4796968Ssam sc->sc_flag |= SLEEP; 4806968Ssam sleep(sc, LPAPRI); 4816968Ssam } 4826968Ssam (void) spl0(); 4836968Ssam } 4846968Ssam TRACERN("READ %d\n", sc->sc_ubufn); 485*8492Sroot return (uiomove(&sc->sc_ubufn, 1, UIO_READ, uio)); 4866968Ssam } 4876968Ssam 4886968Ssam lpacmd(bp, lpaaddr, sc, ubanum) 4897835Sroot register struct buf *bp; 4907835Sroot register struct lpadevice *lpaaddr; 4917835Sroot register struct lpa_softc *sc; 4927835Sroot register short ubanum; 4936968Ssam { 4946968Ssam int ubareg; 4956968Ssam 4966968Ssam TRACER("CMD\n"); 4976968Ssam ubareg = ubasetup(ubanum, bp, UBA_NEEDBDP); 4986968Ssam lpawait(lpaaddr, sc); 4996968Ssam lpaaddr->lrda = ubareg; 5006968Ssam lpaaddr->lcim &= ~RDAEXT; 5016968Ssam lpaaddr->lcim |= ((ubareg >> (16-RDAEXTOFFSET)) & RDAEXT) | GO; 5026968Ssam lpawait(lpaaddr, sc); 5036968Ssam ubarelse(ubanum, &ubareg); 5046968Ssam } 5056968Ssam 5066968Ssam lpawait(lpaaddr, sc) 507*8492Sroot register struct lpadevice *lpaaddr; 508*8492Sroot register struct lpa_softc *sc; 5096968Ssam { 510*8492Sroot 5116968Ssam (void) spl5(); 5126968Ssam while ((lpaaddr->lcim & READYI) == 0) { 5136968Ssam TRACER("SLEEP\n"); 5146968Ssam sc->sc_flag |= SLEEP; 5156968Ssam sleep((caddr_t)sc, LPAPRI); 5166968Ssam } 5176968Ssam (void) spl0(); 5186968Ssam } 5196968Ssam 5206968Ssam lpaiintr(unit) 521*8492Sroot int unit; 5226968Ssam { 5236968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 5246968Ssam 5256968Ssam TRACER("{I"); 5266968Ssam if (sc->sc_flag & SLEEP) { 5276968Ssam TRACER("<WAKEUP>"); 5286968Ssam wakeup((caddr_t)sc); 5296968Ssam sc->sc_flag &= ~SLEEP; 5306968Ssam } 5316968Ssam TRACER("}"); 5326968Ssam } 5336968Ssam 5346968Ssam lpaointr(unit) 535*8492Sroot int unit; 5366968Ssam { 5376968Ssam register int c, m; 5386968Ssam register struct lpa_softc *sc = &lpa_softc[unit]; 5396968Ssam register struct uba_device *ui = lpadinfo[unit]; 5406968Ssam register struct lpadevice *lpaaddr = (struct lpadevice *) ui->ui_addr; 5416968Ssam int spx; 5426968Ssam 5436968Ssam TRACER("{O"); 5446968Ssam if (sc->sc_flag & SLEEP) { 5456968Ssam TRACER("<WAKEUP>"); 5466968Ssam wakeup(sc); 5476968Ssam sc->sc_flag &= ~SLEEP; 5486968Ssam } 5496968Ssam c = lpaaddr->lcos; 5506968Ssam m = lpaaddr->lms; 5516968Ssam lpaaddr->lcos &= ~READYO; 5526968Ssam if (c & ERROR) { 5536968Ssam TRACER("<ERROR>"); 5546968Ssam c = (c >> 8) & 0377; 5556968Ssam if ((sc->sc_flag & STOP) == 0 || (c != OVERRUN)) { 5566968Ssam printf("LPA ERROR %o %o\n", c, m&0177777); 5576968Ssam sc->sc_flag |= ERROR; 5586968Ssam } 5596968Ssam sc->sc_flag &= ~STOP; 5606968Ssam TRACER("}\n"); 5616968Ssam return; 5626968Ssam } 5636968Ssam TRACERN("<LPA %d>", sc->sc_lbufnx); 5646968Ssam sc->sc_lbufn = sc->sc_lbufnx; 5656968Ssam if (sc->sc_ubufn == sc->sc_lbufnx && c & ECODE) { 5666968Ssam TRACER("<STOP?>"); 5676968Ssam if (sc->sc_flag & STOP) 5686968Ssam return; 5696968Ssam printf("LPA OVERRUN\n"); 5706968Ssam sc->sc_flag |= ERROR; 5716968Ssam } 5726968Ssam inc(sc_lbufnx); 5736968Ssam TRACERN("<USTAT %o>", sc->sc_ustat); 5746968Ssam spx = spl7(); 5756968Ssam sc->sc_ustat &= ~NBI; 5766968Ssam sc->sc_ustat |= sc->sc_lbufnx << 8; 5776968Ssam sc->sc_ustat &= ~DONE; 5786968Ssam (void) splx(spx); 5796968Ssam TRACERN("<LPAN %d>}", sc->sc_lbufnx); 5806968Ssam } 5816968Ssam 5826968Ssam lpareset(uban) 583*8492Sroot int uban; 5846968Ssam { 5856968Ssam register struct uba_device *ui; 5866968Ssam register struct lpadevice *lpaaddr; 5876968Ssam register struct lpa_softc *sc; 5886968Ssam register int unit; 5896968Ssam 5906968Ssam TRACER("LPA RESET\n"); 5916968Ssam for (unit = 0; unit < NLPA; unit++) { 592*8492Sroot if ((ui = lpadinfo[unit]) == 0 || 593*8492Sroot ui->ui_ubanum != uban || ui->ui_alive == 0) 594*8492Sroot continue; 5956968Ssam printf(" lpa%d", unit); 5966968Ssam lpaaddr = (struct lpadevice *)ui->ui_addr; 5976968Ssam sc = &lpa_softc[unit]; 5986968Ssam sc->sc_flag |= ERROR; 5996968Ssam (void) spl7(); 6006968Ssam lpaaddr->lcim = RESET; 6016968Ssam lpaaddr->lcim = 0; 6026968Ssam (void) spl0(); 6036968Ssam if (sc->sc_flag & SLEEP) { 6046968Ssam wakeup((caddr_t)sc); 6056968Ssam sc->sc_flag &= ~SLEEP; 6066968Ssam } 6076968Ssam } 6086968Ssam } 6096968Ssam #endif NLPA 610