134406Skarels /* 235514Sbostic * Copyright (c) 1988 The Regents of the University of California. 335514Sbostic * All rights reserved. 435514Sbostic * 535514Sbostic * This code is derived from software contributed to Berkeley by 635514Sbostic * Computer Consoles Inc. 735514Sbostic * 835514Sbostic * Redistribution and use in source and binary forms are permitted 935514Sbostic * provided that the above copyright notice and this paragraph are 1035514Sbostic * duplicated in all such forms and that any documentation, 1135514Sbostic * advertising materials, and other materials related to such 1235514Sbostic * distribution and use acknowledge that the software was developed 1335514Sbostic * by the University of California, Berkeley. The name of the 1435514Sbostic * University may not be used to endorse or promote products derived 1535514Sbostic * from this software without specific prior written permission. 1635514Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1735514Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1835514Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1935514Sbostic * 20*40735Skarels * @(#)dr.c 7.6 (Berkeley) 04/03/90 2134406Skarels */ 2229651Ssam 2329651Ssam #include "dr.h" 2429651Ssam #if NDR > 0 2530294Ssam /* 2630294Ssam * DRV11-W DMA interface driver. 2730294Ssam * 2830227Ssam * UNTESTED WITH 4.3 2929651Ssam */ 3037507Smckusick #include "machine/mtpr.h" 3137507Smckusick #include "machine/pte.h" 3229651Ssam 3329651Ssam #include "param.h" 3429651Ssam #include "conf.h" 3529651Ssam #include "user.h" 3629651Ssam #include "proc.h" 3729651Ssam #include "map.h" 3829651Ssam #include "ioctl.h" 3929651Ssam #include "buf.h" 4029651Ssam #include "vm.h" 4130294Ssam #include "kernel.h" 4229651Ssam 4329651Ssam #include "../tahoevba/vbavar.h" 4429651Ssam #include "../tahoevba/drreg.h" 4529651Ssam 4629651Ssam #define YES 1 4729651Ssam #define NO 0 4829651Ssam 4929651Ssam struct vba_device *drinfo[NDR]; 5029651Ssam struct dr_aux dr_aux[NDR]; 5129651Ssam 5229651Ssam unsigned drminphys(); 5330294Ssam int drprobe(), drintr(), drattach(), drtimo(), drrwtimo(); 5430294Ssam int drstrategy(); 5530294Ssam extern struct vba_device *drinfo[]; 5630294Ssam static long drstd[] = { 0 }; 5729651Ssam struct vba_driver drdriver = 5830294Ssam { drprobe, 0, drattach, 0, drstd, "rs", drinfo }; 5929651Ssam 6029651Ssam #define RSUNIT(dev) (minor(dev) & 7) 6129651Ssam #define SPL_UP spl5 6229651Ssam 6329651Ssam /* -------- Per-unit data -------- */ 6429651Ssam 6529651Ssam extern struct dr_aux dr_aux[]; 6629651Ssam 6729651Ssam #ifdef DR_DEBUG 6830294Ssam long DR11 = 0; 6929651Ssam #endif 7029651Ssam 7129651Ssam drprobe(reg, vi) 7230294Ssam caddr_t reg; 7330294Ssam struct vba_device *vi; 7429651Ssam { 7530294Ssam register int br, cvec; /* must be r12, r11 */ 7630294Ssam struct rsdevice *dr; 7729651Ssam 7830294Ssam #ifdef lint 7930294Ssam br = 0; cvec = br; br = cvec; 8030294Ssam drintr(0); 8129651Ssam #endif 8230294Ssam if (badaddr(reg, 2)) 8330294Ssam return (0); 8430294Ssam dr = (struct rsdevice *)reg; 8530294Ssam dr->dr_intvect = --vi->ui_hd->vh_lastiv; 8629651Ssam #ifdef DR_DEBUG 8730294Ssam printf("dprobe: Set interrupt vector %lx and init\n",dr->dr_intvec); 8829651Ssam #endif 8930294Ssam /* generate interrupt here for autoconfig */ 9030294Ssam dr->dr_cstat = MCLR; /* init board and device */ 9129651Ssam #ifdef DR_DEBUG 9230294Ssam printf("drprobe: Initial status %lx\n", dr->dr_cstat); 9329651Ssam #endif 9430294Ssam br = 0x18, cvec = dr->dr_intvect; /* XXX */ 9530294Ssam return (sizeof (struct rsdevice)); /* DR11 exist */ 9629651Ssam } 9729651Ssam 9829651Ssam /* ARGSUSED */ 9929651Ssam drattach(ui) 10030294Ssam struct vba_device *ui; 10129651Ssam { 10230294Ssam register struct dr_aux *rsd; 10329651Ssam 10430294Ssam rsd = &dr_aux[ui->ui_unit]; 10530294Ssam rsd->dr_flags = DR_PRES; /* This dr11 is present */ 10630294Ssam rsd->dr_addr = (struct rsdevice *)ui->ui_addr; /* Save addr of this dr11 */ 10730294Ssam rsd->dr_istat = 0; 10830294Ssam rsd->dr_bycnt = 0; 10930294Ssam rsd->dr_cmd = 0; 11030294Ssam rsd->currenttimo = 0; 11129651Ssam } 11229651Ssam 11330294Ssam /*ARGSUSED*/ 11430294Ssam dropen(dev, flag) 11530294Ssam dev_t dev; 11630294Ssam int flag; 11729651Ssam { 11830294Ssam register int unit = RSUNIT(dev); 11930294Ssam register struct rsdevice *dr; 12030294Ssam register struct dr_aux *rsd; 12129651Ssam 12230294Ssam if (drinfo[unit] == 0 || !drinfo[unit]->ui_alive) 12330294Ssam return (ENXIO); 12430294Ssam dr = RSADDR(unit); 12530294Ssam rsd = &dr_aux[unit]; 12630294Ssam if (rsd->dr_flags & DR_OPEN) { 12729651Ssam #ifdef DR_DEBUG 12830294Ssam printf("\ndropen: dr11 unit %ld already open",unit); 12929651Ssam #endif 13030294Ssam return (ENXIO); /* DR11 already open */ 13130294Ssam } 13230294Ssam rsd->dr_flags |= DR_OPEN; /* Mark it OPEN */ 13330294Ssam rsd->dr_istat = 0; /* Clear status of previous interrupt */ 13430294Ssam rsd->rtimoticks = hz; /* Set read no stall timout to 1 sec */ 13530294Ssam rsd->wtimoticks = hz*60; /* Set write no stall timout to 1 min */ 13630294Ssam dr->dr_cstat = DR_ZERO; /* Clear function & latches */ 13730294Ssam dr->dr_pulse = (RDMA | RATN); /* clear leftover attn & e-o-r flags */ 13830294Ssam drtimo(dev); /* start the self kicker */ 13930294Ssam return (0); 14029651Ssam } 14129651Ssam 14229651Ssam drclose (dev) 14330294Ssam dev_t dev; 14429651Ssam { 14530294Ssam register int unit = RSUNIT(dev); 14630294Ssam register struct dr_aux *dra; 14730294Ssam register struct rsdevice *rs; 14830294Ssam register short s; 14929651Ssam 15030294Ssam dra = &dr_aux[unit]; 15130294Ssam if ((dra->dr_flags & DR_OPEN) == 0) { 15229651Ssam #ifdef DR_DEBUG 15330294Ssam printf("\ndrclose: DR11 device %ld not open",unit); 15429651Ssam #endif 15530294Ssam return; 15630294Ssam } 15730294Ssam dra->dr_flags &= ~(DR_OPEN|DR_ACTV); 15830294Ssam rs = dra->dr_addr; 15930294Ssam s = SPL_UP(); 16030294Ssam rs->dr_cstat = DR_ZERO; 16130294Ssam if (dra->dr_buf.b_flags & B_BUSY) { 16230294Ssam dra->dr_buf.b_flags &= ~B_BUSY; 16330294Ssam wakeup((caddr_t)&dra->dr_buf.b_flags); 16430294Ssam } 16530294Ssam splx(s); 166*40735Skarels return (0); 16729651Ssam } 16829651Ssam 16929651Ssam 17029651Ssam /* drread() works exactly like drwrite() except that the 17129651Ssam B_READ flag is used when physio() is called 17229651Ssam */ 17329651Ssam drread (dev, uio) 17430294Ssam dev_t dev; 17530294Ssam struct uio *uio; 17629651Ssam { register struct dr_aux *dra; 17729651Ssam register struct buf *bp; 17830294Ssam register int spl, err; 17930294Ssam register int unit = RSUNIT(dev); 18029651Ssam 18130294Ssam if (uio->uio_iov->iov_len <= 0 || /* Negative count */ 18230294Ssam uio->uio_iov->iov_len & 1 || /* odd count */ 18330294Ssam (int)uio->uio_iov->iov_base & 1) /* odd destination address */ 18430294Ssam return (EINVAL); 18529651Ssam #ifdef DR_DEBUG 18630294Ssam if (DR11 & 8) 18730294Ssam printf("\ndrread: (len:%ld)(base:%lx)", 18830294Ssam uio->uio_iov->iov_len,(int)uio->uio_iov->iov_base); 18929651Ssam #endif 19030294Ssam dra = &dr_aux[RSUNIT(dev)]; 19130294Ssam dra->dr_op = DR_READ; 19230294Ssam bp = &dra->dr_buf; 19330294Ssam bp->b_resid = 0; 19430294Ssam if (dra->dr_flags & DR_NORSTALL) { 19530294Ssam /* 19630294Ssam * We are in no stall mode, start the timer, 19730294Ssam * raise IPL so nothing can stop us once the 19830294Ssam * timer's running 19930294Ssam */ 20030294Ssam spl = SPL_UP(); 20130294Ssam timeout(drrwtimo, (caddr_t)((dra->currenttimo<<8) | unit), 20230294Ssam (int)dra->rtimoticks); 20330294Ssam err = physio(drstrategy, bp, dev,B_READ, drminphys, uio); 20430294Ssam splx(spl); 20530294Ssam if (err) 20630294Ssam return (err); 20730294Ssam dra->currenttimo++; /* Update current timeout number */ 20830294Ssam /* Did we timeout */ 20930294Ssam if (dra->dr_flags & DR_TMDM) { 21030294Ssam dra->dr_flags &= ~DR_TMDM; /* Clear timeout flag */ 21130294Ssam u.u_error = 0; /* Made the error ourself, ignore it */ 21230294Ssam } 21330294Ssam return (err); 21429651Ssam } 21530294Ssam return (physio(drstrategy, bp, dev,B_READ, drminphys, uio)); 21629651Ssam } 21729651Ssam 21830294Ssam drwrite(dev, uio) 21930294Ssam dev_t dev; 22030294Ssam struct uio *uio; 22129651Ssam { register struct dr_aux *dra; 22229651Ssam register struct buf *bp; 22330294Ssam register int unit = RSUNIT(dev); 22430294Ssam int spl, err; 22529651Ssam 22630294Ssam if (uio->uio_iov->iov_len <= 0 || uio->uio_iov->iov_len & 1 || 22730294Ssam (int)uio->uio_iov->iov_base & 1) 22830294Ssam return (EINVAL); 22929651Ssam #ifdef DR_DEBUG 23030294Ssam if (DR11 & 4) 23130294Ssam printf("\ndrwrite: (len:%ld)(base:%lx)", 23230294Ssam uio->uio_iov->iov_len,(int)uio->uio_iov->iov_base); 23329651Ssam #endif 23430294Ssam dra = &dr_aux[RSUNIT(dev)]; 23530294Ssam dra->dr_op = DR_WRITE; 23630294Ssam bp = &dra->dr_buf; 23730294Ssam bp->b_resid = 0; 23830294Ssam if (dra->dr_flags & DR_NOWSTALL) { 23930294Ssam /* 24030294Ssam * We are in no stall mode, start the timer, 24130294Ssam * raise IPL so nothing can stop us once the 24230294Ssam * timer's running 24330294Ssam */ 24430294Ssam spl = SPL_UP(); 24530294Ssam timeout(drrwtimo,(caddr_t)((dra->currenttimo<<8) | unit), 24630294Ssam (int)dra->wtimoticks); 24730294Ssam err = physio (drstrategy, bp, dev,B_WRITE, drminphys, uio); 24830294Ssam splx(spl); 24930294Ssam if (err) 25030294Ssam return (err); 25130294Ssam dra->currenttimo++; /* Update current timeout number */ 25230294Ssam /* Did we timeout */ 25330294Ssam if (dra->dr_flags & DR_TMDM) { 25430294Ssam dra->dr_flags &= ~DR_TMDM; /* Clear timeout flag */ 25530294Ssam u.u_error = 0; /* Made the error ourself, ignore it */ 25630294Ssam } 25730294Ssam return (err); 25829651Ssam } 25930294Ssam return (physio(drstrategy, bp, dev,B_WRITE, drminphys, uio)); 26029651Ssam } 26129651Ssam 26230294Ssam /* 26330294Ssam * Routine used by calling program to issue commands to dr11 driver and 26430294Ssam * through it to the device. 26530294Ssam * It is also used to read status from the device and driver and to wait 26630294Ssam * for attention interrupts. 26730294Ssam * Status is returned in an 8 elements unsigned short integer array, the 26830294Ssam * first two elements of the array are also used to pass arguments to 26930294Ssam * drioctl() if required. 27030294Ssam * The function bits to be written to the dr11 are included in the cmd 27130294Ssam * argument. Even if they are not being written to the dr11 in a particular 27230294Ssam * drioctl() call, they will update the copy of cmd that is stored in the 27330294Ssam * driver. When drstrategy() is called, this updated copy is used if a 27430294Ssam * deferred function bit write has been specified. The "side effect" of 27530294Ssam * calls to the drioctl() requires that the last call prior to a read or 27630294Ssam * write has an appropriate copy of the function bits in cmd if they are 27730294Ssam * to be used in drstrategy(). 27830294Ssam * When used as command value, the contents of data[0] is the command 27930294Ssam * parameter. 28030294Ssam */ 28130294Ssam drioctl(dev, cmd, data) 28230294Ssam dev_t dev; 28330294Ssam int cmd; 28430294Ssam long *data; 28529651Ssam { 28630294Ssam register int unit = RSUNIT(dev); 28730294Ssam register struct dr_aux *dra; 28830294Ssam register struct rsdevice *rsaddr = RSADDR(unit); 28937545Smckusick int s, error = 0; 29030294Ssam u_short status; 29130294Ssam long temp; 29229651Ssam 29329651Ssam #ifdef DR_DEBUG 29430294Ssam if (DR11 & 0x10) 29530294Ssam printf("\ndrioctl: (dev:%lx)(cmd:%lx)(data:%lx)(data[0]:%lx)", 29630294Ssam dev,cmd,data,data[0]); 29729651Ssam #endif 29830294Ssam dra = &dr_aux[unit]; 29930294Ssam dra->dr_cmd = 0; /* Fresh copy; clear all previous flags */ 30030294Ssam switch (cmd) { 30129651Ssam 30230294Ssam case DRWAIT: /* Wait for attention interrupt */ 30329651Ssam #ifdef DR_DEBUG 30430294Ssam printf("\ndrioctl: wait for attention interrupt"); 30529651Ssam #endif 30630294Ssam s = SPL_UP(); 30730294Ssam /* 30830294Ssam * If the attention flag in dr_flags is set, it probably 30930294Ssam * means that an attention has arrived by the time a 31030294Ssam * previous DMA end-of-range interrupt was serviced. If 31130294Ssam * ATRX is set, we will return with out sleeping, since 31230294Ssam * we have received an attention since the last call to 31330294Ssam * wait on attention. This may not be appropriate for 31430294Ssam * some applications. 31530294Ssam */ 31630294Ssam if ((dra->dr_flags & DR_ATRX) == 0) { 31730294Ssam dra->dr_flags |= DR_ATWT; /* Set waiting flag */ 31830294Ssam /* 31930294Ssam * Enable interrupt; use pulse reg. 32030294Ssam * so function bits are not changed 32130294Ssam */ 32230294Ssam rsaddr->dr_pulse = IENB; 323*40735Skarels error = tsleep((caddr_t)&dra->dr_cmd, DRPRI | PCATCH, 324*40735Skarels devio, 0); 32530294Ssam } 32630294Ssam splx(s); 32730294Ssam break; 32829651Ssam 32930294Ssam case DRPIOW: /* Write to p-i/o register */ 33030294Ssam rsaddr->dr_data = data[0]; 33130294Ssam break; 33229651Ssam 33330294Ssam case DRPACL: /* Send pulse to device */ 33430294Ssam rsaddr->dr_pulse = FCN2; 33530294Ssam break; 33629651Ssam 33730294Ssam case DRDACL: /* Defer alco pulse until go */ 33830294Ssam dra->dr_cmd |= DR_DACL; 33930294Ssam break; 34029651Ssam 34130294Ssam case DRPCYL: /* Set cycle with next go */ 34230294Ssam dra->dr_cmd |= DR_PCYL; 34330294Ssam break; 34429651Ssam 34530294Ssam case DRDFCN: /* Update function with next go */ 34630294Ssam dra->dr_cmd |= DR_DFCN; 34730294Ssam break; 34829651Ssam 34930294Ssam case DRRATN: /* Reset attention flag */ 35030294Ssam rsaddr->dr_pulse = RATN; 35130294Ssam break; 35229651Ssam 35330294Ssam case DRRDMA: /* Reset DMA e-o-r flag */ 35430294Ssam rsaddr->dr_pulse = RDMA; 35530294Ssam break; 35629651Ssam 35730294Ssam case DRSFCN: /* Set function bits */ 35830294Ssam temp = data[0] & DR_FMSK; 35930294Ssam /* 36030294Ssam * This has a very important side effect -- It clears 36130294Ssam * the interrupt enable flag. That is fine for this driver, 36230294Ssam * but if it is desired to leave interrupt enable at all 36330294Ssam * times, it will be necessary to read the status register 36430294Ssam * first to get IENB, or carry a software flag that indicates 36530294Ssam * whether interrupts are set, and or this into the control 36630294Ssam * register value being written. 36730294Ssam */ 36830294Ssam rsaddr->dr_cstat = temp; 36930294Ssam break; 37029651Ssam 37130294Ssam case DRRPER: /* Clear parity flag */ 37230294Ssam rsaddr->dr_pulse = RPER; 37330294Ssam break; 37429651Ssam 37530294Ssam case DRSETRSTALL: /* Set read stall mode. */ 37630294Ssam dra->dr_flags &= (~DR_NORSTALL); 37730294Ssam break; 37829651Ssam 37930294Ssam case DRSETNORSTALL: /* Set no stall read mode. */ 38030294Ssam dra->dr_flags |= DR_NORSTALL; 38130294Ssam break; 38229651Ssam 38330294Ssam case DRGETRSTALL: /* Returns true if in read stall mode */ 38430294Ssam data[0] = (dra->dr_flags & DR_NORSTALL)? 0 : 1; 38530294Ssam break; 38629651Ssam 38730294Ssam case DRSETRTIMEOUT: /* Set read stall timeout (1/10 secs) */ 38830294Ssam if (data[0] < 1) { 38930294Ssam u.u_error = EINVAL; 39030294Ssam temp = 1; 39130294Ssam } 39230294Ssam dra->rtimoticks = (data[0] * hz )/10; 39330294Ssam break; 39429651Ssam 39530294Ssam case DRGETRTIMEOUT: /* Return read stall timeout */ 39630294Ssam data[0] = ((dra->rtimoticks)*10)/hz; 39730294Ssam break; 39829651Ssam 39930294Ssam case DRSETWSTALL: /* Set write stall mode. */ 40030294Ssam dra->dr_flags &= (~DR_NOWSTALL); 40130294Ssam break; 40229651Ssam 40330294Ssam case DRSETNOWSTALL: /* Set write stall mode. */ 40430294Ssam dra->dr_flags |= DR_NOWSTALL; 40530294Ssam break; 40629651Ssam 40730294Ssam case DRGETWSTALL: /* Return true if in write stall mode */ 40830294Ssam data[0] = (dra->dr_flags & DR_NOWSTALL)? 0 : 1; 40930294Ssam break; 41029651Ssam 41130294Ssam case DRSETWTIMEOUT: /* Set write stall timeout (1/10's) */ 41230294Ssam if (data[0] < 1) { 41330294Ssam u.u_error = EINVAL; 41430294Ssam temp = 1; 41530294Ssam } 41630294Ssam dra->wtimoticks = (data[0] * hz )/10; 41730294Ssam break; 41829651Ssam 41930294Ssam case DRGETWTIMEOUT: /* Return write stall timeout */ 42030294Ssam data[0] = ((dra->wtimoticks)*10)/hz; 42130294Ssam break; 42229651Ssam 42330294Ssam case DRWRITEREADY: /* Return true if can write data */ 42430294Ssam data[0] = (rsaddr->dr_cstat & STTA)? 1 : 0; 42530294Ssam break; 42629651Ssam 42730294Ssam case DRREADREADY: /* Return true if data to be read */ 42830294Ssam data[0] = (rsaddr->dr_cstat & STTB)? 1 : 0; 42930294Ssam break; 43029651Ssam 43130294Ssam case DRBUSY: /* Return true if device busy */ 43230294Ssam /* 43330294Ssam * Internally this is the DR11-W 43430294Ssam * STAT C bit, but there is a bug in the Omega 500/FIFO 43530294Ssam * interface board that it cannot drive this signal low 43630294Ssam * for certain DR11-W ctlr such as the Ikon. We use the 43730294Ssam * REDY signal of the CSR on the Ikon DR11-W instead. 43830294Ssam */ 43930294Ssam #ifdef notdef 44030294Ssam data[0] = (rsaddr->dr_cstat & STTC)? 1 : 0; 44130294Ssam #else 44230294Ssam data[0] = ((rsaddr->dr_cstat & REDY)? 0 : 1); 44330294Ssam #endif 44430294Ssam break; 44529651Ssam 44630294Ssam case DRRESET: /* Reset device */ 44730294Ssam /* Reset DMA ATN RPER flag */ 44830294Ssam rsaddr->dr_pulse = (MCLR|RDMA|RATN|RPER); 44930294Ssam DELAY(0x1f000); 450*40735Skarels while ((rsaddr->dr_cstat & REDY) == 0 && error == 0) 451*40735Skarels /* Wakeup by drtimo() */ 452*40735Skarels error = tsleep((caddr_t)dra, DRPRI | PCATCH, devio, 0); 45330294Ssam dra->dr_istat = 0; 45430294Ssam dra->dr_cmd = 0; 45530294Ssam dra->currenttimo = 0; 45630294Ssam break; 45729651Ssam 45830294Ssam case DR11STAT: { /* Copy back dr11 status to user */ 45930294Ssam register struct dr11io *dr = (struct dr11io *)data; 46030294Ssam dr->arg[0] = dra->dr_flags; 46130294Ssam dr->arg[1] = rsaddr->dr_cstat; 46230294Ssam dr->arg[2] = dra->dr_istat; /* Status at last interrupt */ 46330294Ssam dr->arg[3] = rsaddr->dr_data; /* P-i/o input data */ 46430294Ssam status = (u_short)((rsaddr->dr_addmod << 8) & 0xff00); 46530294Ssam dr->arg[4] = status | (u_short)(rsaddr->dr_intvect & 0xff); 46630294Ssam dr->arg[5] = rsaddr->dr_range; 46730294Ssam dr->arg[6] = rsaddr->dr_rahi; 46830294Ssam dr->arg[7] = rsaddr->dr_ralo; 46930294Ssam break; 47030294Ssam } 47130294Ssam case DR11LOOP: /* Perform loopback test */ 47230294Ssam /* 47330294Ssam * NB: MUST HAVE LOOPBACK CABLE ATTACHED -- 47430294Ssam * Test results are printed on system console 47530294Ssam */ 47637545Smckusick if (error = suser(u.u_cred, &u.u_acflag)) 47737545Smckusick break; 47837545Smckusick dr11loop(rsaddr, dra, unit); 47930294Ssam break; 48029651Ssam 48130294Ssam default: 48230294Ssam return (EINVAL); 48329651Ssam } 48429651Ssam #ifdef DR_DEBUG 48530294Ssam if (DR11 & 0x10) 48630294Ssam printf("**** (data[0]:%lx)",data[0]); 48729651Ssam #endif 48837545Smckusick return (error); 48929651Ssam } 49029651Ssam 49130294Ssam #define NPAT 2 49230294Ssam #define DMATBL 20 49330294Ssam u_short tstpat[DMATBL] = { 0xAAAA, 0x5555}; 49430294Ssam long DMAin = 0; 49530138Ssam 49630294Ssam /* 49730294Ssam * Perform loopback test -- MUST HAVE LOOPBACK CABLE ATTACHED 49830294Ssam * Test results are printed on system console 49930294Ssam */ 50030294Ssam dr11loop(dr, dra, unit) 50130294Ssam struct rsdevice *dr; 50230294Ssam struct dr_aux *dra; 50330294Ssam int unit; 50430294Ssam { 50530294Ssam register long result, ix; 50630294Ssam long addr, wait; 50730138Ssam 50830138Ssam dr->dr_cstat = MCLR; /* Clear board & device, disable intr */ 50930294Ssam printf("\n\t ----- DR11 unit %ld loopback test -----", unit); 51030138Ssam printf("\n\t Program I/O ..."); 51130138Ssam for (ix=0;ix<NPAT;ix++) { 51230138Ssam dr->dr_data = tstpat[ix]; /* Write to Data out register */ 51330294Ssam result = dr->dr_data & 0xFFFF; /* Read it back */ 51430138Ssam if (result != tstpat[ix]) { 51530138Ssam printf("Failed, expected : %lx --- actual : %lx", 51630294Ssam tstpat[ix], result); 51730138Ssam return; 51830138Ssam } 51930138Ssam } 52030138Ssam printf("OK\n\t Functions & Status Bits ..."); 52130138Ssam dr->dr_cstat = (FCN1 | FCN3); 52230138Ssam result = dr->dr_cstat & 0xffff; /* Read them back */ 52330138Ssam if ((result & (STTC | STTA)) != (STTC |STTA)) { 52430138Ssam printf("Failed, expected : %lx --- actual : %lx, ISR:%lx", 52530294Ssam (STTA|STTC), (result & (STTA|STTC)), result); 52630138Ssam return; 52730138Ssam } 52830138Ssam dr->dr_cstat = FCN2; 52930138Ssam result = dr->dr_cstat & 0xffff; /* Read them back */ 53030138Ssam if ((result & STTB) != STTB) { 53130138Ssam printf("Failed, expected : %lx --- actual : %lx, ISR:%lx", 53230294Ssam STTB, (result & STTB), result); 53330138Ssam return; 53430138Ssam } 53530138Ssam printf("OK\n\t DMA output ..."); 53630294Ssam if (DMAin) 53730294Ssam goto dmain; 53830138Ssam /* Initialize DMA data buffer */ 53930294Ssam for (ix=0; ix<DMATBL; ix++) 54030294Ssam tstpat[ix] = 0xCCCC + ix; 54130138Ssam tstpat[DMATBL-1] = 0xCCCC; /* Last word output */ 54230138Ssam /* Setup normal DMA */ 54330294Ssam addr = (long)vtoph((struct proc *)0, (unsigned)tstpat); 54430294Ssam dr->dr_walo = (addr >> 1) & 0xffff; 54530294Ssam dr->dr_wahi = (addr >> 17) & 0x7fff; 54630294Ssam /* Set DMA range count: (number of words - 1) */ 54730294Ssam dr->dr_range = DMATBL - 1; 54830294Ssam /* Set address modifier code to be used for DMA access to memory */ 54930294Ssam dr->dr_addmod = DRADDMOD; 55030138Ssam 55130294Ssam /* 55230294Ssam * Clear dmaf and attf to assure a clean dma start, also disable 55330294Ssam * attention interrupt 55430294Ssam */ 55530294Ssam dr->dr_pulse = RDMA|RATN|RMSK; /* Use pulse register */ 55630294Ssam dr->dr_cstat = GO|CYCL; /* GO...... */ 55730138Ssam 55830138Ssam /* Wait for DMA complete; REDY and DMAF are true in ISR */ 55930138Ssam wait = 0; 56030294Ssam while ((result=(dr->dr_cstat & (REDY|DMAF))) != (REDY|DMAF)) { 56130294Ssam printf("\n\tWait for DMA complete...ISR : %lx", result); 56230138Ssam if (++wait > 5) { 56330138Ssam printf("\n\t DMA output fails...timeout!!, ISR:%lx", 56430138Ssam result); 56530138Ssam return; 56630138Ssam } 56730138Ssam } 56830138Ssam result = dr->dr_data & 0xffff; /* Read last word output */ 56930138Ssam if (result != 0xCCCC) { 57030138Ssam printf("\n\t Fails, expected : %lx --- actual : %lx", 57130294Ssam 0xCCCC, result); 57230138Ssam return; 57330138Ssam } 57430138Ssam printf("OK\n\t DMA input ..."); 57530138Ssam dmain: 57630138Ssam dr->dr_data = 0x1111; /* DMA input data */ 57730138Ssam /* Setup normal DMA */ 57830294Ssam addr = (long)vtoph((struct proc *)0, (unsigned)tstpat); 57930294Ssam dr->dr_walo = (addr >> 1) & 0xffff; 58030294Ssam dr->dr_wahi = (addr >> 17) & 0x7fff; 58130294Ssam dr->dr_range = DMATBL - 1; 58230294Ssam dr->dr_addmod = (char)DRADDMOD; 58330294Ssam dr->dr_cstat = FCN1; /* Set FCN1 in ICR to DMA in*/ 58430294Ssam if ((dra->dr_flags & DR_LOOPTST) == 0) { 58530138Ssam /* Use pulse reg */ 58630294Ssam dr->dr_pulse = RDMA|RATN|RMSK|CYCL|GO; 58730138Ssam /* Wait for DMA complete; REDY and DMAF are true in ISR */ 58830138Ssam wait = 0; 58930294Ssam while ((result=(dr->dr_cstat & (REDY|DMAF))) != (REDY|DMAF)) { 59030138Ssam printf("\n\tWait for DMA to complete...ISR:%lx",result); 59130138Ssam if (++wait > 5) { 59230138Ssam printf("\n\t DMA input timeout!!, ISR:%lx", 59330138Ssam result); 59430138Ssam return; 59530138Ssam } 59630138Ssam } 59730294Ssam } else { 59830138Ssam /* Enable DMA e-o-r interrupt */ 59930294Ssam dr->dr_pulse = IENB|RDMA|RATN|CYCL|GO; 60030138Ssam /* Wait for DMA complete; DR_LOOPTST is false in dra->dr_flags*/ 60130138Ssam wait = 0; 60230138Ssam while (dra->dr_flags & DR_LOOPTST) { 60330138Ssam result = dr->dr_cstat & 0xffff; 60430294Ssam printf("\n\tWait for DMA e-o-r intr...ISR:%lx", result); 60530138Ssam if (++wait > 7) { 60630138Ssam printf("\n\t DMA e-o-r timeout!!, ISR:%lx", 60730138Ssam result); 60830138Ssam dra->dr_flags &= ~DR_LOOPTST; 60930138Ssam return; 61030138Ssam } 61130138Ssam } 61230138Ssam dra->dr_flags |= DR_LOOPTST; 61330138Ssam } 61430294Ssam mtpr(P1DC, tstpat); /* Purge cache */ 61530294Ssam mtpr(P1DC, 0x3ff+tstpat); 61630294Ssam for (ix=0; ix<DMATBL; ix++) { 61730138Ssam if (tstpat[ix] != 0x1111) { 61830294Ssam printf("\n\t Fails, ix:%d, expected:%x --- actual:%x", 61930294Ssam ix, 0x1111, tstpat[ix]); 62030138Ssam return; 62130138Ssam } 62230138Ssam } 62330294Ssam if ((dra->dr_flags & DR_LOOPTST) == 0) { 62430138Ssam dra->dr_flags |= DR_LOOPTST; 62530138Ssam printf(" OK..\n\tDMA end of range interrupt..."); 62630138Ssam goto dmain; 62730138Ssam } 62830138Ssam printf(" OK..\n\tAttention interrupt...."); 62930294Ssam dr->dr_pulse = IENB|RDMA; 63030294Ssam dr->dr_pulse = FCN2; 63130138Ssam /* Wait for ATTN interrupt; DR_LOOPTST is false in dra->dr_flags*/ 63230138Ssam wait = 0; 63330138Ssam while (dra->dr_flags & DR_LOOPTST) { 63430138Ssam result = dr->dr_cstat & 0xffff; 63530138Ssam printf("\n\tWait for Attention intr...ISR:%lx",result); 63630138Ssam if (++wait > 7) { 63730138Ssam printf("\n\t Attention interrupt timeout!!, ISR:%lx", 63830138Ssam result); 63930138Ssam dra->dr_flags &= ~DR_LOOPTST; 64030138Ssam return; 64130138Ssam } 64230138Ssam } 64330138Ssam dra->dr_flags &= ~DR_LOOPTST; 64430138Ssam printf(" OK..\n\tDone..."); 64530138Ssam } 64630138Ssam 64729651Ssam /* Reset state on Unibus reset */ 64830294Ssam /*ARGSUSED*/ 64929651Ssam drreset(uban) 65030294Ssam int uban; 65129651Ssam { 65229651Ssam 65329651Ssam } 65429651Ssam 65529651Ssam /* 65629651Ssam * An interrupt is caused either by an error, 65729651Ssam * base address overflow, or transfer complete 65829651Ssam */ 65930294Ssam drintr(dr11) 66030294Ssam int dr11; 66129651Ssam { 66230294Ssam register struct dr_aux *dra = &dr_aux[dr11]; 66330294Ssam register struct rsdevice *rsaddr = RSADDR(dr11); 66430294Ssam register struct buf *bp; 66530294Ssam register short status; 66629651Ssam 66730294Ssam status = rsaddr->dr_cstat & 0xffff; /* get board status register */ 66830294Ssam dra->dr_istat = status; 66929651Ssam #ifdef DR_DEBUG 67030294Ssam if (DR11 & 2) 67130294Ssam printf("\ndrintr: dr11 status : %lx",status & 0xffff); 67229651Ssam #endif 67330294Ssam if (dra->dr_flags & DR_LOOPTST) { /* doing loopback test */ 67430294Ssam dra->dr_flags &= ~DR_LOOPTST; 67530294Ssam return; 67630294Ssam } 67730294Ssam /* 67830294Ssam * Make sure this is not a stray interrupt; at least one of dmaf or attf 67930294Ssam * must be set. Note that if the dr11 interrupt enable latch is reset 68030294Ssam * during a hardware interrupt ack sequence, and by the we get to this 68130294Ssam * point in the interrupt code it will be 0. This is done to give the 68230294Ssam * programmer some control over how the two more-or-less independent 68330294Ssam * interrupt sources on the board are handled. 68430294Ssam * If the attention flag is set when drstrategy() is called to start a 68530294Ssam * dma read or write an interrupt will be generated as soon as the 68630294Ssam * strategy routine enables interrupts for dma end-of-range. This will 68730294Ssam * cause execution of the interrupt routine (not necessarily bad) and 68830294Ssam * will cause the interrupt enable mask to be reset (very bad since the 68930294Ssam * dma end-of-range condition will not be able to generate an interrupt 69030294Ssam * when it occurs) causing the dma operation to time-out (even though 69130294Ssam * the dma transfer will be done successfully) or hang the process if a 69230294Ssam * software time-out capability is not implemented. One way to avoid 69330294Ssam * this situation is to check for a pending attention interrupt (attf 69430294Ssam * set) by calling drioctl() before doing a read or a write. For the 69530294Ssam * time being this driver will solve the problem by clearing the attf 69630294Ssam * flag in the status register before enabling interrupts in 69730294Ssam * drstrategy(). 69830294Ssam * 69930294Ssam * **** The IKON 10084 for which this driver is written will set both 70030294Ssam * attf and dmaf if dma is terminated by an attention pulse. This will 70130294Ssam * cause a wakeup(&dr_aux), which will be ignored since it is not being 70230294Ssam * waited on, and an iodone(bp) which is the desired action. Some other 70330294Ssam * dr11 emulators, in particular the IKON 10077 for the Multibus, donot 70430294Ssam * dmaf in this case. This may require some addtional code in the inter- 70530294Ssam * rupt routine to ensure that en iodone(bp) is issued when dma is term- 70630294Ssam * inated by attention. 70730294Ssam */ 70830294Ssam bp = dra->dr_actf; 70930294Ssam if ((status & (ATTF | DMAF)) == 0) { 71030294Ssam printf("dr%d: stray interrupt, status=%x", dr11, status); 71130294Ssam return; 71230294Ssam } 71330294Ssam if (status & DMAF) { /* End-of-range interrupt */ 71430294Ssam dra->dr_flags |= DR_DMAX; 71529651Ssam 71629651Ssam #ifdef DR_DEBUG 71730294Ssam if (DR11 & 2) 71830294Ssam printf("\ndrintr: e-o-r interrupt,cstat:%lx,dr_flags:%lx", 71930294Ssam status&0xffff, dra->dr_flags & DR_ACTV); 72029651Ssam #endif 72130294Ssam if ((dra->dr_flags & DR_ACTV) == 0) { 72230294Ssam /* We are not doing DMA !! */ 72330294Ssam bp->b_flags |= B_ERROR; 72430294Ssam } else { 72530294Ssam if (dra->dr_op == DR_READ) 72630294Ssam mtpr(P1DC, bp->b_un.b_addr); 72730294Ssam dra->dr_bycnt -= bp->b_bcount; 72830294Ssam if (dra->dr_bycnt >0) { 72930294Ssam bp->b_un.b_addr += bp->b_bcount; 73030294Ssam bp->b_bcount = (dra->dr_bycnt > NBPG) ? NBPG: 73129651Ssam dra->dr_bycnt; 73230294Ssam drstart(rsaddr, dra, bp); 73330294Ssam return; 73430294Ssam } 73529651Ssam } 73630294Ssam dra->dr_flags &= ~DR_ACTV; 73730294Ssam wakeup((caddr_t)dra); /* Wakeup waiting in drwait() */ 73830294Ssam rsaddr->dr_pulse = (RPER|RDMA|RATN); /* reset dma e-o-r flag */ 73929651Ssam } 74030294Ssam /* 74130294Ssam * Now test for attention interrupt -- It may be set in addition to 74230294Ssam * the dma e-o-r interrupt. If we get one we will issue a wakeup to 74330294Ssam * the drioctl() routine which is presumable waiting for one. 74430294Ssam * The program may have to monitor the attention interrupt received 74530294Ssam * flag in addition to doing waits for the interrupt. Futhermore, 74630294Ssam * interrupts are not enabled unless dma is in progress or drioctl() 74730294Ssam * has been called to wait for attention -- this may produce some 74830294Ssam * strange results if attf is set on the dr11 when a read or a write 74930294Ssam * is initiated, since that will enables interrupts. 75030294Ssam * **** The appropriate code for this interrupt routine will probably 75130294Ssam * be rather application dependent. 75230294Ssam */ 75330294Ssam if (status & ATTF) { 75430294Ssam dra->dr_flags |= DR_ATRX; 75530294Ssam dra->dr_flags &= ~DR_ATWT; 75630294Ssam rsaddr->dr_cstat = RATN; /* reset attention flag */ 75730294Ssam /* 75830294Ssam * Some applications which use attention to terminate 75930294Ssam * dma may also want to issue an iodone() here to 76030294Ssam * wakeup physio(). 76130294Ssam */ 76230294Ssam wakeup((caddr_t)&dra->dr_cmd); 76330294Ssam } 76429651Ssam } 76529651Ssam 76629651Ssam unsigned 76729651Ssam drminphys(bp) 76830294Ssam struct buf *bp; 76929651Ssam { 77030294Ssam 77130294Ssam if (bp->b_bcount > 65536) 77230294Ssam bp->b_bcount = 65536; 77329651Ssam } 77429651Ssam 77529651Ssam /* 77630294Ssam * This routine performs the device unique operations on the DR11W 77730294Ssam * it is passed as an argument to and invoked by physio 77829651Ssam */ 77929651Ssam drstrategy (bp) 78030294Ssam register struct buf *bp; 78129651Ssam { 78230294Ssam register int s; 78330294Ssam int unit = RSUNIT(bp->b_dev); 78430294Ssam register struct rsdevice *rsaddr = RSADDR(unit); 78530294Ssam register struct dr_aux *dra = &dr_aux[unit]; 78630294Ssam register int ok; 78729651Ssam #ifdef DR_DEBUG 78830294Ssam register char *caddr; 78930294Ssam long drva(); 79029651Ssam #endif 79129651Ssam 79230294Ssam if ((dra->dr_flags & DR_OPEN) == 0) { /* Device not open */ 79330294Ssam bp->b_error = ENXIO; 79430294Ssam bp->b_flags |= B_ERROR; 79530294Ssam iodone (bp); 79630294Ssam return; 79730294Ssam } 79830294Ssam while (dra->dr_flags & DR_ACTV) 79930294Ssam /* Device is active; should never be in here... */ 800*40735Skarels (void) tsleep((caddr_t)&dra->dr_flags, DRPRI, devio, 0); 80130294Ssam dra->dr_actf = bp; 80229651Ssam #ifdef DR_DEBUG 80330294Ssam drva(dra, bp->b_proc, bp->b_un.b_addr, bp->b_bcount); 80429651Ssam #endif 80530294Ssam dra->dr_oba = bp->b_un.b_addr; /* Save original addr, count */ 80630294Ssam dra->dr_obc = bp->b_bcount; 80730294Ssam dra->dr_bycnt = bp->b_bcount; /* Save xfer count used by drintr() */ 80830294Ssam if ((((long)bp->b_un.b_addr & 0x3fffffff) >> PGSHIFT) != 80930294Ssam ((((long)bp->b_un.b_addr & 0x3fffffff) + bp->b_bcount) >> PGSHIFT)) 81030294Ssam bp->b_bcount = NBPG - (((long)bp->b_un.b_addr) & PGOFSET); 81130294Ssam dra->dr_flags |= DR_ACTV; /* Mark active (use in intr handler) */ 81230294Ssam s = SPL_UP(); 81330294Ssam drstart(rsaddr,dra,bp); 81430294Ssam splx(s); 81530294Ssam ok = drwait(rsaddr,dra); 81629651Ssam #ifdef DR_DEBUG 81730294Ssam if (DR11 & 0x40) { 81830294Ssam caddr = (char *)dra->dr_oba; 81930294Ssam if (dra->dr_op == DR_READ) 82030294Ssam printf("\nAfter read: (%lx)(%lx)", 82130294Ssam caddr[0]&0xff, caddr[1]&0xff); 82230294Ssam } 82329651Ssam #endif 82430294Ssam dra->dr_flags &= ~DR_ACTV; /* Clear active flag */ 82530294Ssam bp->b_un.b_addr = dra->dr_oba; /* Restore original addr, count */ 82630294Ssam bp->b_bcount = dra->dr_obc; 82730294Ssam if (!ok) 82830294Ssam bp->b_flags |= B_ERROR; 82930294Ssam /* Mark buffer B_DONE,so physstrat() in ml/machdep.c won't sleep */ 83030294Ssam iodone(bp); 83130294Ssam wakeup((caddr_t)&dra->dr_flags); 83230294Ssam /* 83330294Ssam * Return to the calling program (physio()). Physio() will sleep 83430294Ssam * until awaken by a call to iodone() in the interupt handler -- 83530294Ssam * which will be called by the dispatcher when it receives dma 83630294Ssam * end-of-range interrupt. 83730294Ssam */ 83829651Ssam } 83929651Ssam 84030294Ssam drwait(rs, dr) 84130294Ssam register struct rsdevice *rs; 84230294Ssam register struct dr_aux *dr; 84329651Ssam { 84430294Ssam int s; 84529651Ssam 84629651Ssam s = SPL_UP(); 84730294Ssam while (dr->dr_flags & DR_ACTV) 848*40735Skarels (void) tsleep((caddr_t)dr, DRPRI, devio, 0); 84929651Ssam splx(s); 85030294Ssam if (dr->dr_flags & DR_TMDM) { /* DMA timed out */ 85129651Ssam dr->dr_flags &= ~DR_TMDM; 85230294Ssam return (0); 85329651Ssam } 85430294Ssam if (rs->dr_cstat & (PERR|BERR|TERR)) { 85530294Ssam dr->dr_actf->b_flags |= B_ERROR; 85630294Ssam return (0); 85729651Ssam } 85829651Ssam dr->dr_flags &= ~DR_DMAX; 85930294Ssam return (1); 86029651Ssam } 86129651Ssam 86230294Ssam /* 86330294Ssam * 86430294Ssam * The lower 8-bit of tinfo is the minor device number, the 86530294Ssam * remaining higher 8-bit is the current timout number 86630294Ssam */ 86729651Ssam drrwtimo(tinfo) 86830294Ssam register u_long tinfo; 86930294Ssam { 87030294Ssam register long unit = tinfo & 0xff; 87129651Ssam register struct dr_aux *dr = &dr_aux[unit]; 87229651Ssam register struct rsdevice *rs = dr->dr_addr; 87329651Ssam 87430294Ssam /* 87530294Ssam * If this is not the timeout that drwrite/drread is waiting 87630294Ssam * for then we should just go away 87730294Ssam */ 87830294Ssam if ((tinfo &~ 0xff) != (dr->currenttimo << 8)) 87930294Ssam return; 88029651Ssam /* Mark the device timed out */ 88129651Ssam dr->dr_flags |= DR_TMDM; 88229651Ssam dr->dr_flags &= ~DR_ACTV; 88329651Ssam rs->dr_pulse = RMSK; /* Inihibit interrupt */ 88429651Ssam rs->dr_pulse = (RPER|RDMA|RATN|IENB); /* Clear DMA logic */ 88530294Ssam /* 88630294Ssam * Some applications will not issue a master after dma timeout, 88730294Ssam * since doing so sends an INIT H pulse to the external device, 88830294Ssam * which may produce undesirable side-effects. 88930294Ssam */ 89029651Ssam /* Wake up process waiting in drwait() and flag the error */ 89130294Ssam dr->dr_actf->b_flags |= B_ERROR; 89229651Ssam wakeup((caddr_t)dr->dr_cmd); 89329651Ssam } 89429651Ssam 89529651Ssam /* 89630294Ssam * Kick the driver every second 89730294Ssam */ 89829651Ssam drtimo(dev) 89930294Ssam dev_t dev; 90029651Ssam { 90130294Ssam register int unit = RSUNIT(dev); 90229651Ssam register struct dr_aux *dr; 90329651Ssam 90430294Ssam dr = &dr_aux[unit]; 90529651Ssam if (dr->dr_flags & DR_OPEN) 90630294Ssam timeout(drtimo, (caddr_t)dev, hz); 90729651Ssam wakeup((caddr_t)dr); /* Wakeup any process waiting for interrupt */ 90829651Ssam } 90929651Ssam 91029651Ssam #ifdef DR_DEBUG 91130294Ssam drva(dra, p, va, bcnt) 91230294Ssam struct dr_aux *dra; 91330294Ssam struct proc *p; 91430294Ssam char *va; 91530294Ssam long bcnt; 91630294Ssam { 91730294Ssam register long first, last , np; 91829651Ssam 91929651Ssam if (DR11 & 0x20) { 92030294Ssam first = ((long)(vtoph(p, (unsigned)va))) >> 10; 92130294Ssam last = ((long)(vtoph(p, (unsigned)va+bcnt))) >> 10; 92229651Ssam np = bcnt / 0x3ff; 92329651Ssam printf("\ndrva: (op:%ld)(first:%ld)(last:%ld)(np:%ld)(cnt:%ld)", 92429651Ssam dra->dr_op,first,last,np,bcnt); 92529651Ssam } 92629651Ssam } 92729651Ssam #endif 92829651Ssam 92930294Ssam drstart(rsaddr, dra, bp) 93030294Ssam register struct rsdevice *rsaddr; 93130294Ssam register struct dr_aux *dra; 93230294Ssam register struct buf *bp; 93330294Ssam { 93430294Ssam register long addr; 93530294Ssam u_short go; 93629651Ssam 93729651Ssam #ifdef DR_DEBUG 93830294Ssam if (dra->dr_op == DR_READ && (DR11 & 8)) { 93930294Ssam char *caddr = (char *)bp->b_un.b_addr; 94029651Ssam printf("\ndrstart: READ, bcnt:%ld",bp->b_bcount); 94129651Ssam printf(",(%lx)(%lx)",caddr[0]&0xff,caddr[1]&0xff); 94229651Ssam } 94329651Ssam #endif 94430294Ssam /* we are doing raw IO, bp->b_un.b_addr is user's address */ 94530294Ssam addr = (long)vtoph(bp->b_proc, (unsigned)bp->b_un.b_addr); 94630294Ssam /* 94730294Ssam * Set DMA address into DR11 interace registers: DR11 requires that 94830294Ssam * the address be right shifted 1 bit position before it is written 94930294Ssam * to the board (The board will left shift it one bit position before 95030294Ssam * it places the address on the bus 95130294Ssam */ 95230294Ssam rsaddr->dr_walo = (addr >> 1) & 0xffff; 95330294Ssam rsaddr->dr_wahi = (addr >> 17) & 0x7fff; 95430294Ssam /* Set DMA range count: (number of words - 1) */ 95530294Ssam rsaddr->dr_range = (bp->b_bcount >> 1) - 1; 95630294Ssam /* Set address modifier code to be used for DMA access to memory */ 95730294Ssam rsaddr->dr_addmod = DRADDMOD; 95830294Ssam /* 95930294Ssam * Now determine whether this is a read or a write. ***** This is 96030294Ssam * probably only usefull for link mode operation, since dr11 doesnot 96130294Ssam * controll the direction of data transfer. The C1 control input 96230294Ssam * controls whether the hardware is doing a read or a write. In link 96330294Ssam * mode this is controlled by function 1 latch (looped back by the 96430294Ssam * cable) and could be set the program. In the general case, the dr11 96530294Ssam * doesnot know in advance what the direction of transfer is - although 96630294Ssam * the program and protocol logic probably is 96730294Ssam */ 96829651Ssam #ifdef DR_DEBUG 96930294Ssam if (DR11 & 1) 97030294Ssam printf( 97130294Ssam "\ndrstrat: about to GO..,dr_cmd:%lx,drstat:%lx,drcnt:%ld,cdata:%lx,OP:%ld", 97230294Ssam dra->dr_cmd, rsaddr->dr_cstat, rsaddr->dr_range, 97330294Ssam rsaddr->dr_data, dra->dr_op); 97429651Ssam #endif 97530294Ssam /* 97630294Ssam * Update function latches may have been done already by drioctl() if 97730294Ssam * request from drioctl() 97830294Ssam */ 97930294Ssam if (dra->dr_cmd & DR_DFCN) { /* deferred function write */ 98030294Ssam dra->dr_cmd &= ~DR_DFCN; /* Clear request */ 98130294Ssam go = dra->dr_cmd & DR_FMSK; /* mask out fcn bits */ 98230294Ssam rsaddr->dr_cstat = go; /* Write it to the board */ 98330294Ssam } 98430294Ssam /* Clear dmaf and attf to assure a clean dma start */ 98530294Ssam rsaddr->dr_pulse = RATN|RDMA|RPER; 98630294Ssam rsaddr->dr_cstat = IENB|GO|CYCL|dra->dr_op; /* GO...... */ 98730294Ssam /* 98830294Ssam * Now check for software cycle request -- usually 98930294Ssam * by transmitter in link mode. 99030294Ssam */ 99130294Ssam if (dra->dr_cmd & DR_PCYL) { 99230294Ssam dra->dr_cmd &= ~DR_PCYL; /* Clear request */ 99330294Ssam rsaddr->dr_pulse = CYCL; /* Use pulse register again */ 99430294Ssam } 99530294Ssam /* 99630294Ssam * Now check for deferred ACLO FCNT2 pulse request -- usually to tell 99730294Ssam * the transmitter (via its attention) that we have enabled dma. 99830294Ssam */ 99930294Ssam if (dra->dr_cmd & DR_DACL) { 100030294Ssam dra->dr_cmd &= ~DR_DACL; /* Clear request */ 100130294Ssam rsaddr->dr_pulse = FCN2; /* Use pulse register again */ 100230294Ssam } 100329651Ssam } 100429651Ssam #endif NDR 1005