1996-10-23 03:15:10 +04:00
|
|
|
/* $NetBSD: sii.c,v 1.20 1996/10/22 23:15:10 mhitch Exp $ */
|
1994-10-27 00:08:38 +03:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*-
|
1994-05-27 12:39:00 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-10-12 06:22:19 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-10-27 00:08:38 +03:00
|
|
|
* @(#)sii.c 8.2 (Berkeley) 11/30/93
|
1993-10-12 06:22:19 +03:00
|
|
|
*
|
1994-05-27 12:39:00 +04:00
|
|
|
* from: Header: /sprite/src/kernel/dev/ds3100.md/RCS/devSII.c,
|
1993-10-12 06:22:19 +03:00
|
|
|
* v 9.2 89/09/14 13:37:41 jhh Exp $ SPRITE (DECWRL)";
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sii.h"
|
|
|
|
#if NSII > 0
|
|
|
|
/*
|
|
|
|
* SCSI interface driver
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/errno.h>
|
1995-08-10 08:21:35 +04:00
|
|
|
#include <sys/device.h>
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
#ifdef notyet
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
1996-10-13 17:13:50 +04:00
|
|
|
|
|
|
|
/* old 4.4bsd/pmax scsi drivers */
|
1993-10-12 06:22:19 +03:00
|
|
|
#include <pmax/dev/device.h>
|
|
|
|
#include <pmax/dev/scsi.h>
|
|
|
|
#include <pmax/dev/siireg.h>
|
1996-10-13 07:02:39 +04:00
|
|
|
#include <pmax/dev/siivar.h>
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
/* Machine-indepedent back-end attach entry point */
|
|
|
|
void siiattach __P((struct siisoftc *sc));
|
1995-09-11 12:29:11 +04:00
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
/*
|
1996-10-13 07:02:39 +04:00
|
|
|
* Autoconfig definition of driver front-end
|
1995-08-10 08:21:35 +04:00
|
|
|
*/
|
1996-10-13 17:13:50 +04:00
|
|
|
#include <machine/machConst.h>
|
1996-10-13 07:02:39 +04:00
|
|
|
int old_siimatch __P((struct device * parent, void *cfdata, void *aux));
|
|
|
|
void old_siiattach __P((struct device *parent, struct device *self, void *aux));
|
1996-03-17 04:38:52 +03:00
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
extern struct cfattach sii_ca;
|
1996-03-17 04:38:52 +03:00
|
|
|
struct cfattach sii_ca = {
|
1996-10-13 07:02:39 +04:00
|
|
|
sizeof(struct siisoftc), old_siimatch, old_siiattach
|
1996-03-17 04:38:52 +03:00
|
|
|
};
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
extern struct cfdriver sii_cd;
|
1996-03-17 04:38:52 +03:00
|
|
|
struct cfdriver sii_cd = {
|
|
|
|
NULL, "sii", DV_DULL
|
1995-08-10 08:21:35 +04:00
|
|
|
};
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
int siiprint(void*, char*);
|
|
|
|
int siiintr __P((void *sc));
|
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
#ifdef USE_NEW_SCSI
|
|
|
|
/* Glue to the machine-independent scsi */
|
|
|
|
struct scsi_adapter asc_switch = {
|
|
|
|
NULL, /* XXX - asc_scsi_cmd */
|
|
|
|
#if 0
|
|
|
|
/*XXX*/ minphys, /* no max transfer size; DMA engine deals */
|
|
|
|
#else
|
|
|
|
SII_MAX_DMA_XFER_LENGTH,
|
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1995-09-13 23:35:53 +04:00
|
|
|
struct scsi_device sii_dev = {
|
1995-08-10 08:21:35 +04:00
|
|
|
/*XXX*/ NULL, /* Use default error handler */
|
|
|
|
/*XXX*/ NULL, /* have a queue, served by this */
|
|
|
|
/*XXX*/ NULL, /* have no async handler */
|
|
|
|
/*XXX*/ NULL, /* Use default 'done' routine */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1996-04-12 22:15:23 +04:00
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
/*
|
1993-10-12 06:22:19 +03:00
|
|
|
* MACROS for timing out spin loops.
|
|
|
|
*
|
|
|
|
* Wait until expression is true.
|
|
|
|
*
|
|
|
|
* Control register bits can change at any time so when the CPU
|
|
|
|
* reads a register, the bits might change and
|
|
|
|
* invalidate the setup and hold times for the CPU.
|
|
|
|
* This macro reads the register twice to be sure the value is stable.
|
|
|
|
*
|
|
|
|
* args: var - variable to save control register contents
|
|
|
|
* reg - control register to read
|
|
|
|
* expr - expression to spin on
|
|
|
|
* spincount - maximum number of times through the loop
|
|
|
|
* cntr - variable for number of tries
|
|
|
|
*/
|
|
|
|
#define SII_WAIT_UNTIL(var, reg, expr, spincount, cntr) { \
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int tmp = reg; \
|
1993-10-12 06:22:19 +03:00
|
|
|
for (cntr = 0; cntr < spincount; cntr++) { \
|
|
|
|
while (tmp != (var = reg)) \
|
|
|
|
tmp = var; \
|
|
|
|
if (expr) \
|
|
|
|
break; \
|
|
|
|
if (cntr >= 100) \
|
|
|
|
DELAY(100); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
int sii_debug = 1;
|
|
|
|
int sii_debug_cmd;
|
|
|
|
int sii_debug_bn;
|
|
|
|
int sii_debug_sz;
|
|
|
|
#define NLOG 16
|
|
|
|
struct sii_log {
|
|
|
|
u_short cstat;
|
|
|
|
u_short dstat;
|
|
|
|
u_short comm;
|
|
|
|
u_short msg;
|
1994-05-27 12:57:32 +04:00
|
|
|
int rlen;
|
|
|
|
int dlen;
|
1993-10-12 06:22:19 +03:00
|
|
|
int target;
|
|
|
|
} sii_log[NLOG], *sii_logp = sii_log;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
u_char sii_buf[256]; /* used for extended messages */
|
|
|
|
|
|
|
|
#define NORESET 0
|
|
|
|
#define RESET 1
|
|
|
|
#define NOWAIT 0
|
|
|
|
#define WAIT 1
|
|
|
|
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
/*
|
|
|
|
* Define a safe address in the SCSI buffer for doing status & message DMA
|
|
|
|
* XXX why not add another field to softc?
|
|
|
|
*/
|
|
|
|
#define SII_BUF_ADDR(sc) ((sc)->sc_buf + SII_MAX_DMA_XFER_LENGTH * 14)
|
1996-04-12 22:15:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Other forward references
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void sii_Reset __P((register struct siisoftc *sc, int resetbus));
|
|
|
|
static void sii_StartCmd __P((register struct siisoftc *sc, int target));
|
|
|
|
static void sii_CmdDone __P((register struct siisoftc *sc, int target,
|
|
|
|
int error));
|
|
|
|
static void sii_DoIntr __P((register struct siisoftc *sc, u_int dstat));
|
|
|
|
static void sii_StateChg __P((register struct siisoftc *sc, u_int cstat));
|
|
|
|
static int sii_GetByte __P((register SIIRegs *regs, int phase, int ack));
|
|
|
|
static void sii_DoSync __P((register SIIRegs *regs, register State *state));
|
|
|
|
static void sii_StartDMA __P((register SIIRegs *regs, int phase,
|
|
|
|
u_short *dmaAddr, int size));
|
|
|
|
|
|
|
|
void siistart __P((register ScsiCmd *scsicmd));
|
|
|
|
void sii_DumpLog __P((void));
|
|
|
|
|
|
|
|
void CopyToBuffer __P((u_short *src, /* NOTE: must be short aligned */
|
|
|
|
volatile u_short *dst, int length));
|
|
|
|
void CopyFromBuffer __P((volatile u_short *src, char *dst, int length));
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-09-21 12:47:17 +04:00
|
|
|
/*
|
|
|
|
* Definition of the controller for the old-style, non-MI
|
|
|
|
* pmax scsi drivers, and for autoconfiguring devices via those
|
|
|
|
* drivers.
|
|
|
|
*/
|
|
|
|
struct pmax_driver siidriver = {
|
|
|
|
"sii", NULL, siistart, 0,
|
|
|
|
};
|
1995-08-10 08:21:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Match driver based on name
|
|
|
|
*/
|
|
|
|
int
|
1996-10-13 07:02:39 +04:00
|
|
|
old_siimatch(parent, match, aux)
|
1995-08-10 08:21:35 +04:00
|
|
|
struct device *parent;
|
|
|
|
void *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
|
1996-01-30 01:52:15 +03:00
|
|
|
if (strcmp(ca->ca_name, "sii") != 0 &&
|
|
|
|
strncmp(ca->ca_name, "PMAZ-AA ", 8) != 0) /*XXX*/
|
1995-08-10 08:21:35 +04:00
|
|
|
return (0);
|
|
|
|
|
1995-09-11 12:29:11 +04:00
|
|
|
/* XXX check for bad address */
|
1996-01-30 01:52:15 +03:00
|
|
|
/*
|
1996-04-12 22:15:23 +04:00
|
|
|
* XXX KN01s (3100/2100) have exactly one SII.
|
|
|
|
* the Decsystem 5100 apparently uses them also, but as yet we
|
|
|
|
* don't know at what address.
|
|
|
|
*
|
1996-01-30 01:52:15 +03:00
|
|
|
* XXX PVAXES apparently use the SII also.
|
|
|
|
*/
|
1995-08-10 08:21:35 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1996-10-13 07:02:39 +04:00
|
|
|
old_siiattach(parent, self, aux)
|
1995-08-10 08:21:35 +04:00
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
register struct confargs *ca = aux;
|
1995-09-11 12:29:11 +04:00
|
|
|
register struct siisoftc *sc = (struct siisoftc *) self;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
sc->sc_regs = (SIIRegs *)MACH_PHYS_TO_UNCACHED(ca->ca_addr);
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_flags = sc->sc_dev.dv_cfdata->cf_flags;
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
siiattach(sc);
|
|
|
|
|
|
|
|
/* tie pseudo-slot to device */
|
|
|
|
BUS_INTR_ESTABLISH(ca, siiintr, sc);
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("\n");
|
1996-10-13 07:02:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siiattach(sc)
|
|
|
|
register struct siisoftc *sc;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
1996-10-23 03:15:10 +04:00
|
|
|
sc->sc_target = -1; /* no command active */
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Give each target its own DMA buffer region.
|
|
|
|
* Make it big enough for 2 max transfers so we can ping pong buffers
|
|
|
|
* while we copy the data.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < SII_NCMD; i++) {
|
|
|
|
sc->sc_st[i].dmaAddr[0] = (u_short *)
|
1996-10-13 07:02:39 +04:00
|
|
|
sc->sc_buf + 2 * SII_MAX_DMA_XFER_LENGTH * i;
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_st[i].dmaAddr[1] = sc->sc_st[i].dmaAddr[0] +
|
|
|
|
SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
}
|
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
/* Hack for old-sytle SCSI-device probe */
|
1995-09-11 12:29:11 +04:00
|
|
|
(void) pmax_add_scsi(&siidriver, sc->sc_dev.dv_unit);
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1995-09-11 12:29:11 +04:00
|
|
|
sii_Reset(sc, RESET);
|
1996-10-13 07:02:39 +04:00
|
|
|
#ifdef USE_NEW_SCSI
|
|
|
|
/* XXX probe SCSI bus and attach slave devices */
|
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Start activity on a SCSI device.
|
|
|
|
* We maintain information on each device separately since devices can
|
|
|
|
* connect/disconnect during an operation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
siistart(scsicmd)
|
|
|
|
register ScsiCmd *scsicmd; /* command to start */
|
|
|
|
{
|
1995-09-13 23:35:53 +04:00
|
|
|
register struct pmax_scsi_device *sdp = scsicmd->sd;
|
1996-03-17 04:38:52 +03:00
|
|
|
register struct siisoftc *sc = sii_cd.cd_devs[sdp->sd_ctlr];
|
1993-10-12 06:22:19 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
/*
|
|
|
|
* Check if another command is already in progress.
|
|
|
|
* We may have to change this if we allow SCSI devices with
|
|
|
|
* separate LUNs.
|
|
|
|
*/
|
|
|
|
if (sc->sc_cmd[sdp->sd_drive]) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %s busy at start\n", sc->sc_dev.dv_xname,
|
1993-10-12 06:22:19 +03:00
|
|
|
sdp->sd_driver->d_name);
|
|
|
|
(*sdp->sd_driver->d_done)(scsicmd->unit, EBUSY,
|
|
|
|
scsicmd->buflen, 0);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
sc->sc_cmd[sdp->sd_drive] = scsicmd;
|
|
|
|
sii_StartCmd(sc, sdp->sd_drive);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if any SII chips have pending interrupts
|
|
|
|
* and process as appropriate.
|
|
|
|
*/
|
1995-09-11 12:29:11 +04:00
|
|
|
int
|
|
|
|
siiintr(xxxsc)
|
|
|
|
void *xxxsc;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
1995-09-11 12:29:11 +04:00
|
|
|
register struct siisoftc *sc = xxxsc;
|
1994-05-27 12:57:32 +04:00
|
|
|
u_int dstat;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find which controller caused the interrupt.
|
|
|
|
*/
|
|
|
|
dstat = sc->sc_regs->dstat;
|
1996-04-12 22:15:23 +04:00
|
|
|
if (dstat & (SII_CI | SII_DI)) {
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DoIntr(sc, dstat);
|
1996-04-12 22:22:35 +04:00
|
|
|
return (0); /* XXX */
|
1996-04-12 22:15:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (1); /* XXX spurious interrupt? */
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the SII chip and do a SCSI reset if 'reset' is true.
|
|
|
|
* NOTE: if !cold && reset, should probably probe for devices
|
|
|
|
* since a SCSI bus reset will set UNIT_ATTENTION.
|
|
|
|
*/
|
|
|
|
static void
|
1995-09-11 12:29:11 +04:00
|
|
|
sii_Reset(sc, reset)
|
|
|
|
register struct siisoftc* sc;
|
1993-10-12 06:22:19 +03:00
|
|
|
int reset; /* TRUE => reset SCSI bus */
|
|
|
|
{
|
1995-09-11 12:29:11 +04:00
|
|
|
register SIIRegs *regs = sc->sc_regs;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 1)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii: RESET\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Reset the SII chip.
|
|
|
|
*/
|
|
|
|
regs->comm = SII_CHRESET;
|
|
|
|
/*
|
|
|
|
* Set arbitrated bus mode.
|
|
|
|
*/
|
|
|
|
regs->csr = SII_HPM;
|
|
|
|
/*
|
|
|
|
* SII is always ID 7.
|
|
|
|
*/
|
|
|
|
regs->id = SII_ID_IO | 7;
|
|
|
|
/*
|
|
|
|
* Enable SII to drive the SCSI bus.
|
|
|
|
*/
|
|
|
|
regs->dictrl = SII_PRE;
|
|
|
|
regs->dmctrl = 0;
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
/*
|
1994-05-27 12:57:32 +04:00
|
|
|
* Assert SCSI bus reset for at least 25 Usec to clear the
|
1993-10-12 06:22:19 +03:00
|
|
|
* world. SII_DO_RST is self clearing.
|
|
|
|
* Delay 250 ms before doing any commands.
|
|
|
|
*/
|
|
|
|
regs->comm = SII_DO_RST;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
DELAY(250000);
|
|
|
|
|
|
|
|
/* rearbitrate synchronous offset */
|
|
|
|
for (i = 0; i < SII_NCMD; i++)
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_st[i].dmaReqAck = 0;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any pending interrupts from the reset.
|
|
|
|
*/
|
|
|
|
regs->cstat = regs->cstat;
|
|
|
|
regs->dstat = regs->dstat;
|
|
|
|
/*
|
|
|
|
* Set up SII for arbitrated bus mode, SCSI parity checking,
|
|
|
|
* Reselect Enable, and Interrupt Enable.
|
|
|
|
*/
|
|
|
|
regs->csr = SII_HPM | SII_RSE | SII_PCE | SII_IE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a SCSI command by sending the cmd data
|
|
|
|
* to a SCSI controller via the SII.
|
|
|
|
* Call the device done proceedure if it can't be started.
|
|
|
|
* NOTE: we should be called with interrupts disabled.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sii_StartCmd(sc, target)
|
|
|
|
register struct siisoftc *sc; /* which SII to use */
|
|
|
|
register int target; /* which command to start */
|
|
|
|
{
|
|
|
|
register SIIRegs *regs;
|
|
|
|
register ScsiCmd *scsicmd;
|
|
|
|
register State *state;
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int status;
|
1993-10-12 06:22:19 +03:00
|
|
|
int error, retval;
|
|
|
|
|
|
|
|
/* if another command is currently in progress, just wait */
|
|
|
|
if (sc->sc_target >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* initialize state information for this command */
|
|
|
|
scsicmd = sc->sc_cmd[target];
|
|
|
|
state = &sc->sc_st[target];
|
|
|
|
state->flags = FIRST_DMA;
|
|
|
|
state->prevComm = 0;
|
|
|
|
state->dmalen = 0;
|
|
|
|
state->dmaCurPhase = -1;
|
|
|
|
state->dmaPrevPhase = -1;
|
|
|
|
state->dmaBufIndex = 0;
|
|
|
|
state->cmd = scsicmd->cmd;
|
|
|
|
state->cmdlen = scsicmd->cmdlen;
|
|
|
|
if ((state->buflen = scsicmd->buflen) == 0) {
|
|
|
|
state->dmaDataPhase = -1; /* illegal phase. shouldn't happen */
|
|
|
|
state->buf = (char *)0;
|
|
|
|
} else {
|
|
|
|
state->dmaDataPhase =
|
|
|
|
(scsicmd->flags & SCSICMD_DATA_TO_DEVICE) ?
|
|
|
|
SII_DATA_OUT_PHASE : SII_DATA_IN_PHASE;
|
|
|
|
state->buf = scsicmd->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 1) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: %s target %d cmd 0x%x addr %p size %d dma %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
scsicmd->sd->sd_driver->d_name, target,
|
|
|
|
scsicmd->cmd[0], scsicmd->buf, scsicmd->buflen,
|
|
|
|
state->dmaDataPhase);
|
|
|
|
}
|
|
|
|
sii_debug_cmd = scsicmd->cmd[0];
|
1994-05-27 12:57:32 +04:00
|
|
|
if (scsicmd->cmd[0] == SCSI_READ_EXT ||
|
|
|
|
scsicmd->cmd[0] == SCSI_WRITE_EXT) {
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_debug_bn = (scsicmd->cmd[2] << 24) |
|
|
|
|
(scsicmd->cmd[3] << 16) |
|
|
|
|
(scsicmd->cmd[4] << 8) |
|
|
|
|
scsicmd->cmd[5];
|
|
|
|
sii_debug_sz = (scsicmd->cmd[7] << 8) | scsicmd->cmd[8];
|
1994-05-27 12:57:32 +04:00
|
|
|
} else {
|
|
|
|
sii_debug_bn = 0;
|
|
|
|
sii_debug_sz = 0;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* try to select the target */
|
|
|
|
regs = sc->sc_regs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Another device may have selected us; in which case,
|
|
|
|
* this command will be restarted later.
|
|
|
|
*/
|
|
|
|
if ((status = regs->dstat) & (SII_CI | SII_DI)) {
|
|
|
|
sii_DoIntr(sc, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_target = target;
|
1994-05-27 12:57:32 +04:00
|
|
|
#if 0
|
|
|
|
/* seem to have problems with synchronous transfers */
|
1993-10-12 06:22:19 +03:00
|
|
|
if (scsicmd->flags & SCSICMD_USE_SYNC) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: doing extended msg\n"); /* XXX */
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Setup to send both the identify message and the synchronous
|
|
|
|
* data transfer request.
|
|
|
|
*/
|
|
|
|
sii_buf[0] = SCSI_DIS_REC_IDENTIFY;
|
|
|
|
sii_buf[1] = SCSI_EXTENDED_MSG;
|
|
|
|
sii_buf[2] = 3; /* message length */
|
|
|
|
sii_buf[3] = SCSI_SYNCHRONOUS_XFER;
|
|
|
|
sii_buf[4] = 0;
|
|
|
|
sii_buf[5] = 3; /* maximum SII chip supports */
|
|
|
|
|
|
|
|
state->dmaCurPhase = SII_MSG_OUT_PHASE,
|
|
|
|
state->dmalen = 6;
|
|
|
|
CopyToBuffer((u_short *)sii_buf,
|
1996-10-13 07:02:39 +04:00
|
|
|
(volatile u_short *)SII_BUF_ADDR(sc), 6);
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->slcsr = target;
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dmctrl = state->dmaReqAck;
|
1996-10-13 07:02:39 +04:00
|
|
|
regs->dmaddrl = (u_short)(SII_BUF_ADDR(sc) >> 1);
|
|
|
|
regs->dmaddrh = (u_short)(SII_BUF_ADDR(sc) >> 17) & 03;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dmlotc = 6;
|
|
|
|
regs->comm = SII_DMA | SII_INXFER | SII_SELECT | SII_ATN |
|
|
|
|
SII_CON | SII_MSG_OUT_PHASE;
|
1994-05-27 12:57:32 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
1993-10-12 06:22:19 +03:00
|
|
|
/* do a chained, select with ATN and programmed I/O command */
|
|
|
|
regs->data = SCSI_DIS_REC_IDENTIFY;
|
|
|
|
regs->slcsr = target;
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dmctrl = state->dmaReqAck;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->comm = SII_INXFER | SII_SELECT | SII_ATN | SII_CON |
|
|
|
|
SII_MSG_OUT_PHASE;
|
|
|
|
}
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for something to happen
|
|
|
|
* (should happen soon or we would use interrupts).
|
|
|
|
*/
|
|
|
|
SII_WAIT_UNTIL(status, regs->cstat, status & (SII_CI | SII_DI),
|
|
|
|
SII_WAIT_COUNT/4, retval);
|
|
|
|
|
|
|
|
/* check to see if we are connected OK */
|
|
|
|
if ((status & (SII_RST | SII_SCH | SII_STATE_MSK)) ==
|
|
|
|
(SII_SCH | SII_CON)) {
|
|
|
|
regs->cstat = status;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
sii_logp->target = target;
|
|
|
|
sii_logp->cstat = status;
|
|
|
|
sii_logp->dstat = 0;
|
|
|
|
sii_logp->comm = regs->comm;
|
|
|
|
sii_logp->msg = -1;
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_logp->rlen = state->buflen;
|
|
|
|
sii_logp->dlen = state->dmalen;
|
1993-10-12 06:22:19 +03:00
|
|
|
if (++sii_logp >= &sii_log[NLOG])
|
|
|
|
sii_logp = sii_log;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* wait a short time for command phase */
|
|
|
|
SII_WAIT_UNTIL(status, regs->dstat, status & SII_MIS,
|
|
|
|
SII_WAIT_COUNT, retval);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 2)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: ds %x cnt %d\n", status, retval);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
if ((status & (SII_CI | SII_MIS | SII_PHASE_MSK)) !=
|
|
|
|
(SII_MIS | SII_CMD_PHASE)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: timeout cs %x ds %x cnt %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->cstat, status, retval); /* XXX */
|
|
|
|
/* process interrupt or continue until it happens */
|
|
|
|
if (status & (SII_CI | SII_DI))
|
|
|
|
sii_DoIntr(sc, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
regs->dstat = SII_DNE; /* clear Msg Out DMA done */
|
|
|
|
|
|
|
|
/* send command data */
|
|
|
|
CopyToBuffer((u_short *)state->cmd,
|
|
|
|
(volatile u_short *)state->dmaAddr[0], state->cmdlen);
|
|
|
|
sii_StartDMA(regs, state->dmaCurPhase = SII_CMD_PHASE,
|
|
|
|
state->dmaAddr[0], state->dmalen = scsicmd->cmdlen);
|
|
|
|
|
|
|
|
/* wait a little while for DMA to finish */
|
|
|
|
SII_WAIT_UNTIL(status, regs->dstat, status & (SII_CI | SII_DI),
|
|
|
|
SII_WAIT_COUNT, retval);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 2)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: ds %x, cnt %d\n", status, retval);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
if (status & (SII_CI | SII_DI))
|
|
|
|
sii_DoIntr(sc, status);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 2)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: DONE ds %x\n", regs->dstat);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Another device may have selected us; in which case,
|
|
|
|
* this command will be restarted later.
|
|
|
|
*/
|
|
|
|
if (status & (SII_CI | SII_DI)) {
|
|
|
|
sii_DoIntr(sc, regs->dstat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disconnect if selection command still in progress.
|
|
|
|
*/
|
|
|
|
if (status & SII_SIP) {
|
|
|
|
error = ENXIO; /* device didn't respond */
|
|
|
|
regs->comm = SII_DISCON;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_WAIT_UNTIL(status, regs->cstat,
|
|
|
|
!(status & (SII_CON | SII_SIP)),
|
|
|
|
SII_WAIT_COUNT, retval);
|
|
|
|
} else
|
|
|
|
error = EBUSY; /* couldn't get the bus */
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 1)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartCmd: Couldn't select target %d error %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
target, error);
|
|
|
|
#endif
|
|
|
|
sc->sc_target = -1;
|
|
|
|
regs->cstat = 0xffff;
|
|
|
|
regs->dstat = 0xffff;
|
|
|
|
regs->comm = 0;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_CmdDone(sc, target, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process interrupt conditions.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sii_DoIntr(sc, dstat)
|
|
|
|
register struct siisoftc *sc;
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int dstat;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
|
|
|
register SIIRegs *regs = sc->sc_regs;
|
|
|
|
register State *state;
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int cstat;
|
|
|
|
int i, msg;
|
|
|
|
u_int comm;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
again:
|
|
|
|
comm = regs->comm;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 3)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoIntr: cs %x, ds %x cm %x ",
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->cstat, dstat, comm);
|
|
|
|
sii_logp->target = sc->sc_target;
|
|
|
|
sii_logp->cstat = regs->cstat;
|
|
|
|
sii_logp->dstat = dstat;
|
|
|
|
sii_logp->comm = comm;
|
|
|
|
sii_logp->msg = -1;
|
1994-05-27 12:57:32 +04:00
|
|
|
if (sc->sc_target >= 0) {
|
|
|
|
sii_logp->rlen = sc->sc_st[sc->sc_target].buflen;
|
|
|
|
sii_logp->dlen = sc->sc_st[sc->sc_target].dmalen;
|
|
|
|
} else {
|
|
|
|
sii_logp->rlen = 0;
|
|
|
|
sii_logp->dlen = 0;
|
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
if (++sii_logp >= &sii_log[NLOG])
|
|
|
|
sii_logp = sii_log;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
regs->dstat = dstat; /* acknowledge everything */
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
if (dstat & SII_CI) {
|
|
|
|
/* deglitch cstat register */
|
|
|
|
msg = regs->cstat;
|
|
|
|
while (msg != (cstat = regs->cstat))
|
|
|
|
msg = cstat;
|
|
|
|
regs->cstat = cstat; /* acknowledge everything */
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_logp > sii_log)
|
|
|
|
sii_logp[-1].cstat = cstat;
|
|
|
|
else
|
|
|
|
sii_log[NLOG - 1].cstat = cstat;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for a BUS RESET */
|
|
|
|
if (cstat & SII_RST) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: SCSI bus reset!!\n", sc->sc_dev.dv_xname);
|
1993-10-12 06:22:19 +03:00
|
|
|
/* need to flush disconnected commands */
|
|
|
|
for (i = 0; i < SII_NCMD; i++) {
|
|
|
|
if (!sc->sc_cmd[i])
|
|
|
|
continue;
|
|
|
|
sii_CmdDone(sc, i, EIO);
|
|
|
|
}
|
|
|
|
/* rearbitrate synchronous offset */
|
|
|
|
for (i = 0; i < SII_NCMD; i++)
|
|
|
|
sc->sc_st[i].dmaReqAck = 0;
|
|
|
|
sc->sc_target = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* Check for a BUS ERROR.
|
|
|
|
* According to DEC, this feature doesn't really work
|
|
|
|
* and to just clear the bit if it's set.
|
|
|
|
*/
|
|
|
|
if (cstat & SII_BER) {
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for state change */
|
|
|
|
if (cstat & SII_SCH) {
|
|
|
|
sii_StateChg(sc, cstat);
|
|
|
|
comm = regs->comm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for DMA completion */
|
|
|
|
if (dstat & SII_DNE) {
|
|
|
|
u_short *dma;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is a race condition with SII_SCH. There is a short
|
1994-05-27 12:57:32 +04:00
|
|
|
* window between the time a SII_SCH is seen after a disconnect
|
1993-10-12 06:22:19 +03:00
|
|
|
* and when the SII_SCH is cleared. A reselect can happen
|
|
|
|
* in this window and we will clear the SII_SCH without
|
|
|
|
* processing the reconnect.
|
|
|
|
*/
|
|
|
|
if (sc->sc_target < 0) {
|
|
|
|
cstat = regs->cstat;
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: target %d DNE?? dev %d,%d cs %x\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->slcsr, regs->destat,
|
|
|
|
cstat); /* XXX */
|
|
|
|
if (cstat & SII_DST) {
|
|
|
|
sc->sc_target = regs->destat;
|
|
|
|
state->prevComm = 0;
|
|
|
|
} else
|
|
|
|
panic("sc_target 1");
|
|
|
|
}
|
|
|
|
state = &sc->sc_st[sc->sc_target];
|
1994-05-27 12:57:32 +04:00
|
|
|
/* check for a PARITY ERROR */
|
|
|
|
if (dstat & SII_IPE) {
|
|
|
|
state->flags |= PARITY_ERR;
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: Parity error!!\n", sc->sc_dev.dv_xname);
|
1994-05-27 12:57:32 +04:00
|
|
|
goto abort;
|
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
/* dmalen = amount left to transfer, i = amount transfered */
|
|
|
|
i = state->dmalen;
|
|
|
|
state->dmalen = 0;
|
|
|
|
state->dmaCurPhase = -1;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("DNE: amt %d ", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (!(dstat & SII_TCZ))
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("no TCZ?? (%d) ", regs->dmlotc);
|
1993-10-12 06:22:19 +03:00
|
|
|
} else if (!(dstat & SII_TCZ)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: no TCZ?? (%d)\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target, regs->dmlotc);
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DumpLog(); /* XXX */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
switch (comm & SII_PHASE_MSK) {
|
|
|
|
case SII_CMD_PHASE:
|
|
|
|
state->cmdlen -= i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_DATA_IN_PHASE:
|
|
|
|
/* check for more data for the same phase */
|
|
|
|
dma = state->dmaAddr[state->dmaBufIndex];
|
|
|
|
buf = state->buf;
|
|
|
|
state->buf += i;
|
|
|
|
state->buflen -= i;
|
|
|
|
if (state->buflen > 0 && !(dstat & SII_MIS)) {
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* start reading next chunk */
|
|
|
|
len = state->buflen;
|
|
|
|
if (len > SII_MAX_DMA_XFER_LENGTH)
|
|
|
|
len = SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
state->dmaBufIndex = !state->dmaBufIndex;
|
|
|
|
sii_StartDMA(regs,
|
|
|
|
state->dmaCurPhase = SII_DATA_IN_PHASE,
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen = len);
|
1993-10-12 06:22:19 +03:00
|
|
|
dstat &= ~(SII_IBF | SII_TBE);
|
|
|
|
}
|
|
|
|
/* copy in the data */
|
|
|
|
CopyFromBuffer((volatile u_short *)dma, buf, i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_DATA_OUT_PHASE:
|
|
|
|
state->dmaBufIndex = !state->dmaBufIndex;
|
|
|
|
state->buf += i;
|
|
|
|
state->buflen -= i;
|
|
|
|
|
|
|
|
/* check for more data for the same phase */
|
|
|
|
if (state->buflen <= 0 || (dstat & SII_MIS))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* start next chunk */
|
|
|
|
i = state->buflen;
|
|
|
|
if (i > SII_MAX_DMA_XFER_LENGTH) {
|
|
|
|
sii_StartDMA(regs, state->dmaCurPhase =
|
|
|
|
SII_DATA_OUT_PHASE,
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen =
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_MAX_DMA_XFER_LENGTH);
|
|
|
|
/* prepare for next chunk */
|
|
|
|
i -= SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
if (i > SII_MAX_DMA_XFER_LENGTH)
|
|
|
|
i = SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
CopyToBuffer((u_short *)(state->buf +
|
|
|
|
SII_MAX_DMA_XFER_LENGTH),
|
|
|
|
(volatile u_short *)
|
|
|
|
state->dmaAddr[!state->dmaBufIndex], i);
|
|
|
|
} else {
|
|
|
|
sii_StartDMA(regs, state->dmaCurPhase =
|
|
|
|
SII_DATA_OUT_PHASE,
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen = i);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
dstat &= ~(SII_IBF | SII_TBE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for phase change or another MsgIn/Out */
|
|
|
|
if (dstat & (SII_MIS | SII_IBF | SII_TBE)) {
|
|
|
|
/*
|
|
|
|
* There is a race condition with SII_SCH. There is a short
|
1994-05-27 12:57:32 +04:00
|
|
|
* window between the time a SII_SCH is seen after a disconnect
|
1993-10-12 06:22:19 +03:00
|
|
|
* and when the SII_SCH is cleared. A reselect can happen
|
|
|
|
* in this window and we will clear the SII_SCH without
|
|
|
|
* processing the reconnect.
|
|
|
|
*/
|
|
|
|
if (sc->sc_target < 0) {
|
|
|
|
cstat = regs->cstat;
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: target %d MIS?? dev %d,%d cs %x ds %x\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->slcsr, regs->destat,
|
|
|
|
cstat, dstat); /* XXX */
|
|
|
|
if (cstat & SII_DST) {
|
|
|
|
sc->sc_target = regs->destat;
|
|
|
|
state->prevComm = 0;
|
1994-05-27 12:57:32 +04:00
|
|
|
} else {
|
1994-11-22 21:58:43 +03:00
|
|
|
#ifdef DEBUG
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_DumpLog();
|
1994-11-22 21:58:43 +03:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
panic("sc_target 2");
|
1994-05-27 12:57:32 +04:00
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
state = &sc->sc_st[sc->sc_target];
|
|
|
|
switch (dstat & SII_PHASE_MSK) {
|
|
|
|
case SII_CMD_PHASE:
|
|
|
|
if (state->dmaPrevPhase >= 0) {
|
|
|
|
/* restart DMA after disconnect/reconnect */
|
|
|
|
if (state->dmaPrevPhase != SII_CMD_PHASE) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: dma reselect phase doesn't match\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
state->dmaCurPhase = SII_CMD_PHASE;
|
|
|
|
state->dmaPrevPhase = -1;
|
|
|
|
regs->dmaddrl = state->dmaAddrL;
|
|
|
|
regs->dmaddrh = state->dmaAddrH;
|
|
|
|
regs->dmlotc = state->dmaCnt;
|
|
|
|
if (state->dmaCnt & 1)
|
|
|
|
regs->dmabyte = state->dmaByte;
|
|
|
|
regs->comm = SII_DMA | SII_INXFER |
|
|
|
|
(comm & SII_STATE_MSK) | SII_CMD_PHASE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Cmd dcnt %d dadr %x ",
|
1993-10-12 06:22:19 +03:00
|
|
|
state->dmaCnt,
|
|
|
|
(state->dmaAddrH << 16) |
|
|
|
|
state->dmaAddrL);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* send command data */
|
|
|
|
i = state->cmdlen;
|
|
|
|
if (i == 0) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: cmd count exceeded\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
CopyToBuffer((u_short *)state->cmd,
|
|
|
|
(volatile u_short *)state->dmaAddr[0],
|
|
|
|
i);
|
|
|
|
sii_StartDMA(regs, state->dmaCurPhase =
|
|
|
|
SII_CMD_PHASE, state->dmaAddr[0],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen = i);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
/* wait a short time for XFER complete */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & (SII_CI | SII_DI), SII_WAIT_COUNT, i);
|
|
|
|
if (dstat & (SII_CI | SII_DI)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
else if (sii_debug > 0)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoIntr: cmd wait ds %x cnt %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
dstat, i);
|
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_DATA_IN_PHASE:
|
|
|
|
case SII_DATA_OUT_PHASE:
|
|
|
|
if (state->cmdlen > 0) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: cmd %x: command data not all sent (%d) 1\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_cmd[sc->sc_target]->cmd[0],
|
|
|
|
state->cmdlen);
|
|
|
|
state->cmdlen = 0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
sii_DumpLog();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (state->dmaPrevPhase >= 0) {
|
|
|
|
/* restart DMA after disconnect/reconnect */
|
|
|
|
if (state->dmaPrevPhase !=
|
|
|
|
(dstat & SII_PHASE_MSK)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: dma reselect phase doesn't match\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
state->dmaCurPhase = state->dmaPrevPhase;
|
|
|
|
state->dmaPrevPhase = -1;
|
|
|
|
regs->dmaddrl = state->dmaAddrL;
|
|
|
|
regs->dmaddrh = state->dmaAddrH;
|
|
|
|
regs->dmlotc = state->dmaCnt;
|
|
|
|
if (state->dmaCnt & 1)
|
|
|
|
regs->dmabyte = state->dmaByte;
|
|
|
|
regs->comm = SII_DMA | SII_INXFER |
|
|
|
|
(comm & SII_STATE_MSK) |
|
|
|
|
state->dmaCurPhase;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Data %d dcnt %d dadr %x ",
|
1993-10-12 06:22:19 +03:00
|
|
|
state->dmaDataPhase,
|
|
|
|
state->dmaCnt,
|
|
|
|
(state->dmaAddrH << 16) |
|
|
|
|
state->dmaAddrL);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (state->dmaDataPhase != (dstat & SII_PHASE_MSK)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: cmd %x: dma phase doesn't match\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_cmd[sc->sc_target]->cmd[0]);
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Data %d ", state->dmaDataPhase);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (sii_debug > 5)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
i = state->buflen;
|
|
|
|
if (i == 0) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: data count exceeded\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
if (i > SII_MAX_DMA_XFER_LENGTH)
|
|
|
|
i = SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
if ((dstat & SII_PHASE_MSK) == SII_DATA_IN_PHASE) {
|
|
|
|
sii_StartDMA(regs,
|
|
|
|
state->dmaCurPhase = SII_DATA_IN_PHASE,
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen = i);
|
1993-10-12 06:22:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* start first chunk */
|
|
|
|
if (state->flags & FIRST_DMA) {
|
|
|
|
state->flags &= ~FIRST_DMA;
|
|
|
|
CopyToBuffer((u_short *)state->buf,
|
|
|
|
(volatile u_short *)
|
|
|
|
state->dmaAddr[state->dmaBufIndex], i);
|
|
|
|
}
|
|
|
|
sii_StartDMA(regs,
|
|
|
|
state->dmaCurPhase = SII_DATA_OUT_PHASE,
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = state->dmalen = i);
|
1993-10-12 06:22:19 +03:00
|
|
|
i = state->buflen - SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
if (i > 0) {
|
|
|
|
/* prepare for next chunk */
|
|
|
|
if (i > SII_MAX_DMA_XFER_LENGTH)
|
|
|
|
i = SII_MAX_DMA_XFER_LENGTH;
|
|
|
|
CopyToBuffer((u_short *)(state->buf +
|
|
|
|
SII_MAX_DMA_XFER_LENGTH),
|
|
|
|
(volatile u_short *)
|
|
|
|
state->dmaAddr[!state->dmaBufIndex], i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_STATUS_PHASE:
|
|
|
|
if (state->cmdlen > 0) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: cmd %x: command data not all sent (%d) 2\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_cmd[sc->sc_target]->cmd[0],
|
|
|
|
state->cmdlen);
|
|
|
|
state->cmdlen = 0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
sii_DumpLog();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read amount transfered if DMA didn't finish */
|
|
|
|
if (state->dmalen > 0) {
|
|
|
|
i = state->dmalen - regs->dmlotc;
|
|
|
|
state->dmalen = 0;
|
|
|
|
state->dmaCurPhase = -1;
|
|
|
|
regs->dmlotc = 0;
|
|
|
|
regs->comm = comm &
|
|
|
|
(SII_STATE_MSK | SII_PHASE_MSK);
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("DMA amt %d ", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
switch (comm & SII_PHASE_MSK) {
|
|
|
|
case SII_DATA_IN_PHASE:
|
|
|
|
/* copy in the data */
|
|
|
|
CopyFromBuffer((volatile u_short *)
|
|
|
|
state->dmaAddr[state->dmaBufIndex],
|
|
|
|
state->buf, i);
|
|
|
|
|
|
|
|
case SII_CMD_PHASE:
|
|
|
|
case SII_DATA_OUT_PHASE:
|
|
|
|
state->buflen -= i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read a one byte status message */
|
|
|
|
state->statusByte = msg =
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_GetByte(regs, SII_STATUS_PHASE, 1);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (msg < 0) {
|
|
|
|
dstat = regs->dstat;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Status %x ", msg);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (sii_logp > sii_log)
|
|
|
|
sii_logp[-1].msg = msg;
|
|
|
|
else
|
|
|
|
sii_log[NLOG - 1].msg = msg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* do a quick wait for COMMAND_COMPLETE */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & (SII_CI | SII_DI), SII_WAIT_COUNT, i);
|
|
|
|
if (dstat & (SII_CI | SII_DI)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt2 %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_MSG_IN_PHASE:
|
|
|
|
/*
|
|
|
|
* Save DMA state if DMA didn't finish.
|
|
|
|
* Be careful not to save state again after reconnect
|
|
|
|
* and see RESTORE_POINTER message.
|
|
|
|
* Note that the SII DMA address is not incremented
|
|
|
|
* as DMA proceeds.
|
|
|
|
*/
|
|
|
|
if (state->dmaCurPhase > 0) {
|
|
|
|
/* save dma registers */
|
|
|
|
state->dmaPrevPhase = state->dmaCurPhase;
|
|
|
|
state->dmaCurPhase = -1;
|
|
|
|
if (dstat & SII_OBB)
|
|
|
|
state->dmaByte = regs->dmabyte;
|
1996-07-30 10:36:33 +04:00
|
|
|
i = regs->dmlotc;
|
|
|
|
if (i != 0)
|
|
|
|
i = state->dmaCnt - i;
|
1993-10-12 06:22:19 +03:00
|
|
|
/* note: no carry from dmaddrl to dmaddrh */
|
|
|
|
state->dmaAddrL = regs->dmaddrl + i;
|
|
|
|
state->dmaAddrH = regs->dmaddrh;
|
1996-07-30 10:36:33 +04:00
|
|
|
state->dmaCnt = regs->dmlotc;
|
|
|
|
if (state->dmaCnt == 0)
|
|
|
|
state->dmaCnt = SII_MAX_DMA_XFER_LENGTH;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->comm = comm &
|
|
|
|
(SII_STATE_MSK | SII_PHASE_MSK);
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("SavP dcnt %d dadr %x ",
|
1993-10-12 06:22:19 +03:00
|
|
|
state->dmaCnt,
|
|
|
|
(state->dmaAddrH << 16) |
|
|
|
|
state->dmaAddrL);
|
|
|
|
if (((dstat & SII_OBB) != 0) ^
|
|
|
|
(state->dmaCnt & 1))
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("OBB??? ");
|
1993-10-12 06:22:19 +03:00
|
|
|
} else if (sii_debug > 0) {
|
|
|
|
if (((dstat & SII_OBB) != 0) ^
|
|
|
|
(state->dmaCnt & 1)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoIntr: OBB??? ds %x cnt %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
dstat, state->dmaCnt);
|
|
|
|
sii_DumpLog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read a one byte message */
|
1994-05-27 12:57:32 +04:00
|
|
|
msg = sii_GetByte(regs, SII_MSG_IN_PHASE, 0);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (msg < 0) {
|
|
|
|
dstat = regs->dstat;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("MsgIn %x ", msg);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (sii_logp > sii_log)
|
|
|
|
sii_logp[-1].msg = msg;
|
|
|
|
else
|
|
|
|
sii_log[NLOG - 1].msg = msg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* process message */
|
|
|
|
switch (msg) {
|
|
|
|
case SCSI_COMMAND_COMPLETE:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
msg = sc->sc_target;
|
|
|
|
sc->sc_target = -1;
|
|
|
|
/*
|
|
|
|
* Wait a short time for disconnect.
|
|
|
|
* Don't be fooled if SII_BER happens first.
|
|
|
|
* Note: a reselect may happen here.
|
|
|
|
*/
|
|
|
|
SII_WAIT_UNTIL(cstat, regs->cstat,
|
|
|
|
cstat & (SII_RST | SII_SCH),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
if ((cstat & (SII_RST | SII_SCH |
|
|
|
|
SII_STATE_MSK)) == SII_SCH) {
|
|
|
|
regs->cstat = SII_SCH | SII_BER;
|
|
|
|
regs->comm = 0;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Double check that we didn't miss a
|
|
|
|
* state change between seeing it and
|
|
|
|
* clearing the SII_SCH bit.
|
|
|
|
*/
|
|
|
|
i = regs->cstat;
|
|
|
|
if (!(i & SII_SCH) &&
|
|
|
|
(i & SII_STATE_MSK) !=
|
|
|
|
(cstat & SII_STATE_MSK))
|
|
|
|
sii_StateChg(sc, i);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cs %x\n", cstat);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
sii_CmdDone(sc, msg, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_EXTENDED_MSG:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
/* read the message length */
|
1994-05-27 12:57:32 +04:00
|
|
|
msg = sii_GetByte(regs, SII_MSG_IN_PHASE, 1);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (msg < 0) {
|
|
|
|
dstat = regs->dstat;
|
|
|
|
goto again;
|
|
|
|
}
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_buf[1] = msg; /* message length */
|
1993-10-12 06:22:19 +03:00
|
|
|
if (msg == 0)
|
|
|
|
msg = 256;
|
1994-05-27 12:57:32 +04:00
|
|
|
/*
|
|
|
|
* We read and acknowlege all the bytes
|
|
|
|
* except the last so we can assert ATN
|
|
|
|
* if needed before acknowledging the last.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < msg; i++) {
|
|
|
|
dstat = sii_GetByte(regs,
|
|
|
|
SII_MSG_IN_PHASE, i < msg - 1);
|
|
|
|
if ((int)dstat < 0) {
|
|
|
|
dstat = regs->dstat;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
sii_buf[i + 2] = dstat;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (sii_buf[2]) {
|
|
|
|
case SCSI_MODIFY_DATA_PTR:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER |
|
|
|
|
SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
i = (sii_buf[3] << 24) |
|
|
|
|
(sii_buf[4] << 16) |
|
|
|
|
(sii_buf[5] << 8) |
|
|
|
|
sii_buf[6];
|
|
|
|
if (state->dmaPrevPhase >= 0) {
|
|
|
|
state->dmaAddrL += i;
|
|
|
|
state->dmaCnt -= i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_SYNCHRONOUS_XFER:
|
1994-05-27 12:57:32 +04:00
|
|
|
/*
|
|
|
|
* Acknowledge last byte and
|
|
|
|
* signal a request for MSG_OUT.
|
|
|
|
*/
|
|
|
|
regs->comm = SII_INXFER | SII_ATN |
|
|
|
|
SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DoSync(regs, state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
reject:
|
1994-05-27 12:57:32 +04:00
|
|
|
/*
|
|
|
|
* Acknowledge last byte and
|
|
|
|
* signal a request for MSG_OUT.
|
|
|
|
*/
|
|
|
|
regs->comm = SII_INXFER | SII_ATN |
|
|
|
|
SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1994-05-27 12:57:32 +04:00
|
|
|
|
|
|
|
/* wait for MSG_OUT phase */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_TBE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/* send a reject message */
|
|
|
|
regs->data = SCSI_MESSAGE_REJECT;
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->comm = SII_INXFER |
|
1993-10-12 06:22:19 +03:00
|
|
|
(regs->cstat & SII_STATE_MSK) |
|
|
|
|
SII_MSG_OUT_PHASE;
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
1994-05-27 12:57:32 +04:00
|
|
|
dstat & SII_DNE,
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_SAVE_DATA_POINTER:
|
|
|
|
case SCSI_RESTORE_POINTERS:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
/* wait a short time for another msg */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & (SII_CI | SII_DI),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
if (dstat & (SII_CI | SII_DI)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_DISCONNECT:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
state->prevComm = comm;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("disconn %d ", sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Wait a short time for disconnect.
|
|
|
|
* Don't be fooled if SII_BER happens first.
|
|
|
|
* Note: a reselect may happen here.
|
|
|
|
*/
|
|
|
|
SII_WAIT_UNTIL(cstat, regs->cstat,
|
|
|
|
cstat & (SII_RST | SII_SCH),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
if ((cstat & (SII_RST | SII_SCH |
|
|
|
|
SII_STATE_MSK)) != SII_SCH) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
dstat = regs->dstat;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
regs->cstat = SII_SCH | SII_BER;
|
|
|
|
regs->comm = 0;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_target = -1;
|
|
|
|
/*
|
|
|
|
* Double check that we didn't miss a state
|
|
|
|
* change between seeing it and clearing
|
|
|
|
* the SII_SCH bit.
|
|
|
|
*/
|
|
|
|
i = regs->cstat;
|
|
|
|
if (!(i & SII_SCH) && (i & SII_STATE_MSK) !=
|
|
|
|
(cstat & SII_STATE_MSK))
|
|
|
|
sii_StateChg(sc, i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_MESSAGE_REJECT:
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: message reject.\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1994-05-27 12:57:32 +04:00
|
|
|
break;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (!(msg & SCSI_IDENTIFY)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: couldn't handle message 0x%x... rejecting.\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target,
|
1993-10-12 06:22:19 +03:00
|
|
|
msg);
|
|
|
|
#ifdef DEBUG
|
|
|
|
sii_DumpLog();
|
|
|
|
#endif
|
1994-05-27 12:57:32 +04:00
|
|
|
goto reject;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
1994-05-27 12:57:32 +04:00
|
|
|
/* acknowledge last byte */
|
|
|
|
regs->comm = SII_INXFER | SII_MSG_IN_PHASE |
|
|
|
|
(comm & SII_STATE_MSK);
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & SII_DNE, SII_WAIT_COUNT, i);
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
/* may want to check LUN some day */
|
|
|
|
/* wait a short time for another msg */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
dstat & (SII_CI | SII_DI),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
if (dstat & (SII_CI | SII_DI)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_MSG_OUT_PHASE:
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("MsgOut\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("MsgOut %x\n", state->flags); /* XXX */
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
/*
|
|
|
|
* Check for parity error.
|
|
|
|
* Hardware will automatically set ATN
|
|
|
|
* to request the device for a MSG_OUT phase.
|
|
|
|
*/
|
|
|
|
if (state->flags & PARITY_ERR) {
|
|
|
|
state->flags &= ~PARITY_ERR;
|
|
|
|
regs->data = SCSI_MESSAGE_PARITY_ERROR;
|
|
|
|
} else
|
|
|
|
regs->data = SCSI_NO_OP;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->comm = SII_INXFER | (comm & SII_STATE_MSK) |
|
|
|
|
SII_MSG_OUT_PHASE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/* wait a short time for XFER complete */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("ds %x i %d\n", dstat, i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
/* just clear the DNE bit and check errors later */
|
|
|
|
if (dstat & SII_DNE) {
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: Couldn't handle phase %d... ignoring.\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, dstat & SII_PHASE_MSK);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 3)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Check to make sure we won't be interrupted again.
|
|
|
|
* Deglitch dstat register.
|
|
|
|
*/
|
|
|
|
msg = regs->dstat;
|
|
|
|
while (msg != (dstat = regs->dstat))
|
|
|
|
msg = dstat;
|
|
|
|
if (dstat & (SII_CI | SII_DI))
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
if (sc->sc_target < 0) {
|
|
|
|
/* look for another device that is ready */
|
|
|
|
for (i = 0; i < SII_NCMD; i++) {
|
|
|
|
/* don't restart a disconnected command */
|
|
|
|
if (!sc->sc_cmd[i] || sc->sc_st[i].prevComm)
|
|
|
|
continue;
|
|
|
|
sii_StartCmd(sc, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
/* jump here to abort the current command */
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: current command terminated\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
sii_DumpLog();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((cstat = regs->cstat) & SII_CON) {
|
|
|
|
/* try to send an abort msg for awhile */
|
|
|
|
regs->dstat = SII_DNE;
|
|
|
|
regs->data = SCSI_ABORT;
|
|
|
|
regs->comm = SII_INXFER | SII_ATN | (cstat & SII_STATE_MSK) |
|
|
|
|
SII_MSG_OUT_PHASE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
(dstat & (SII_DNE | SII_PHASE_MSK)) ==
|
|
|
|
(SII_DNE | SII_MSG_OUT_PHASE),
|
|
|
|
2 * SII_WAIT_COUNT, i);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 0)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Abort: cs %x ds %x i %d\n", cstat, dstat, i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
1996-09-07 05:19:45 +04:00
|
|
|
if ((dstat & (SII_DNE | SII_PHASE_MSK)) ==
|
1993-10-12 06:22:19 +03:00
|
|
|
(SII_DNE | SII_MSG_OUT_PHASE)) {
|
|
|
|
/* disconnect if command in progress */
|
|
|
|
regs->comm = SII_DISCON;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_WAIT_UNTIL(cstat, regs->cstat,
|
|
|
|
!(cstat & SII_CON), SII_WAIT_COUNT, i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 0)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Abort: cs %x\n", cstat);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
regs->cstat = 0xffff;
|
|
|
|
regs->dstat = 0xffff;
|
|
|
|
regs->comm = 0;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
i = sc->sc_target;
|
|
|
|
sc->sc_target = -1;
|
|
|
|
sii_CmdDone(sc, i, EIO);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoIntr: after CmdDone target %d\n", sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sii_StateChg(sc, cstat)
|
|
|
|
register struct siisoftc *sc;
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int cstat;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
|
|
|
register SIIRegs *regs = sc->sc_regs;
|
|
|
|
register State *state;
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("SCH: ");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (cstat & SII_STATE_MSK) {
|
|
|
|
case 0:
|
|
|
|
/* disconnect */
|
|
|
|
i = sc->sc_target;
|
|
|
|
sc->sc_target = -1;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("disconn %d ", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
if (i >= 0 && !sc->sc_st[i].prevComm) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: spurrious disconnect (%d)\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, i, regs->slcsr);
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_st[i].prevComm = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_CON:
|
|
|
|
/* connected as initiator */
|
|
|
|
i = regs->slcsr;
|
|
|
|
if (sc->sc_target == i)
|
|
|
|
break;
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: connect to device %d??\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_target, i);
|
1993-10-12 06:22:19 +03:00
|
|
|
sc->sc_target = i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SII_DST:
|
|
|
|
/*
|
|
|
|
* Wait for CON to become valid,
|
|
|
|
* chip is slow sometimes.
|
|
|
|
*/
|
|
|
|
SII_WAIT_UNTIL(cstat, regs->cstat,
|
|
|
|
cstat & SII_CON, SII_WAIT_COUNT, i);
|
|
|
|
if (!(cstat & SII_CON))
|
|
|
|
panic("sii resel");
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case SII_CON | SII_DST:
|
|
|
|
/*
|
|
|
|
* Its a reselection. Save the ID and wait for
|
|
|
|
* interrupts to tell us what to do next
|
|
|
|
* (should be MSG_IN of IDENTIFY).
|
|
|
|
* NOTE: sc_target may be >= 0 if we were in
|
|
|
|
* the process of trying to start a command
|
|
|
|
* and were reselected before the select
|
|
|
|
* command finished.
|
|
|
|
*/
|
|
|
|
sc->sc_target = i = regs->destat;
|
1994-05-27 12:57:32 +04:00
|
|
|
state = &sc->sc_st[i];
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->comm = SII_CON | SII_DST | SII_MSG_IN_PHASE;
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dmctrl = state->dmaReqAck;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
if (!state->prevComm) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: device %d: spurious reselection\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, i);
|
1993-10-12 06:22:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
state->prevComm = 0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("resel %d ", sc->sc_target);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
case SII_DST | SII_TGT:
|
|
|
|
case SII_CON | SII_DST | SII_TGT:
|
|
|
|
/* connected as target */
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: Selected by device %d as target!!\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, regs->destat);
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->comm = SII_DISCON;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
SII_WAIT_UNTIL(!(regs->cstat & SII_CON),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
regs->cstat = 0xffff;
|
|
|
|
regs->dstat = 0xffff;
|
|
|
|
regs->comm = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("%s: Unknown state change (cs %x)!!\n",
|
1995-09-11 12:29:11 +04:00
|
|
|
sc->sc_dev.dv_xname, cstat);
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
sii_DumpLog();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read one byte of data.
|
1994-05-27 12:57:32 +04:00
|
|
|
* If 'ack' is true, acknowledge the byte.
|
1993-10-12 06:22:19 +03:00
|
|
|
*/
|
|
|
|
static int
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_GetByte(regs, phase, ack)
|
1993-10-12 06:22:19 +03:00
|
|
|
register SIIRegs *regs;
|
1994-05-27 12:57:32 +04:00
|
|
|
int phase, ack;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int dstat;
|
|
|
|
register u_int state;
|
|
|
|
register int i;
|
|
|
|
register int data;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
dstat = regs->dstat;
|
|
|
|
state = regs->cstat & SII_STATE_MSK;
|
|
|
|
if (!(dstat & SII_IBF) || (dstat & SII_MIS)) {
|
|
|
|
regs->comm = state | phase;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
/* wait a short time for IBF */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & SII_IBF,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!(dstat & SII_IBF))
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("status no IBF\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
}
|
1994-05-27 12:57:32 +04:00
|
|
|
if (dstat & SII_DNE) { /* XXX */
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_GetByte: DNE set 5\n");
|
1994-11-22 21:58:43 +03:00
|
|
|
#ifdef DEBUG
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DumpLog();
|
1994-11-22 21:58:43 +03:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dstat = SII_DNE;
|
|
|
|
}
|
1994-05-27 12:57:32 +04:00
|
|
|
data = regs->data;
|
|
|
|
/* check for parity error */
|
|
|
|
if (dstat & SII_IPE) {
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 4)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("cnt0 %d\n", i);
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_GetByte: data %x ?? ds %x cm %x i %d\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
data, dstat, regs->comm, i); /* XXX */
|
|
|
|
data = -1;
|
|
|
|
ack = 1;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
if (ack) {
|
|
|
|
regs->comm = SII_INXFER | state | phase;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
/* wait a short time for XFER complete */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
/* clear the DNE */
|
|
|
|
if (dstat & SII_DNE) {
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1994-05-27 12:57:32 +04:00
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
return (data);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exchange messages to initiate synchronous data transfers.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sii_DoSync(regs, state)
|
|
|
|
register SIIRegs *regs;
|
|
|
|
register State *state;
|
|
|
|
{
|
1994-05-27 12:57:32 +04:00
|
|
|
register u_int dstat, comm;
|
|
|
|
register int i, j;
|
|
|
|
u_int len;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: len %d per %d req/ack %d\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
sii_buf[1], sii_buf[3], sii_buf[4]);
|
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1994-05-27 12:57:32 +04:00
|
|
|
/* SII chip can only handle a minimum transfer period of ??? */
|
|
|
|
if (sii_buf[3] < 64)
|
|
|
|
sii_buf[3] = 64;
|
|
|
|
/* SII chip can only handle a maximum REQ/ACK offset of 3 */
|
1993-10-12 06:22:19 +03:00
|
|
|
len = sii_buf[4];
|
|
|
|
if (len > 3)
|
1994-05-27 12:57:32 +04:00
|
|
|
len = 3;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
sii_buf[0] = SCSI_EXTENDED_MSG;
|
|
|
|
sii_buf[1] = 3; /* message length */
|
|
|
|
sii_buf[2] = SCSI_SYNCHRONOUS_XFER;
|
|
|
|
sii_buf[4] = len;
|
1994-05-27 12:57:32 +04:00
|
|
|
#if 1
|
|
|
|
comm = SII_INXFER | SII_ATN | SII_MSG_OUT_PHASE |
|
|
|
|
(regs->cstat & SII_STATE_MSK);
|
|
|
|
regs->comm = comm & ~SII_INXFER;
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
/* wait for target to request the next byte */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & SII_TBE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
if (!(dstat & SII_TBE) ||
|
|
|
|
(dstat & SII_PHASE_MSK) != SII_MSG_OUT_PHASE) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: TBE? ds %x cm %x i %d\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
dstat, comm, i); /* XXX */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the last message byte should have ATN off */
|
|
|
|
if (j == 4)
|
|
|
|
comm &= ~SII_ATN;
|
|
|
|
|
|
|
|
regs->data = sii_buf[j];
|
|
|
|
regs->comm = comm;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1994-05-27 12:57:32 +04:00
|
|
|
|
|
|
|
/* wait a short time for XFER complete */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & SII_DNE,
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
|
|
|
|
if (!(dstat & SII_DNE)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: DNE? ds %x cm %x i %d\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
dstat, comm, i); /* XXX */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the DNE, other errors handled later */
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1994-05-27 12:57:32 +04:00
|
|
|
}
|
1996-10-13 07:02:39 +04:00
|
|
|
#else /* 0 */
|
|
|
|
CopyToBuffer((u_short *)sii_buf,
|
|
|
|
(volatile u_short *)SII_BUF_ADDR(sc), 5);
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: %x %x %x ds %x\n",
|
1996-10-13 07:02:39 +04:00
|
|
|
((volatile u_short *)SII_BUF_ADDR(sc))[0],
|
|
|
|
((volatile u_short *)SII_BUF_ADDR(sc))[2],
|
|
|
|
((volatile u_short *)SII_BUF_ADDR(sc))[4],
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dstat); /* XXX */
|
1996-10-13 07:02:39 +04:00
|
|
|
regs->dmaddrl = (u_short)(SII_BUF_ADDR(sc) >> 1);
|
|
|
|
regs->dmaddrh = (u_short)(SII_BUF_ADDR(sc) >> 17) & 03;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dmlotc = 5;
|
|
|
|
regs->comm = SII_DMA | SII_INXFER | SII_ATN |
|
|
|
|
(regs->cstat & SII_STATE_MSK) | SII_MSG_OUT_PHASE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/* wait a short time for XFER complete */
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat,
|
|
|
|
(dstat & (SII_DNE | SII_TCZ)) == (SII_DNE | SII_TCZ),
|
|
|
|
SII_WAIT_COUNT, i);
|
|
|
|
|
|
|
|
if ((dstat & (SII_DNE | SII_TCZ)) != (SII_DNE | SII_TCZ)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: ds %x cm %x i %d lotc %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
dstat, regs->comm, i, regs->dmlotc); /* XXX */
|
|
|
|
sii_DumpLog(); /* XXX */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* clear the DNE, other errors handled later */
|
|
|
|
regs->dstat = SII_DNE;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1996-10-13 07:02:39 +04:00
|
|
|
#endif /* 0 */
|
1994-05-27 12:57:32 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
SII_WAIT_UNTIL(dstat, regs->dstat, dstat & (SII_CI | SII_DI),
|
|
|
|
SII_WAIT_COUNT, i);
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_DoSync: ds %x cm %x i %d lotc %d\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
dstat, regs->comm, i, regs->dmlotc); /* XXX */
|
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
state->dmaReqAck = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue the sequence of commands to the controller to start DMA.
|
|
|
|
* NOTE: the data buffer should be word-aligned for DMA out.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sii_StartDMA(regs, phase, dmaAddr, size)
|
|
|
|
register SIIRegs *regs; /* which SII to use */
|
|
|
|
int phase; /* phase to send/receive data */
|
|
|
|
u_short *dmaAddr; /* DMA buffer address */
|
|
|
|
int size; /* # of bytes to transfer */
|
|
|
|
{
|
|
|
|
|
|
|
|
if (regs->dstat & SII_DNE) { /* XXX */
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dstat = SII_DNE;
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartDMA: DNE set\n");
|
1994-11-22 21:58:43 +03:00
|
|
|
#ifdef DEBUG
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DumpLog();
|
1994-11-22 21:58:43 +03:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
1994-05-27 12:57:32 +04:00
|
|
|
regs->dmaddrl = ((u_long)dmaAddr >> 1);
|
|
|
|
regs->dmaddrh = ((u_long)dmaAddr >> 17) & 03;
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->dmlotc = size;
|
|
|
|
regs->comm = SII_DMA | SII_INXFER | (regs->cstat & SII_STATE_MSK) |
|
|
|
|
phase;
|
1996-04-12 22:15:23 +04:00
|
|
|
wbflush();
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 5) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_StartDMA: cs 0x%x, ds 0x%x, cm 0x%x, size %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
regs->cstat, regs->dstat, regs->comm, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the device driver's 'done' routine to let it know the command is done.
|
|
|
|
* The 'done' routine may try to start another command.
|
|
|
|
* To be fair, we should start pending commands for other devices
|
|
|
|
* before allowing the same device to start another command.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sii_CmdDone(sc, target, error)
|
|
|
|
register struct siisoftc *sc; /* which SII to use */
|
|
|
|
int target; /* which device is done */
|
|
|
|
int error; /* error code if any errors */
|
|
|
|
{
|
|
|
|
register ScsiCmd *scsicmd;
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
scsicmd = sc->sc_cmd[target];
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (target < 0 || !scsicmd)
|
|
|
|
panic("sii_CmdDone");
|
|
|
|
#endif
|
|
|
|
sc->sc_cmd[target] = (ScsiCmd *)0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sii_debug > 1) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii_CmdDone: %s target %d cmd %x err %d resid %d\n",
|
1993-10-12 06:22:19 +03:00
|
|
|
scsicmd->sd->sd_driver->d_name, target,
|
|
|
|
scsicmd->cmd[0], error, sc->sc_st[target].buflen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* look for another device that is ready */
|
|
|
|
for (i = 0; i < SII_NCMD; i++) {
|
|
|
|
/* don't restart a disconnected command */
|
|
|
|
if (!sc->sc_cmd[i] || sc->sc_st[i].prevComm)
|
|
|
|
continue;
|
|
|
|
sii_StartCmd(sc, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*scsicmd->sd->sd_driver->d_done)(scsicmd->unit, error,
|
|
|
|
sc->sc_st[target].buflen, sc->sc_st[target].statusByte);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-04-12 22:15:23 +04:00
|
|
|
void
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_DumpLog()
|
|
|
|
{
|
|
|
|
register struct sii_log *lp;
|
|
|
|
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("sii: cmd %x bn %d cnt %d\n", sii_debug_cmd, sii_debug_bn,
|
1993-10-12 06:22:19 +03:00
|
|
|
sii_debug_sz);
|
1994-05-27 12:39:00 +04:00
|
|
|
lp = sii_logp;
|
|
|
|
do {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("target %d cs %x ds %x cm %x msg %x rlen %x dlen %x\n",
|
1994-05-27 12:57:32 +04:00
|
|
|
lp->target, lp->cstat, lp->dstat, lp->comm, lp->msg,
|
|
|
|
lp->rlen, lp->dlen);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (++lp >= &sii_log[NLOG])
|
|
|
|
lp = sii_log;
|
1994-05-27 12:39:00 +04:00
|
|
|
} while (lp != sii_logp);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
1994-05-27 12:57:32 +04:00
|
|
|
|