1224 lines
32 KiB
C
1224 lines
32 KiB
C
/* $NetBSD: siop.c,v 1.19 1995/01/05 07:22:48 chopps Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1994 Michael L. Hitch
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
* All rights reserved.
|
|
*
|
|
* This code is derived from software contributed to Berkeley by
|
|
* Van Jacobson of Lawrence Berkeley Laboratory.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
* must display the following acknowledgement:
|
|
* This product includes software developed by the University of
|
|
* California, Berkeley and its contributors.
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* @(#)siop.c 7.5 (Berkeley) 5/4/91
|
|
*/
|
|
|
|
/*
|
|
* AMIGA 53C710 scsi adaptor driver
|
|
*/
|
|
|
|
/* need to know if any tapes have been configured */
|
|
#include "st.h"
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/device.h>
|
|
#include <sys/buf.h>
|
|
#include <scsi/scsi_all.h>
|
|
#include <scsi/scsiconf.h>
|
|
#include <machine/cpu.h>
|
|
#include <amiga/amiga/custom.h>
|
|
#include <amiga/dev/siopreg.h>
|
|
#include <amiga/dev/siopvar.h>
|
|
|
|
extern u_int kvtop();
|
|
|
|
/*
|
|
* SCSI delays
|
|
* In u-seconds, primarily for state changes on the SPC.
|
|
*/
|
|
#define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */
|
|
#define SCSI_DATA_WAIT 500000 /* wait per data in/out step */
|
|
#define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */
|
|
|
|
int siopicmd __P((struct siop_softc *, int, int, void *, int, void *, int));
|
|
int siopgo __P((struct siop_softc *, struct scsi_xfer *));
|
|
int siopgetsense __P((struct siop_softc *, struct scsi_xfer *));
|
|
void siopabort __P((struct siop_softc *, siop_regmap_p, char *));
|
|
void sioperror __P((struct siop_softc *, siop_regmap_p, u_char));
|
|
void siopstart __P((struct siop_softc *));
|
|
void siopreset __P((struct siop_softc *));
|
|
void siopsetdelay __P((int));
|
|
void siop_scsidone __P((struct siop_softc *, int));
|
|
void siop_donextcmd __P((struct siop_softc *));
|
|
int siopintr __P((struct siop_softc *));
|
|
|
|
/* 53C710 script */
|
|
#include <amiga/dev/siop_script.out>
|
|
|
|
/* default to not inhibit sync negotiation on any drive */
|
|
u_char siop_inhibit_sync[8] = { 0, 0, 0, 0, 0, 0, 0 }; /* initialize, so patchable */
|
|
u_char siop_allow_disc[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
int siop_no_dma = 0;
|
|
|
|
int siop_reset_delay = 250; /* delay after reset, in milleseconds */
|
|
int siop_sync_period = 50; /* synchronous transfer period, in nanoseconds */
|
|
|
|
int siop_cmd_wait = SCSI_CMD_WAIT;
|
|
int siop_data_wait = SCSI_DATA_WAIT;
|
|
int siop_init_wait = SCSI_INIT_WAIT;
|
|
|
|
/*
|
|
* sync period transfer lookup - only valid for 66Mhz clock
|
|
*/
|
|
static struct {
|
|
unsigned char x; /* period from sync request message */
|
|
unsigned char y; /* siop_period << 4 | sbcl */
|
|
} xxx[] = {
|
|
{ 60/4, 0<<4 | 1},
|
|
{ 76/4, 1<<4 | 1},
|
|
{ 92/4, 2<<4 | 1},
|
|
{ 92/4, 0<<4 | 2},
|
|
{108/4, 3<<4 | 1},
|
|
{116/4, 1<<4 | 2},
|
|
{120/4, 4<<4 | 1},
|
|
{120/4, 0<<4 | 3},
|
|
{136/4, 5<<4 | 1},
|
|
{140/4, 2<<4 | 2},
|
|
{152/4, 6<<4 | 1},
|
|
{152/4, 1<<4 | 3},
|
|
{164/4, 3<<4 | 2},
|
|
{168/4, 7<<4 | 1},
|
|
{180/4, 2<<4 | 3},
|
|
{184/4, 4<<4 | 2},
|
|
{208/4, 5<<4 | 2},
|
|
{212/4, 3<<4 | 3},
|
|
{232/4, 6<<4 | 2},
|
|
{240/4, 4<<4 | 3},
|
|
{256/4, 7<<4 | 2},
|
|
{272/4, 5<<4 | 3},
|
|
{300/4, 6<<4 | 3},
|
|
{332/4, 7<<4 | 3}
|
|
};
|
|
|
|
#ifdef DEBUG
|
|
#define QPRINTF(a) if (siop_debug > 1) printf a
|
|
/*
|
|
* 0x01 - full debug
|
|
* 0x02 - DMA chaining
|
|
* 0x04 - siopintr
|
|
* 0x08 - phase mismatch
|
|
* 0x10 - panic on phase mismatch
|
|
* 0x20 - panic on unhandled exceptions
|
|
* 0x100 - disconnect/reconnect
|
|
*/
|
|
int siop_debug = 0;
|
|
int siopsync_debug = 0;
|
|
int siopdma_hits = 0;
|
|
int siopdma_misses = 0;
|
|
int siopchain_ints = 0;
|
|
int siopstarts = 0;
|
|
int siopints = 0;
|
|
int siopphmm = 0;
|
|
#else
|
|
#define QPRINTF(a)
|
|
#endif
|
|
|
|
|
|
/*
|
|
* default minphys routine for siop based controllers
|
|
*/
|
|
void
|
|
siop_minphys(bp)
|
|
struct buf *bp;
|
|
{
|
|
/*
|
|
* no max transfer at this level
|
|
*/
|
|
}
|
|
|
|
/*
|
|
* used by specific siop controller
|
|
*
|
|
*/
|
|
int
|
|
siop_scsicmd(xs)
|
|
struct scsi_xfer *xs;
|
|
{
|
|
struct siop_pending *pendp;
|
|
struct siop_softc *dev;
|
|
struct scsi_link *slp;
|
|
int flags, s, i;
|
|
|
|
slp = xs->sc_link;
|
|
dev = slp->adapter_softc;
|
|
flags = xs->flags;
|
|
|
|
if (flags & SCSI_DATA_UIO)
|
|
panic("siop: scsi data uio requested");
|
|
|
|
if (dev->sc_xs && flags & SCSI_POLL)
|
|
panic("siop_scsicmd: busy");
|
|
|
|
s = splbio();
|
|
pendp = &dev->sc_xsstore[slp->target][slp->lun];
|
|
if (pendp->xs) {
|
|
splx(s);
|
|
return(TRY_AGAIN_LATER);
|
|
}
|
|
|
|
if (dev->sc_xs) {
|
|
pendp->xs = xs;
|
|
TAILQ_INSERT_TAIL(&dev->sc_xslist, pendp, link);
|
|
splx(s);
|
|
return(SUCCESSFULLY_QUEUED);
|
|
}
|
|
pendp->xs = NULL;
|
|
dev->sc_xs = xs;
|
|
splx(s);
|
|
|
|
/*
|
|
* nothing is pending do it now.
|
|
*/
|
|
siop_donextcmd(dev);
|
|
|
|
if (flags & SCSI_POLL)
|
|
return(COMPLETE);
|
|
return(SUCCESSFULLY_QUEUED);
|
|
}
|
|
|
|
/*
|
|
* entered with dev->sc_xs pointing to the next xfer to perform
|
|
*/
|
|
void
|
|
siop_donextcmd(dev)
|
|
struct siop_softc *dev;
|
|
{
|
|
struct scsi_xfer *xs;
|
|
struct scsi_link *slp;
|
|
int flags, stat, i;
|
|
|
|
xs = dev->sc_xs;
|
|
slp = xs->sc_link;
|
|
flags = xs->flags;
|
|
|
|
if (flags & SCSI_RESET)
|
|
siopreset(dev);
|
|
|
|
xs->cmd->bytes[0] |= slp->lun << 5;
|
|
for (i = 0; i < 2; ++i) {
|
|
if (dev->sc_iob[i].sc_xs == NULL) {
|
|
dev->sc_iob[i].sc_xs = xs;
|
|
dev->sc_cur = & dev->sc_iob[i];
|
|
dev->sc_iob[i].sc_stat[0] = -1;
|
|
break;
|
|
}
|
|
}
|
|
if (dev->sc_cur == NULL)
|
|
panic ("siop: too many I/O's");
|
|
++dev->sc_active;
|
|
#if 0
|
|
if (dev->sc_active > 1) {
|
|
printf ("active count %d\n", dev->sc_active);
|
|
}
|
|
#endif
|
|
if (flags & SCSI_POLL || siop_no_dma)
|
|
stat = siopicmd(dev, slp->target, slp->lun, xs->cmd,
|
|
xs->cmdlen, xs->data, xs->datalen);
|
|
else if (siopgo(dev, xs) == 0)
|
|
return;
|
|
else
|
|
stat = dev->sc_cur->sc_stat[0];
|
|
|
|
siop_scsidone(dev, stat);
|
|
}
|
|
|
|
void
|
|
siop_scsidone(dev, stat)
|
|
struct siop_softc *dev;
|
|
int stat;
|
|
{
|
|
struct siop_pending *pendp;
|
|
struct scsi_xfer *xs;
|
|
int s, donext;
|
|
|
|
xs = dev->sc_xs;
|
|
#ifdef DIAGNOSTIC
|
|
if (xs == NULL)
|
|
panic("siop_scsidone");
|
|
#endif
|
|
/*
|
|
* is this right?
|
|
*/
|
|
xs->status = stat;
|
|
|
|
if (stat == 0)
|
|
xs->resid = 0;
|
|
else {
|
|
switch(stat) {
|
|
case SCSI_CHECK:
|
|
if (stat = siopgetsense(dev, xs))
|
|
goto bad_sense;
|
|
xs->error = XS_SENSE;
|
|
break;
|
|
case SCSI_BUSY:
|
|
xs->error = XS_BUSY;
|
|
break;
|
|
bad_sense:
|
|
default:
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
QPRINTF(("siop_scsicmd() bad %x\n", stat));
|
|
break;
|
|
}
|
|
}
|
|
xs->flags |= ITSDONE;
|
|
|
|
--dev->sc_active;
|
|
dev->sc_cur->sc_xs = NULL;
|
|
dev->sc_cur = NULL;
|
|
/*
|
|
* if another command is already pending (i.e. it was pre-empted
|
|
* by a reconnecting device), make it the current command and
|
|
* continue
|
|
*/
|
|
|
|
/*
|
|
* grab next command before scsi_done()
|
|
* this way no single device can hog scsi resources.
|
|
*/
|
|
s = splbio();
|
|
pendp = dev->sc_xslist.tqh_first;
|
|
if (pendp == NULL) {
|
|
donext = 0;
|
|
dev->sc_xs = NULL;
|
|
} else {
|
|
donext = 1;
|
|
TAILQ_REMOVE(&dev->sc_xslist, pendp, link);
|
|
dev->sc_xs = pendp->xs;
|
|
pendp->xs = NULL;
|
|
}
|
|
splx(s);
|
|
scsi_done(xs);
|
|
|
|
if (donext)
|
|
siop_donextcmd(dev);
|
|
else if (dev->sc_active && dev->sc_xs == NULL) {
|
|
/* printf ("siop_scsidone: still active %d\n", dev->sc_active);*/
|
|
/* dev->sc_siopp->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;*/
|
|
}
|
|
}
|
|
|
|
int
|
|
siopgetsense(dev, xs)
|
|
struct siop_softc *dev;
|
|
struct scsi_xfer *xs;
|
|
{
|
|
struct scsi_sense rqs;
|
|
struct scsi_link *slp;
|
|
int stat;
|
|
|
|
slp = xs->sc_link;
|
|
|
|
rqs.opcode = REQUEST_SENSE;
|
|
rqs.byte2 = slp->lun << 5;
|
|
#ifdef not_yet
|
|
rqs.length = xs->req_sense_length ? xs->req_sense_length :
|
|
sizeof(xs->sense);
|
|
#else
|
|
rqs.length = sizeof(xs->sense);
|
|
#endif
|
|
if (rqs.length > sizeof (xs->sense))
|
|
rqs.length = sizeof (xs->sense);
|
|
rqs.unused[0] = rqs.unused[1] = rqs.control = 0;
|
|
|
|
return(siopicmd(dev, slp->target, slp->lun, &rqs, sizeof(rqs),
|
|
&xs->sense, rqs.length));
|
|
}
|
|
|
|
void
|
|
siopabort(dev, regs, where)
|
|
register struct siop_softc *dev;
|
|
siop_regmap_p regs;
|
|
char *where;
|
|
{
|
|
int i;
|
|
|
|
printf ("%s: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
|
|
dev->sc_dev.dv_xname,
|
|
where, regs->siop_dstat, regs->siop_sstat0, regs->siop_sbcl);
|
|
|
|
if (dev->sc_active > 0) {
|
|
#ifdef TODO
|
|
SET_SBIC_cmd (regs, SBIC_CMD_ABORT);
|
|
WAIT_CIP (regs);
|
|
|
|
GET_SBIC_asr (regs, asr);
|
|
if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
|
|
{
|
|
/* ok, get more drastic.. */
|
|
|
|
SET_SBIC_cmd (regs, SBIC_CMD_RESET);
|
|
delay(25);
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
GET_SBIC_csr (regs, csr); /* clears interrupt also */
|
|
|
|
dev->sc_flags &= ~SIOP_SELECTED;
|
|
return;
|
|
}
|
|
|
|
do
|
|
{
|
|
SBIC_WAIT (regs, SBIC_ASR_INT, 0);
|
|
GET_SBIC_csr (regs, csr);
|
|
}
|
|
while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
|
|
&& (csr != SBIC_CSR_CMD_INVALID));
|
|
#endif
|
|
|
|
/* lets just hope it worked.. */
|
|
dev->sc_flags &= ~SIOP_SELECTED;
|
|
for (i = 0; i < 2; ++i) {
|
|
if (dev->sc_iob[i].sc_xs && &dev->sc_iob[i] !=
|
|
dev->sc_cur) {
|
|
printf ("siopabort: cleanup!\n");
|
|
dev->sc_iob[i].sc_xs = NULL;
|
|
}
|
|
}
|
|
dev->sc_active = 0;
|
|
}
|
|
}
|
|
|
|
void
|
|
siopinitialize(dev)
|
|
struct siop_softc *dev;
|
|
{
|
|
/*
|
|
* Need to check that scripts is on a long word boundary
|
|
* and that DS is on a long word boundary.
|
|
* Also need to verify that dev doesn't span non-contiguous
|
|
* physical pages.
|
|
*/
|
|
dev->sc_scriptspa = kvtop(scripts);
|
|
#if 0
|
|
dev->sc_dspa = kvtop(&dev->sc_ds);
|
|
dev->sc_lunpa = kvtop(&dev->sc_msgout);
|
|
dev->sc_statuspa = kvtop(&dev->sc_stat[0]);
|
|
dev->sc_msgpa = kvtop(&dev->sc_msg[0]);
|
|
#endif
|
|
siopreset (dev);
|
|
}
|
|
|
|
void
|
|
siopreset(dev)
|
|
struct siop_softc *dev;
|
|
{
|
|
siop_regmap_p regs;
|
|
u_int i, s;
|
|
u_char my_id, dummy;
|
|
|
|
regs = dev->sc_siopp;
|
|
|
|
if (dev->sc_flags & SIOP_ALIVE)
|
|
siopabort(dev, regs, "reset");
|
|
|
|
printf("%s: ", dev->sc_dev.dv_xname); /* XXXX */
|
|
|
|
s = splbio();
|
|
my_id = 7;
|
|
|
|
/*
|
|
* Reset the chip
|
|
* XXX - is this really needed?
|
|
*/
|
|
regs->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
|
|
regs->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
|
|
regs->siop_istat &= ~SIOP_ISTAT_RST;
|
|
/*
|
|
* Reset SCSI bus (do we really want this?)
|
|
*/
|
|
regs->siop_sien &= ~SIOP_SIEN_RST;
|
|
regs->siop_scntl1 |= SIOP_SCNTL1_RST;
|
|
delay(1);
|
|
regs->siop_scntl1 &= ~SIOP_SCNTL1_RST;
|
|
/* regs->siop_sien |= SIOP_SIEN_RST;*/
|
|
|
|
/*
|
|
* Set up various chip parameters
|
|
*/
|
|
regs->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
|
|
regs->siop_dcntl = dev->sc_clock_freq & 0xff;
|
|
regs->siop_dmode = 0x80; /* burst length = 4 */
|
|
regs->siop_sien = 0x00; /* don't enable interrupts yet */
|
|
regs->siop_dien = 0x00; /* don't enable interrupts yet */
|
|
regs->siop_scid = 1 << my_id;
|
|
regs->siop_dwt = 0x00;
|
|
regs->siop_ctest0 |= SIOP_CTEST0_BTD | SIOP_CTEST0_EAN;
|
|
regs->siop_ctest7 |= (dev->sc_clock_freq >> 8) & 0xff;
|
|
|
|
/* will need to re-negotiate sync xfers */
|
|
bzero(&dev->sc_sync, sizeof (dev->sc_sync));
|
|
|
|
i = regs->siop_istat;
|
|
if (i & SIOP_ISTAT_SIP)
|
|
dummy = regs->siop_sstat0;
|
|
if (i & SIOP_ISTAT_DIP)
|
|
dummy = regs->siop_dstat;
|
|
|
|
splx (s);
|
|
|
|
delay (siop_reset_delay * 1000);
|
|
printf("siop id %d reset V%d\n", my_id, regs->siop_ctest8 >> 4);
|
|
dev->sc_flags |= SIOP_ALIVE;
|
|
dev->sc_flags &= ~(SIOP_SELECTED | SIOP_DMA);
|
|
}
|
|
|
|
/*
|
|
* Setup Data Storage for 53C710 and start SCRIPTS processing
|
|
*/
|
|
|
|
void
|
|
siop_setup (dev, target, lun, cbuf, clen, buf, len)
|
|
struct siop_softc *dev;
|
|
int target;
|
|
int lun;
|
|
u_char *cbuf;
|
|
int clen;
|
|
u_char *buf;
|
|
int len;
|
|
{
|
|
siop_regmap_p regs = dev->sc_siopp;
|
|
int i;
|
|
int nchain;
|
|
int count, tcount;
|
|
char *addr, *dmaend;
|
|
struct siop_iob *iob = dev->sc_cur;
|
|
|
|
#ifdef DEBUG
|
|
if (regs->siop_sbcl & SIOP_BSY) {
|
|
printf ("ACK! siop was busy: regs %x script %x dsa %x\n",
|
|
regs, &scripts, &iob->sc_ds);
|
|
/*Debugger();*/
|
|
}
|
|
i = regs->siop_istat;
|
|
if (i & SIOP_ISTAT_DIP) {
|
|
int dstat;
|
|
dstat = regs->siop_dstat;
|
|
}
|
|
if (i & SIOP_ISTAT_SIP) {
|
|
int sstat;
|
|
sstat = regs->siop_sstat0;
|
|
}
|
|
#endif
|
|
dev->sc_istat = 0;
|
|
iob->sc_msgout[0] = MSG_IDENTIFY | lun;
|
|
/*
|
|
* HACK - if no data transfer, allow disconnects
|
|
*/
|
|
if (/*len == 0 || */ siop_allow_disc[target]) {
|
|
iob->sc_msgout[0] = MSG_IDENTIFY_DR | lun;
|
|
regs->siop_scntl1 |= SIOP_SCNTL1_ESR;
|
|
}
|
|
iob->sc_status = 0;
|
|
iob->sc_stat[0] = -1;
|
|
iob->sc_msg[0] = -1;
|
|
iob->sc_ds.scsi_addr = (0x10000 << target) | (dev->sc_sync[target].period << 8);
|
|
iob->sc_ds.idlen = 1;
|
|
iob->sc_ds.idbuf = (char *) kvtop(&iob->sc_msgout[0]);
|
|
iob->sc_ds.cmdlen = clen;
|
|
iob->sc_ds.cmdbuf = (char *) kvtop(cbuf);
|
|
iob->sc_ds.stslen = 1;
|
|
iob->sc_ds.stsbuf = (char *) kvtop(&iob->sc_stat[0]);
|
|
iob->sc_ds.msglen = 1;
|
|
iob->sc_ds.msgbuf = (char *) kvtop(&iob->sc_msg[0]);
|
|
iob->sc_msg[1] = -1;
|
|
iob->sc_ds.msginlen = 1;
|
|
iob->sc_ds.extmsglen = 1;
|
|
iob->sc_ds.synmsglen = 3;
|
|
iob->sc_ds.msginbuf = (char *) kvtop(&iob->sc_msg[1]);
|
|
iob->sc_ds.extmsgbuf = (char *) kvtop(&iob->sc_msg[2]);
|
|
iob->sc_ds.synmsgbuf = (char *) kvtop(&iob->sc_msg[3]);
|
|
bzero(&iob->sc_ds.chain, sizeof (iob->sc_ds.chain));
|
|
|
|
if (dev->sc_sync[target].state == SYNC_START) {
|
|
if (siop_inhibit_sync[target]) {
|
|
dev->sc_sync[target].state = SYNC_DONE;
|
|
dev->sc_sync[target].offset = 0;
|
|
dev->sc_sync[target].period = 0;
|
|
#ifdef DEBUG
|
|
if (siopsync_debug)
|
|
printf ("Forcing target %d asynchronous\n", target);
|
|
#endif
|
|
}
|
|
else {
|
|
iob->sc_msg[2] = -1;
|
|
iob->sc_msgout[1] = MSG_EXT_MESSAGE;
|
|
iob->sc_msgout[2] = 3;
|
|
iob->sc_msgout[3] = MSG_SYNC_REQ;
|
|
iob->sc_msgout[4] = siop_sync_period / 4;
|
|
iob->sc_msgout[5] = SIOP_MAX_OFFSET;
|
|
iob->sc_ds.idlen = 6;
|
|
dev->sc_sync[target].state = SYNC_SENT;
|
|
#ifdef DEBUG
|
|
if (siopsync_debug)
|
|
printf ("Sending sync request to target %d\n", target);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
/*
|
|
* If length is > 1 page, check for consecutive physical pages
|
|
* Need to set up chaining if not
|
|
*/
|
|
iob->iob_buf = buf;
|
|
iob->iob_len = len;
|
|
iob->iob_curbuf = iob->iob_curlen = 0;
|
|
nchain = 0;
|
|
count = len;
|
|
addr = buf;
|
|
dmaend = NULL;
|
|
while (count > 0) {
|
|
iob->sc_ds.chain[nchain].databuf = (char *) kvtop (addr);
|
|
if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
|
|
tcount = count;
|
|
iob->sc_ds.chain[nchain].datalen = tcount;
|
|
addr += tcount;
|
|
count -= tcount;
|
|
if (iob->sc_ds.chain[nchain].databuf == dmaend) {
|
|
dmaend += iob->sc_ds.chain[nchain].datalen;
|
|
iob->sc_ds.chain[--nchain].datalen += tcount;
|
|
#ifdef DEBUG
|
|
++siopdma_hits;
|
|
#endif
|
|
}
|
|
else {
|
|
dmaend = iob->sc_ds.chain[nchain].databuf +
|
|
iob->sc_ds.chain[nchain].datalen;
|
|
iob->sc_ds.chain[nchain].datalen = tcount;
|
|
#ifdef DEBUG
|
|
if (nchain) /* Don't count miss on first one */
|
|
++siopdma_misses;
|
|
#endif
|
|
}
|
|
++nchain;
|
|
}
|
|
#ifdef DEBUG
|
|
if (nchain != 1 && len != 0 && siop_debug & 3) {
|
|
printf ("DMA chaining set: %d\n", nchain);
|
|
for (i = 0; i < nchain; ++i) {
|
|
printf (" [%d] %8x %4x\n", i, iob->sc_ds.chain[i].databuf,
|
|
iob->sc_ds.chain[i].datalen);
|
|
}
|
|
}
|
|
if (regs->siop_sbcl & SIOP_BSY) {
|
|
printf ("ACK! siop was busy at start: regs %x script %x dsa %x\n",
|
|
regs, &scripts, &iob->sc_ds);
|
|
/*Debugger();*/
|
|
}
|
|
#endif
|
|
|
|
/* push data case on data the 53c710 needs to access */
|
|
dma_cachectl (dev, sizeof (struct siop_softc));
|
|
dma_cachectl (cbuf, clen);
|
|
if (buf != NULL && len != 0)
|
|
dma_cachectl (buf, len);
|
|
if (dev->sc_active <= 1) {
|
|
regs->siop_sbcl = dev->sc_sync[target].offset;
|
|
regs->siop_dsa = kvtop(&iob->sc_ds);
|
|
/* XXX if disconnected devices pending, this may not work */
|
|
regs->siop_dsp = dev->sc_scriptspa;
|
|
} else {
|
|
regs->siop_istat = SIOP_ISTAT_SIGP;
|
|
}
|
|
#ifdef DEBUG
|
|
++siopstarts;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
* Process a DMA or SCSI interrupt from the 53C710 SIOP
|
|
*/
|
|
|
|
int
|
|
siop_checkintr(dev, istat, dstat, sstat0, status)
|
|
struct siop_softc *dev;
|
|
u_char istat;
|
|
u_char dstat;
|
|
u_char sstat0;
|
|
int *status;
|
|
{
|
|
siop_regmap_p regs = dev->sc_siopp;
|
|
struct siop_iob *iob = dev->sc_cur;
|
|
int target;
|
|
int dfifo, dbc, sstat1;
|
|
|
|
dfifo = regs->siop_dfifo;
|
|
dbc = regs->siop_dbc0;
|
|
sstat1 = regs->siop_sstat1;
|
|
regs->siop_ctest8 |= SIOP_CTEST8_CLF;
|
|
while ((regs->siop_ctest1 & SIOP_CTEST1_FMT) == 0)
|
|
;
|
|
regs->siop_ctest8 &= ~SIOP_CTEST8_CLF;
|
|
#ifdef DEBUG
|
|
++siopints;
|
|
if (siop_debug & 0x100) {
|
|
DCIAS(&iob->sc_stat[0]); /* XXX */
|
|
printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
|
|
istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
|
|
printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
|
|
iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
|
|
iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
|
|
}
|
|
#endif
|
|
if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff00) {
|
|
/* Normal completion status, or check condition */
|
|
if (regs->siop_dsa != kvtop(&iob->sc_ds)) {
|
|
printf ("siop: invalid dsa: %x %x\n", regs->siop_dsa,
|
|
kvtop(&iob->sc_ds));
|
|
panic("*** siop DSA invalid ***");
|
|
}
|
|
target = dev->sc_slave;
|
|
if (dev->sc_sync[target].state == SYNC_SENT) {
|
|
#ifdef DEBUG
|
|
if (siopsync_debug)
|
|
printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
|
|
iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
|
|
iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
|
|
#endif
|
|
if (iob->sc_msg[1] == 0xff)
|
|
printf ("%s: target %d ignored sync request\n",
|
|
dev->sc_dev.dv_xname, target);
|
|
else if (iob->sc_msg[1] == MSG_REJECT)
|
|
printf ("%s: target %d rejected sync request\n",
|
|
dev->sc_dev.dv_xname, target);
|
|
dev->sc_sync[target].state = SYNC_DONE;
|
|
dev->sc_sync[target].period = 0;
|
|
dev->sc_sync[target].offset = 0;
|
|
if (iob->sc_msg[2] == 3 &&
|
|
iob->sc_msg[3] == MSG_SYNC_REQ &&
|
|
iob->sc_msg[5] != 0) {
|
|
if (iob->sc_msg[4] && iob->sc_msg[4] < 100 / 4) {
|
|
#ifdef DEBUG
|
|
printf ("%d: target %d wanted %dns period\n",
|
|
dev->sc_dev.dv_xname, target,
|
|
iob->sc_msg[4] * 4);
|
|
#endif
|
|
/*
|
|
* Kludge for Maxtor XT8580S
|
|
* It accepts whatever we request, even
|
|
* though it won't work. So we ask for
|
|
* a short period than we can handle. If
|
|
* the device says it can do it, use 208ns.
|
|
* If the device says it can do less than
|
|
* 100ns, then we limit it to 100ns.
|
|
*/
|
|
if (iob->sc_msg[4] == siop_sync_period / 4)
|
|
iob->sc_msg[4] = 208 / 4;
|
|
else
|
|
iob->sc_msg[4] = 100 / 4;
|
|
}
|
|
printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
|
|
dev->sc_dev.dv_xname, target,
|
|
iob->sc_msg[4] * 4, iob->sc_msg[5]);
|
|
scsi_period_to_siop (dev, target);
|
|
}
|
|
}
|
|
#if 0
|
|
DCIAS(dev->sc_statuspa); /* XXX */
|
|
#else
|
|
dma_cachectl(&iob->sc_stat[0], 1);
|
|
#endif
|
|
*status = iob->sc_stat[0];
|
|
#ifdef DEBUG
|
|
if (regs->siop_sbcl & SIOP_BSY) {
|
|
/*printf ("ACK! siop was busy at end: regs %x script %x dsa %x\n",
|
|
regs, &scripts, &iob->sc_ds);*/
|
|
/*Debugger();*/
|
|
}
|
|
#endif
|
|
if (dev->sc_active > 1)
|
|
regs->siop_dcntl |= SIOP_DCNTL_STD;
|
|
return 1;
|
|
}
|
|
if (sstat0 & SIOP_SSTAT0_M_A) { /* Phase mismatch */
|
|
#ifdef DEBUG
|
|
++siopphmm;
|
|
if (iob->iob_len) {
|
|
int adjust;
|
|
adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
|
|
if (sstat1 & SIOP_SSTAT1_ORF)
|
|
++adjust;
|
|
if (sstat1 & SIOP_SSTAT1_OLF)
|
|
++adjust;
|
|
iob->iob_curlen = *((long *)®s->siop_dcmd) & 0xffffff;
|
|
iob->iob_curlen += adjust;
|
|
iob->iob_curbuf = *((long *)®s->siop_dnad);
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100)
|
|
printf ("Phase mismatch: dnad %x dbc %x dfifo %x dbc %x sstat1 %x adjust %x sbcl %x\n",
|
|
iob->iob_curbuf, iob->iob_curlen, dfifo, dbc, sstat1, adjust, regs->siop_sbcl);
|
|
#endif
|
|
}
|
|
if (siop_debug & 9)
|
|
printf ("Phase mismatch: %x dsp +%x dcmd %x\n",
|
|
regs->siop_sbcl,
|
|
regs->siop_dsp - dev->sc_scriptspa,
|
|
*((long *)®s->siop_dcmd));
|
|
if (siop_debug & 0x10)
|
|
panic ("53c710 phase mismatch");
|
|
#endif
|
|
if ((regs->siop_sbcl & SIOP_REQ) == 0)
|
|
printf ("Phase mismatch: REQ not asserted! %02x\n",
|
|
regs->siop_sbcl);
|
|
switch (regs->siop_sbcl & 7) {
|
|
/*
|
|
* For data out and data in phase, check for DMA chaining
|
|
*/
|
|
case 0: /* data out */
|
|
case 1: /* data in */
|
|
case 2: /* status */
|
|
case 3: /* command */
|
|
case 6: /* message in */
|
|
case 7: /* message out */
|
|
regs->siop_dsp = dev->sc_scriptspa + Ent_switch;
|
|
break;
|
|
default:
|
|
goto bad_phase;
|
|
}
|
|
return 0;
|
|
}
|
|
if (sstat0 & SIOP_SSTAT0_STO) { /* Select timed out */
|
|
#ifdef DEBUG
|
|
if (regs->siop_sbcl & SIOP_BSY) {
|
|
printf ("ACK! siop was busy at timeout: regs %x script %x dsa %x\n",
|
|
regs, &scripts, &iob->sc_ds);
|
|
printf(" sbcl %x sdid %x istat %x dstat %x sstat0 %x\n",
|
|
regs->siop_sbcl, regs->siop_sdid, istat, dstat, sstat0);
|
|
if (!(regs->siop_sbcl & SIOP_BSY)) {
|
|
printf ("Yikes, it's not busy now!\n");
|
|
#if 0
|
|
*status = -1;
|
|
if (dev->sc_active > 1)
|
|
regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
|
|
return 1;
|
|
#endif
|
|
}
|
|
/* regs->siop_dcntl |= SIOP_DCNTL_STD;*/
|
|
return (0);
|
|
Debugger();
|
|
}
|
|
#endif
|
|
*status = -1;
|
|
if (dev->sc_active > 1)
|
|
regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
|
|
return 1;
|
|
}
|
|
target = dev->sc_slave;
|
|
if (sstat0 & SIOP_SSTAT0_UDC) {
|
|
#ifdef DEBUG
|
|
printf ("%s: target %d disconnected unexpectedly\n",
|
|
dev->sc_dev.dv_xname, target);
|
|
#endif
|
|
#if 0
|
|
siopabort (dev, regs, "siopchkintr");
|
|
#endif
|
|
*status = STS_BUSY;
|
|
if (dev->sc_active > 1)
|
|
regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
|
|
return 1;
|
|
}
|
|
if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff0a) {
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100)
|
|
printf ("%s: ID %x disconnected TEMP %x (+%d) buf %x len %x buf %x len %x dfifo %x dbc %x sstat1 %x\n",
|
|
dev->sc_dev.dv_xname, 1 << target, regs->siop_temp,
|
|
regs->siop_temp - dev->sc_scriptspa,
|
|
iob->iob_curbuf, iob->iob_curlen,
|
|
iob->sc_ds.chain[0].databuf, iob->sc_ds.chain[0].datalen, dfifo, dbc, sstat1);
|
|
#endif
|
|
/*
|
|
* HACK!
|
|
* set current entry in disconnect state
|
|
* clear current
|
|
* if another iob available and another request pending,
|
|
* start another
|
|
*/
|
|
iob->sc_status = dev->sc_flags & (SIOP_SELECTED|SIOP_DMA);
|
|
dev->sc_flags &= ~(SIOP_SELECTED|SIOP_DMA);
|
|
dev->sc_cur = NULL; /* no current device */
|
|
dev->sc_xs = NULL;
|
|
/* continue script to wait for reconnect */
|
|
regs->siop_dcntl |= SIOP_DCNTL_STD;
|
|
if (dev->sc_active < 2) {
|
|
struct siop_pending *pendp;
|
|
int s = splbio();
|
|
/*
|
|
* can start another I/O, see if there are
|
|
* any pending and start them
|
|
*/
|
|
if (pendp = dev->sc_xslist.tqh_first) {
|
|
TAILQ_REMOVE(&dev->sc_xslist, pendp, link);
|
|
dev->sc_xs = pendp->xs;
|
|
pendp->xs = NULL;
|
|
splx(s);
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100)
|
|
printf ("starting a pending command %x\n", dev->sc_xs);
|
|
#endif
|
|
siop_donextcmd(dev);
|
|
}
|
|
splx(s);
|
|
}
|
|
return (0);
|
|
}
|
|
if (dstat & SIOP_DSTAT_SIR && (regs->siop_dsps == 0xff09 ||
|
|
regs->siop_dsps == 0xff06)) {
|
|
int i;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100)
|
|
printf ("%s: target reselected %x %x\n",
|
|
dev->sc_dev.dv_xname, regs->siop_lcrc,
|
|
regs->siop_dsps);
|
|
#endif
|
|
if (dev->sc_cur) {
|
|
printf ("siop: oops - reconnect before current done\n");
|
|
/* panic ("siop: what now?");*/
|
|
}
|
|
/*
|
|
* locate iob of reconnecting device
|
|
* set dev->sc_cur to iob
|
|
*/
|
|
for (i = 0, iob = NULL; i < 2; ++i) {
|
|
if (dev->sc_iob[i].sc_xs == NULL)
|
|
continue;
|
|
if (!dev->sc_iob[i].sc_status)
|
|
continue;
|
|
if (!(regs->siop_lcrc & (dev->sc_iob[i].sc_ds.scsi_addr >> 16)))
|
|
continue;
|
|
iob = &dev->sc_iob[i];
|
|
dev->sc_cur = iob;
|
|
dev->sc_xs = iob->sc_xs;
|
|
dev->sc_flags |= iob->sc_status;
|
|
iob->sc_status = 0;
|
|
DCIAS(kvtop(&iob->sc_stat[0]));
|
|
regs->siop_dsa = kvtop(&iob->sc_ds);
|
|
if (iob->iob_curlen) {
|
|
if (iob->iob_curbuf <= (u_long) iob->sc_ds.chain[0].databuf ||
|
|
iob->iob_curbuf >= (u_long)(iob->sc_ds.chain[0].databuf + iob->sc_ds.chain[0].datalen))
|
|
printf ("%s: saved data pointer not in chain[0]\n");
|
|
iob->sc_ds.chain[0].databuf = (char *) iob->iob_curbuf;
|
|
iob->sc_ds.chain[0].datalen = iob->iob_curlen;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100)
|
|
printf ("%s: reselect buf %x len %x\n",
|
|
dev->sc_dev.dv_xname, iob->iob_curbuf,
|
|
iob->iob_curlen);
|
|
#endif
|
|
DCIAS(kvtop(&iob->sc_ds.chain));
|
|
}
|
|
}
|
|
if (iob == NULL)
|
|
panic("unable to find reconnecting device");
|
|
regs->siop_dcntl |= SIOP_DCNTL_STD;
|
|
return (0);
|
|
}
|
|
if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff07) {
|
|
/* reselect was interrupted */
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x100 &&
|
|
(regs->siop_sfbr & SIOP_CTEST2_SIGP) == 0)
|
|
printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x\n",
|
|
dev->sc_dev.dv_xname, regs->siop_scntl1, regs->siop_ctest2, regs->siop_sfbr);
|
|
#endif
|
|
target = dev->sc_xs->sc_link->target;
|
|
regs->siop_dsa = kvtop(&dev->sc_cur->sc_ds);
|
|
regs->siop_sbcl = dev->sc_sync[target].offset;
|
|
regs->siop_dcntl |= SIOP_DCNTL_STD;
|
|
return (0);
|
|
}
|
|
if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
|
|
#if 0
|
|
DCIAS(dev->sc_statuspa);
|
|
#else
|
|
dma_cachectl (&iob->sc_stat[0], 1);
|
|
#endif
|
|
printf ("SIOP interrupt: %x sts %x msg %x sbcl %x\n",
|
|
regs->siop_dsps, iob->sc_stat[0], iob->sc_msg[0],
|
|
regs->siop_sbcl);
|
|
siopreset (dev);
|
|
*status = -1;
|
|
return 1;
|
|
}
|
|
if (sstat0 & SIOP_SSTAT0_SGE)
|
|
printf ("SIOP: SCSI Gross Error\n");
|
|
if (sstat0 & SIOP_SSTAT0_PAR)
|
|
printf ("SIOP: Parity Error\n");
|
|
if (dstat & SIOP_DSTAT_IID)
|
|
printf ("SIOP: Invalid instruction detected\n");
|
|
bad_phase:
|
|
/*
|
|
* temporary panic for unhandled conditions
|
|
* displays various things about the 53C710 status and registers
|
|
* then panics.
|
|
* XXXX need to clean this up to print out the info, reset, and continue
|
|
*/
|
|
printf ("siopchkintr: target %x ds %x\n", target, &iob->sc_ds);
|
|
printf ("scripts %x ds %x regs %x dsp %x dcmd %x\n", dev->sc_scriptspa,
|
|
kvtop(&dev->sc_iob), kvtop(regs), regs->siop_dsp,
|
|
*((long *)®s->siop_dcmd));
|
|
printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x\n",
|
|
istat, dstat, sstat0, regs->siop_dsps, regs->siop_dsa,
|
|
regs->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
|
|
#ifdef DEBUG
|
|
if (siop_debug & 0x20)
|
|
panic("siopchkintr: **** temp ****");
|
|
#endif
|
|
siopreset (dev); /* hard reset */
|
|
*status = -1;
|
|
return 1;
|
|
}
|
|
|
|
/*
|
|
* SCSI 'immediate' command: issue a command to some SCSI device
|
|
* and get back an 'immediate' response (i.e., do programmed xfer
|
|
* to get the response data). 'cbuf' is a buffer containing a scsi
|
|
* command of length clen bytes. 'buf' is a buffer of length 'len'
|
|
* bytes for data. The transfer direction is determined by the device
|
|
* (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
|
|
* command must supply no data. 'xferphase' is the bus phase the
|
|
* caller expects to happen after the command is issued. It should
|
|
* be one of DATA_IN_PHASE, DATA_OUT_PHASE or STATUS_PHASE.
|
|
*
|
|
* XXX - 53C710 will use DMA, but no interrupts (it's a heck of a
|
|
* lot easier to do than to use programmed I/O).
|
|
*
|
|
*/
|
|
int
|
|
siopicmd(dev, target, lun, cbuf, clen, buf, len)
|
|
struct siop_softc *dev;
|
|
int target;
|
|
int lun;
|
|
void *cbuf;
|
|
int clen;
|
|
void *buf;
|
|
int len;
|
|
{
|
|
siop_regmap_p regs = dev->sc_siopp;
|
|
struct siop_iob *iob = dev->sc_cur;
|
|
int i;
|
|
int status;
|
|
u_char istat;
|
|
u_char dstat;
|
|
u_char sstat0;
|
|
|
|
if (dev->sc_flags & SIOP_SELECTED) {
|
|
printf ("siopicmd%d: bus busy\n", target);
|
|
return -1;
|
|
}
|
|
regs->siop_sien = 0x00; /* disable SCSI and DMA interrupts */
|
|
regs->siop_dien = 0x00;
|
|
dev->sc_flags |= SIOP_SELECTED;
|
|
dev->sc_slave = target;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 1)
|
|
printf ("siopicmd: target %x/%x cmd %02x ds %x\n", target,
|
|
lun, *((char *)cbuf), &iob->sc_ds);
|
|
#endif
|
|
siop_setup (dev, target, lun, cbuf, clen, buf, len);
|
|
|
|
for (;;) {
|
|
/* use cmd_wait values? */
|
|
i = siop_cmd_wait << 1;
|
|
while (((istat = regs->siop_istat) &
|
|
(SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
|
|
if (--i <= 0) {
|
|
printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x\n",
|
|
target, *((char *)cbuf),
|
|
regs->siop_sbcl, regs->siop_dsp,
|
|
regs->siop_dsp - dev->sc_scriptspa,
|
|
*((long *)®s->siop_dcmd), &iob->sc_ds);
|
|
i = siop_cmd_wait << 2;
|
|
/* XXXX need an upper limit and reset */
|
|
}
|
|
delay(10);
|
|
}
|
|
dstat = regs->siop_dstat;
|
|
sstat0 = regs->siop_sstat0;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 1) {
|
|
DCIAS(kvtop(iob->sc_stat[0])); /* XXX should just invalidate dev->sc_stat */
|
|
printf ("siopicmd: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
|
|
istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl,
|
|
iob->sc_stat[0], iob->sc_msg[0]);
|
|
}
|
|
#endif
|
|
if (siop_checkintr(dev, istat, dstat, sstat0, &status)) {
|
|
dev->sc_flags &= ~SIOP_SELECTED;
|
|
return (status);
|
|
}
|
|
}
|
|
}
|
|
|
|
int
|
|
siopgo(dev, xs)
|
|
struct siop_softc *dev;
|
|
struct scsi_xfer *xs;
|
|
{
|
|
siop_regmap_p regs;
|
|
int i;
|
|
int nchain;
|
|
int count, tcount;
|
|
char *addr, *dmaend;
|
|
|
|
#ifdef DEBUG
|
|
if (siop_debug & 1)
|
|
printf ("%s: go ", dev->sc_dev.dv_xname);
|
|
#if 0
|
|
if ((cdb->cdb[1] & 1) == 0 &&
|
|
((cdb->cdb[0] == CMD_WRITE && cdb->cdb[2] == 0 && cdb->cdb[3] == 0) ||
|
|
(cdb->cdb[0] == CMD_WRITE_EXT && cdb->cdb[2] == 0 && cdb->cdb[3] == 0
|
|
&& cdb->cdb[4] == 0)))
|
|
panic ("siopgo: attempted write to block < 0x100");
|
|
#endif
|
|
#endif
|
|
#if 0
|
|
cdb->cdb[1] |= unit << 5;
|
|
#endif
|
|
|
|
if (dev->sc_flags & SIOP_SELECTED) {
|
|
printf ("%s: bus busy\n", dev->sc_dev.dv_xname);
|
|
return 1;
|
|
}
|
|
|
|
dev->sc_flags |= SIOP_SELECTED | SIOP_DMA;
|
|
dev->sc_slave = xs->sc_link->target;
|
|
regs = dev->sc_siopp;
|
|
/* enable SCSI and DMA interrupts */
|
|
regs->siop_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE |
|
|
SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
|
|
regs->siop_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
|
|
/*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 1)
|
|
printf ("siopgo: target %x cmd %02x ds %x\n", dev->sc_slave, xs->cmd->opcode, &dev->sc_cur->sc_ds);
|
|
#endif
|
|
|
|
siop_setup(dev, dev->sc_slave, xs->sc_link->lun, xs->cmd, xs->cmdlen, xs->data, xs->datalen);
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Check for 53C710 interrupts
|
|
*/
|
|
|
|
int
|
|
siopintr (dev)
|
|
register struct siop_softc *dev;
|
|
{
|
|
siop_regmap_p regs;
|
|
register u_char istat, dstat, sstat0;
|
|
int unit;
|
|
int status;
|
|
int found = 0;
|
|
|
|
regs = dev->sc_siopp;
|
|
istat = dev->sc_istat;
|
|
if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
|
|
return;
|
|
if ((dev->sc_flags & (SIOP_DMA | SIOP_SELECTED)) == SIOP_SELECTED)
|
|
return; /* doing non-interrupt I/O */
|
|
/* Got a valid interrupt on this device */
|
|
dstat = dev->sc_dstat;
|
|
sstat0 = dev->sc_sstat0;
|
|
dev->sc_istat = 0;
|
|
#ifdef DEBUG
|
|
if (siop_debug & 1)
|
|
printf ("%s: intr istat %x dstat %x sstat0 %x\n",
|
|
dev->sc_dev.dv_xname, istat, dstat, sstat0);
|
|
if (!dev->sc_active) {
|
|
printf ("%s: spurious interrupt? istat %x dstat %x sstat0 %x status %x\n",
|
|
dev->sc_dev.dv_xname, istat, dstat, sstat0, dev->sc_cur->sc_stat[0]);
|
|
}
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
if (siop_debug & 5) {
|
|
DCIAS(kvtop(&dev->sc_cur->sc_stat[0]));
|
|
printf ("siopintr%d: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
|
|
unit, istat, dstat, sstat0, regs->siop_dsps,
|
|
regs->siop_sbcl, dev->sc_cur->sc_stat[0], dev->sc_cur->sc_msg[0]);
|
|
}
|
|
#endif
|
|
if (siop_checkintr (dev, istat, dstat, sstat0, &status)) {
|
|
#if 1
|
|
if (dev->sc_active <= 1) { /* more HACK */
|
|
regs->siop_sien = 0;
|
|
regs->siop_dien = 0;
|
|
}
|
|
if (status == 0xff)
|
|
printf ("siopintr: status == 0xff\n");
|
|
#endif
|
|
if (dev->sc_flags & SIOP_DMA) {
|
|
dev->sc_flags &= ~(SIOP_DMA | SIOP_SELECTED);
|
|
if (regs->siop_sbcl & SIOP_BSY)
|
|
printf ("siopintr: SCSI bus busy at I/O completion\n");
|
|
siop_scsidone(dev, dev->sc_cur->sc_stat[0]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This is based on the Progressive Peripherals Zeus driver and may
|
|
* not be correct for other 53c710 boards.
|
|
*
|
|
*/
|
|
scsi_period_to_siop (dev, target)
|
|
struct siop_softc *dev;
|
|
{
|
|
int period, offset, i, sxfer;
|
|
|
|
period = dev->sc_cur->sc_msg[4];
|
|
offset = dev->sc_cur->sc_msg[5];
|
|
sxfer = 0;
|
|
if (offset <= SIOP_MAX_OFFSET)
|
|
sxfer = offset;
|
|
for (i = 0; i < sizeof (xxx) / 2; ++i) {
|
|
if (period <= xxx[i].x) {
|
|
sxfer |= xxx[i].y & 0x70;
|
|
offset = xxx[i].y & 0x03;
|
|
break;
|
|
}
|
|
}
|
|
dev->sc_sync[target].period = sxfer;
|
|
dev->sc_sync[target].offset = offset;
|
|
#ifdef DEBUG
|
|
printf ("sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, offset);
|
|
#endif
|
|
}
|