1996-10-13 06:59:38 +04:00
|
|
|
/* $NetBSD: esp.c,v 1.59 1996/10/13 02:59:48 christos Exp $ */
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
#ifdef __sparc__
|
|
|
|
#define SPARC_DRIVER
|
|
|
|
#endif
|
1994-11-20 23:51:32 +03:00
|
|
|
|
1996-09-28 07:21:04 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Charles M. Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Charles M. Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Copyright (c) 1994 Peter Galbavy
|
1995-11-28 23:49:12 +03:00
|
|
|
* Copyright (c) 1995 Paul Kranenburg
|
1994-09-18 03:48:32 +04:00
|
|
|
* All rights reserved.
|
1993-10-02 13:22:00 +03:00
|
|
|
*
|
|
|
|
* 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:
|
1994-09-18 03:48:32 +04:00
|
|
|
* This product includes software developed by Peter Galbavy
|
1996-04-01 02:38:29 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
1994-09-18 03:48:32 +04:00
|
|
|
* derived from this software without specific prior written permission.
|
1993-10-02 13:22:00 +03:00
|
|
|
*
|
1994-09-18 03:48:32 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Based on aic6360 by Jarle Greipsland
|
|
|
|
*
|
|
|
|
* Acknowledgements: Many of the algorithms used in this driver are
|
|
|
|
* inspired by the work of Julian Elischer (julian@tfs.com) and
|
|
|
|
* Charles Hannum (mycroft@duality.gnu.ai.mit.edu). Thanks a million!
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
#include <sys/types.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
#include <sys/param.h>
|
1994-09-18 03:48:32 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
#include <sys/device.h>
|
1994-09-18 03:48:32 +04:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/queue.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
1995-11-28 23:49:12 +03:00
|
|
|
#include <scsi/scsi_message.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <sparc/dev/sbusvar.h>
|
|
|
|
#include <sparc/dev/dmareg.h>
|
|
|
|
#include <sparc/dev/dmavar.h>
|
|
|
|
#include <sparc/dev/espreg.h>
|
|
|
|
#include <sparc/dev/espvar.h>
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
#include <dev/tc/tcvar.h>
|
|
|
|
#include <alpha/tc/tcdsvar.h>
|
|
|
|
#include <alpha/tc/espreg.h>
|
|
|
|
#include <alpha/tc/espvar.h>
|
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-04-01 02:38:29 +04:00
|
|
|
int esp_debug = 0; /*ESP_SHOWPHASE|ESP_SHOWMISC|ESP_SHOWTRAC|ESP_SHOWCMDS;*/
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-06-02 17:43:30 +04:00
|
|
|
/*static*/ void espattach __P((struct device *, struct device *, void *));
|
|
|
|
/*static*/ int espmatch __P((struct device *, void *, void *));
|
|
|
|
/*static*/ u_int esp_adapter_info __P((struct esp_softc *));
|
|
|
|
/*static*/ void espreadregs __P((struct esp_softc *));
|
1996-09-28 05:49:06 +04:00
|
|
|
/*static*/ void esp_select __P((struct esp_softc *, struct esp_ecb *));
|
1996-09-28 07:21:04 +04:00
|
|
|
/*static*/ int esp_reselect __P((struct esp_softc *, int));
|
1995-06-02 17:43:30 +04:00
|
|
|
/*static*/ void esp_scsi_reset __P((struct esp_softc *));
|
|
|
|
/*static*/ void esp_reset __P((struct esp_softc *));
|
|
|
|
/*static*/ void esp_init __P((struct esp_softc *, int));
|
|
|
|
/*static*/ int esp_scsi_cmd __P((struct scsi_xfer *));
|
1996-09-28 05:49:06 +04:00
|
|
|
/*static*/ int esp_poll __P((struct esp_softc *, struct scsi_xfer *, int));
|
1995-06-02 17:43:30 +04:00
|
|
|
/*static*/ void esp_sched __P((struct esp_softc *));
|
1996-09-28 05:49:06 +04:00
|
|
|
/*static*/ void esp_done __P((struct esp_softc *, struct esp_ecb *));
|
1995-06-02 17:43:30 +04:00
|
|
|
/*static*/ void esp_msgin __P((struct esp_softc *));
|
|
|
|
/*static*/ void esp_msgout __P((struct esp_softc *));
|
|
|
|
/*static*/ int espintr __P((struct esp_softc *));
|
|
|
|
/*static*/ void esp_timeout __P((void *arg));
|
1996-09-28 05:49:06 +04:00
|
|
|
/*static*/ void esp_abort __P((struct esp_softc *, struct esp_ecb *));
|
|
|
|
/*static*/ void esp_dequeue __P((struct esp_softc *, struct esp_ecb *));
|
|
|
|
void esp_sense __P((struct esp_softc *, struct esp_ecb *));
|
|
|
|
void esp_free_ecb __P((struct esp_softc *, struct esp_ecb *, int));
|
|
|
|
struct esp_ecb *esp_get_ecb __P((struct esp_softc *, int));
|
|
|
|
static inline int esp_stp2cpb __P((struct esp_softc *, int));
|
|
|
|
static inline int esp_cpb2stp __P((struct esp_softc *, int));
|
|
|
|
static inline void esp_setsync __P((struct esp_softc *, struct esp_tinfo *));
|
1996-03-14 22:44:30 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/* Linkup to the rest of the kernel */
|
1996-03-17 05:00:30 +03:00
|
|
|
struct cfattach esp_ca = {
|
|
|
|
sizeof(struct esp_softc), espmatch, espattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver esp_cd = {
|
|
|
|
NULL, "esp", DV_DULL
|
1993-10-02 13:22:00 +03:00
|
|
|
};
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
struct scsi_adapter esp_switch = {
|
|
|
|
esp_scsi_cmd,
|
1995-07-24 11:33:32 +04:00
|
|
|
minphys, /* no max at this level; handled by DMA code */
|
1995-01-02 23:21:01 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
1993-10-02 13:22:00 +03:00
|
|
|
};
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
struct scsi_device esp_dev = {
|
|
|
|
NULL, /* Use default error handler */
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL, /* Use default 'done' routine */
|
|
|
|
};
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-10-03 00:59:56 +03:00
|
|
|
int
|
1994-11-23 10:02:02 +03:00
|
|
|
espmatch(parent, vcf, aux)
|
1994-10-03 00:59:56 +03:00
|
|
|
struct device *parent;
|
1994-11-23 10:02:02 +03:00
|
|
|
void *vcf, *aux;
|
1994-10-03 00:59:56 +03:00
|
|
|
{
|
1994-11-23 10:02:02 +03:00
|
|
|
struct cfdata *cf = vcf;
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-10-03 00:59:56 +03:00
|
|
|
register struct confargs *ca = aux;
|
|
|
|
register struct romaux *ra = &ca->ca_ra;
|
|
|
|
|
|
|
|
if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
|
|
|
|
return (0);
|
1994-10-15 08:48:47 +03:00
|
|
|
if (ca->ca_bustype == BUS_SBUS)
|
|
|
|
return (1);
|
|
|
|
ra->ra_len = NBPG;
|
|
|
|
return (probeget(ra->ra_vaddr, 1) != -1);
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
struct tcdsdev_attach_args *tcdsdev = aux;
|
|
|
|
|
|
|
|
if (strncmp(tcdsdev->tcdsda_modname, "PMAZ-AA ", TC_ROM_LLEN))
|
|
|
|
return (0);
|
|
|
|
return (!tc_badaddr(tcdsdev->tcdsda_addr));
|
|
|
|
#endif
|
1994-10-03 00:59:56 +03:00
|
|
|
}
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Attach this instance, and then all the sub-devices
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
|
|
|
void
|
1994-09-18 03:48:32 +04:00
|
|
|
espattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
register struct confargs *ca = aux;
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
register struct tcdsdev_attach_args *tcdsdev = aux;
|
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
struct esp_softc *sc = (void *)self;
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
struct bootpath *bp;
|
1996-06-12 16:46:21 +04:00
|
|
|
int dmachild = strncmp(parent->dv_xname, "dma", 3) == 0;
|
1996-09-28 05:49:06 +04:00
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* Make sure things are sane. I don't know if this is ever
|
|
|
|
* necessary, but it seem to be in all of Torek's code.
|
|
|
|
*/
|
|
|
|
if (ca->ca_ra.ra_nintr != 1) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": expected 1 interrupt, got %d\n", ca->ca_ra.ra_nintr);
|
1993-10-02 13:22:00 +03:00
|
|
|
return;
|
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
sc->sc_pri = ca->ca_ra.ra_intr[0].int_pri;
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" pri %d", sc->sc_pri);
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Map my registers in, if they aren't already in virtual
|
|
|
|
* address space.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
if (ca->ca_ra.ra_vaddr)
|
1995-12-19 02:58:31 +03:00
|
|
|
sc->sc_reg = (volatile u_char *) ca->ca_ra.ra_vaddr;
|
1994-09-18 03:48:32 +04:00
|
|
|
else {
|
1995-12-19 02:58:31 +03:00
|
|
|
sc->sc_reg = (volatile u_char *)
|
1995-12-11 15:43:14 +03:00
|
|
|
mapiodev(ca->ca_ra.ra_reg, 0, ca->ca_ra.ra_len, ca->ca_bustype);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
sc->sc_reg = (volatile u_int32_t *)tcdsdev->tcdsda_addr;
|
|
|
|
sc->sc_cookie = tcdsdev->tcdsda_cookie;
|
|
|
|
sc->sc_dma = tcdsdev->tcdsda_sc;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": address %x", sc->sc_reg);
|
1996-09-28 05:49:06 +04:00
|
|
|
tcds_intr_establish(parent, sc->sc_cookie, TC_IPL_BIO,
|
|
|
|
(int (*)(void *))espintr, sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
/* Other settings */
|
1994-10-03 00:59:56 +03:00
|
|
|
sc->sc_node = ca->ca_ra.ra_node;
|
|
|
|
if (ca->ca_bustype == BUS_SBUS) {
|
|
|
|
sc->sc_id = getpropint(sc->sc_node, "initiator-id", 7);
|
|
|
|
sc->sc_freq = getpropint(sc->sc_node, "clock-frequency", -1);
|
|
|
|
} else {
|
|
|
|
sc->sc_id = 7;
|
|
|
|
sc->sc_freq = 24000000;
|
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_freq < 0)
|
|
|
|
sc->sc_freq = ((struct sbus_softc *)
|
|
|
|
sc->sc_dev.dv_parent)->sc_clockfreq;
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
if (parent->dv_cfdata->cf_driver == &tcds_cd) {
|
|
|
|
sc->sc_id = tcdsdev->tcdsda_id;
|
|
|
|
sc->sc_freq = tcdsdev->tcdsda_freq;
|
|
|
|
} else {
|
|
|
|
/* XXX */
|
|
|
|
sc->sc_id = 7;
|
|
|
|
sc->sc_freq = 24000000;
|
|
|
|
}
|
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
/* gimme Mhz */
|
|
|
|
sc->sc_freq /= 1000000;
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1995-11-03 19:47:43 +03:00
|
|
|
if (dmachild) {
|
|
|
|
sc->sc_dma = (struct dma_softc *)parent;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dma->sc_esp = sc;
|
1995-11-03 19:47:43 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* find the DMA by poking around the dma device structures
|
|
|
|
*
|
|
|
|
* What happens here is that if the dma driver has not been
|
|
|
|
* configured, then this returns a NULL pointer. Then when the
|
|
|
|
* dma actually gets configured, it does the opposing test, and
|
|
|
|
* if the sc->sc_esp field in it's softc is NULL, then tries to
|
|
|
|
* find the matching esp driver.
|
|
|
|
*
|
|
|
|
*/
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dma = (struct dma_softc *)
|
|
|
|
getdevunit("dma", sc->sc_dev.dv_unit);
|
1995-11-03 19:47:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* and a back pointer to us, for DMA
|
|
|
|
*/
|
|
|
|
if (sc->sc_dma)
|
|
|
|
sc->sc_dma->sc_esp = sc;
|
1996-05-21 23:09:43 +04:00
|
|
|
else
|
|
|
|
panic("espattach: no dma found");
|
1995-11-03 19:47:43 +03:00
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
sc->sc_dma->sc_esp = sc; /* XXX */
|
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It is necessary to try to load the 2nd config register here,
|
|
|
|
* to find out what rev the esp chip is, else the esp_reset
|
|
|
|
* will not set up the defaults correctly.
|
|
|
|
*/
|
|
|
|
sc->sc_cfg1 = sc->sc_id | ESPCFG1_PARENB;
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1995-09-06 16:35:38 +04:00
|
|
|
sc->sc_cfg2 = ESPCFG2_SCSI2 | ESPCFG2_RPE;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_cfg3 = ESPCFG3_CDB;
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG2, sc->sc_cfg2);
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-12-19 02:58:31 +03:00
|
|
|
if ((ESP_READ_REG(sc, ESP_CFG2) & ~ESPCFG2_RSVD) != (ESPCFG2_SCSI2 | ESPCFG2_RPE)) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": ESP100");
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_rev = ESP100;
|
1993-10-02 13:22:00 +03:00
|
|
|
} else {
|
1996-06-12 02:26:16 +04:00
|
|
|
sc->sc_cfg2 = ESPCFG2_SCSI2;
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG2, sc->sc_cfg2);
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_cfg3 = 0;
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG3, sc->sc_cfg3);
|
1995-10-24 19:03:57 +03:00
|
|
|
sc->sc_cfg3 = (ESPCFG3_CDB | ESPCFG3_FCLK);
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG3, sc->sc_cfg3);
|
|
|
|
if (ESP_READ_REG(sc, ESP_CFG3) != (ESPCFG3_CDB | ESPCFG3_FCLK)) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": ESP100A");
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_rev = ESP100A;
|
1993-10-02 13:22:00 +03:00
|
|
|
} else {
|
1996-06-12 23:12:19 +04:00
|
|
|
/* ESPCFG2_FE enables > 64K transfers */
|
1996-06-12 02:26:16 +04:00
|
|
|
sc->sc_cfg2 |= ESPCFG2_FE;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_cfg3 = 0;
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG3, sc->sc_cfg3);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": ESP200");
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_rev = ESP200;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
sc->sc_cfg2 = ESPCFG2_SCSI2;
|
|
|
|
sc->sc_cfg3 = 0x4; /* Save residual byte. XXX??? */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": NCR53C94");
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_rev = NCR53C94;
|
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* This is the value used to start sync negotiations
|
|
|
|
* Note that the ESP register "SYNCTP" is programmed
|
|
|
|
* in "clocks per byte", and has a minimum value of 4.
|
|
|
|
* The SCSI period used in negotiation is one-fourth
|
|
|
|
* of the time (in nanoseconds) needed to transfer one byte.
|
|
|
|
* Since the chip's clock is given in MHz, we have the following
|
|
|
|
* formula: 4 * period = (1000 / freq) * 4
|
|
|
|
*/
|
|
|
|
sc->sc_minsync = 1000 / sc->sc_freq;
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* Alas, we must now modify the value a bit, because it's
|
|
|
|
* only valid when can switch on FASTCLK and FASTSCSI bits
|
|
|
|
* in config register 3...
|
|
|
|
*/
|
|
|
|
switch (sc->sc_rev) {
|
|
|
|
case ESP100:
|
1996-02-12 18:59:51 +03:00
|
|
|
sc->sc_maxxfer = 64 * 1024;
|
1995-11-29 01:49:31 +03:00
|
|
|
sc->sc_minsync = 0; /* No synch on old chip? */
|
|
|
|
break;
|
1995-11-28 23:49:12 +03:00
|
|
|
case ESP100A:
|
1996-02-12 18:59:51 +03:00
|
|
|
sc->sc_maxxfer = 64 * 1024;
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_minsync = esp_cpb2stp(sc, 5); /* Min clocks/byte is 5 */
|
|
|
|
break;
|
|
|
|
case ESP200:
|
1996-02-12 18:59:51 +03:00
|
|
|
sc->sc_maxxfer = 16 * 1024 * 1024;
|
1995-11-28 23:49:12 +03:00
|
|
|
/* XXX - do actually set FAST* bits */
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
sc->sc_maxxfer = 64 * 1024;
|
|
|
|
#endif
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
sc->sc_ccf = FREQTOCCF(sc->sc_freq);
|
|
|
|
|
|
|
|
/* The value *must not* be == 1. Make it 2 */
|
|
|
|
if (sc->sc_ccf == 1)
|
|
|
|
sc->sc_ccf = 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The recommended timeout is 250ms. This register is loaded
|
|
|
|
* with a value calculated as follows, from the docs:
|
|
|
|
*
|
|
|
|
* (timout period) x (CLK frequency)
|
|
|
|
* reg = -------------------------------------
|
|
|
|
* 8192 x (Clock Conversion Factor)
|
|
|
|
*
|
|
|
|
* Since CCF has a linear relation to CLK, this generally computes
|
|
|
|
* to the constant of 153.
|
|
|
|
*/
|
|
|
|
sc->sc_timeout = ((250 * 1000) * sc->sc_freq) / (8192 * sc->sc_ccf);
|
|
|
|
|
|
|
|
/* CCF register only has 3 bits; 0 is actually 8 */
|
|
|
|
sc->sc_ccf &= 7;
|
|
|
|
|
|
|
|
/* Reset state & bus */
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_state = 0;
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 1);
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" %dMhz, target %d\n", sc->sc_freq, sc->sc_id);
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
/* add me to the sbus structures */
|
|
|
|
sc->sc_sd.sd_reset = (void *) esp_reset;
|
1994-10-15 11:57:20 +03:00
|
|
|
#if defined(SUN4C) || defined(SUN4M)
|
1995-11-03 19:47:43 +03:00
|
|
|
if (ca->ca_bustype == BUS_SBUS) {
|
|
|
|
if (dmachild)
|
|
|
|
sbus_establish(&sc->sc_sd, sc->sc_dev.dv_parent);
|
|
|
|
else
|
|
|
|
sbus_establish(&sc->sc_sd, &sc->sc_dev);
|
|
|
|
}
|
1994-10-15 11:57:20 +03:00
|
|
|
#endif /* SUN4C || SUN4M */
|
1996-09-28 05:49:06 +04:00
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
/* and the interuppts */
|
|
|
|
sc->sc_ih.ih_fun = (void *) espintr;
|
1993-10-02 13:22:00 +03:00
|
|
|
sc->sc_ih.ih_arg = sc;
|
1994-09-18 03:48:32 +04:00
|
|
|
intr_establish(sc->sc_pri, &sc->sc_ih);
|
1994-05-27 06:38:15 +04:00
|
|
|
evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt);
|
1996-09-28 05:49:06 +04:00
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* fill in the prototype scsi_link.
|
|
|
|
*/
|
1996-08-28 22:59:15 +04:00
|
|
|
sc->sc_link.channel = SCSI_CHANNEL_ONLY_ONE;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_link.adapter_softc = sc;
|
1995-01-02 23:21:01 +03:00
|
|
|
sc->sc_link.adapter_target = sc->sc_id;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_link.adapter = &esp_switch;
|
|
|
|
sc->sc_link.device = &esp_dev;
|
1995-01-02 23:21:01 +03:00
|
|
|
sc->sc_link.openings = 2;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* If the boot path is "esp" at the moment and it's me, then
|
|
|
|
* walk our pointer to the sub-device, ready for the config
|
|
|
|
* below.
|
|
|
|
*/
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1994-09-18 03:48:32 +04:00
|
|
|
bp = ca->ca_ra.ra_bp;
|
1994-10-03 00:59:56 +03:00
|
|
|
switch (ca->ca_bustype) {
|
|
|
|
case BUS_SBUS:
|
|
|
|
if (bp != NULL && strcmp(bp->name, "esp") == 0 &&
|
|
|
|
SAME_ESP(sc, bp, ca))
|
1995-08-18 14:43:46 +04:00
|
|
|
bootpath_store(1, bp + 1);
|
1994-10-03 00:59:56 +03:00
|
|
|
break;
|
|
|
|
default:
|
1995-08-18 14:43:46 +04:00
|
|
|
if (bp != NULL && strcmp(bp->name, "esp") == 0 &&
|
|
|
|
bp->val[0] == -1 && bp->val[1] == sc->sc_dev.dv_unit)
|
|
|
|
bootpath_store(1, bp + 1);
|
1994-10-03 00:59:56 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try to attach all the sub-devices
|
|
|
|
*/
|
1996-08-28 22:59:15 +04:00
|
|
|
config_found(self, &sc->sc_link, scsiprint);
|
1995-08-18 14:43:46 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1995-08-18 14:43:46 +04:00
|
|
|
bootpath_store(1, NULL);
|
1996-09-28 05:49:06 +04:00
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* This is the generic esp reset function. It does not reset the SCSI bus,
|
|
|
|
* only this controllers, but kills any on-going commands, and also stops
|
|
|
|
* and resets the DMA.
|
|
|
|
*
|
|
|
|
* After reset, registers are loaded with the defaults from the attach
|
|
|
|
* routine above.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1996-04-01 02:38:29 +04:00
|
|
|
void
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_reset(sc)
|
|
|
|
struct esp_softc *sc;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
/* reset DMA first */
|
|
|
|
DMA_RESET(sc->sc_dma);
|
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
/* reset SCSI chip */
|
|
|
|
ESPCMD(sc, ESPCMD_RSTCHIP);
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_NOP);
|
|
|
|
DELAY(500);
|
|
|
|
|
|
|
|
/* do these backwards, and fall through */
|
|
|
|
switch (sc->sc_rev) {
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifndef SPARC_DRIVER
|
|
|
|
case NCR53C94:
|
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP200:
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG3, sc->sc_cfg3);
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP100A:
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG2, sc->sc_cfg2);
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP100:
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG1, sc->sc_cfg1);
|
|
|
|
ESP_WRITE_REG(sc, ESP_CCF, sc->sc_ccf);
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCOFF, 0);
|
|
|
|
ESP_WRITE_REG(sc, ESP_TIMEOUT, sc->sc_timeout);
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unknown revision code, assuming ESP100\n",
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_CFG1, sc->sc_cfg1);
|
|
|
|
ESP_WRITE_REG(sc, ESP_CCF, sc->sc_ccf);
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCOFF, 0);
|
|
|
|
ESP_WRITE_REG(sc, ESP_TIMEOUT, sc->sc_timeout);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Reset the SCSI bus, but not the chip
|
1994-05-27 06:38:15 +04:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
void
|
|
|
|
esp_scsi_reset(sc)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifdef SPARC_DRIVER
|
1995-11-03 19:47:43 +03:00
|
|
|
/* stop DMA first, as the chip will return to Bus Free phase */
|
|
|
|
DMACSR(sc->sc_dma) &= ~D_EN_DMA;
|
1996-09-28 05:49:06 +04:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* XXX STOP DMA FIRST
|
|
|
|
*/
|
|
|
|
#endif
|
1995-11-03 19:47:43 +03:00
|
|
|
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("esp: resetting SCSI bus\n");
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_RSTSCSI);
|
|
|
|
}
|
1994-05-27 06:38:15 +04:00
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Initialize esp state machine
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
void
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, doreset)
|
1993-10-02 13:22:00 +03:00
|
|
|
struct esp_softc *sc;
|
1994-11-05 12:35:54 +03:00
|
|
|
int doreset;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1994-09-18 03:48:32 +04:00
|
|
|
int r;
|
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[ESP_INIT(%d)] ", doreset));
|
1994-11-05 12:35:54 +03:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state == 0) {
|
|
|
|
/* First time through; initialize. */
|
1994-09-18 03:48:32 +04:00
|
|
|
TAILQ_INIT(&sc->ready_list);
|
|
|
|
TAILQ_INIT(&sc->nexus_list);
|
|
|
|
TAILQ_INIT(&sc->free_list);
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_nexus = NULL;
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb = sc->sc_ecb;
|
|
|
|
bzero(ecb, sizeof(sc->sc_ecb));
|
|
|
|
for (r = 0; r < sizeof(sc->sc_ecb) / sizeof(*ecb); r++) {
|
|
|
|
TAILQ_INSERT_TAIL(&sc->free_list, ecb, chain);
|
|
|
|
ecb++;
|
|
|
|
}
|
1994-11-21 04:56:38 +03:00
|
|
|
bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
|
1994-09-18 03:48:32 +04:00
|
|
|
} else {
|
1996-09-28 05:49:06 +04:00
|
|
|
/* Cancel any active commands. */
|
|
|
|
sc->sc_state = ESP_CLEANING;
|
|
|
|
if ((ecb = sc->sc_nexus) != NULL) {
|
|
|
|
ecb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
untimeout(esp_timeout, ecb);
|
|
|
|
esp_done(sc, ecb);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
while ((ecb = sc->nexus_list.tqh_first) != NULL) {
|
1996-09-28 05:49:06 +04:00
|
|
|
ecb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
untimeout(esp_timeout, ecb);
|
|
|
|
esp_done(sc, ecb);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* reset the chip to a known state
|
|
|
|
*/
|
|
|
|
esp_reset(sc);
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_phase = sc->sc_prevphase = INVALID_PHASE;
|
|
|
|
for (r = 0; r < 8; r++) {
|
1996-09-28 07:21:04 +04:00
|
|
|
struct esp_tinfo *ti = &sc->sc_tinfo[r];
|
1996-05-17 00:31:28 +04:00
|
|
|
/* XXX - config flags per target: low bits: no reselect; high bits: no synch */
|
|
|
|
int fl = sc->sc_dev.dv_cfdata->cf_flags;
|
1994-11-05 12:35:54 +03:00
|
|
|
|
1996-09-28 07:21:04 +04:00
|
|
|
ti->flags = ((sc->sc_minsync && !(fl & (1<<(r+8))))
|
1996-05-17 00:31:28 +04:00
|
|
|
? T_NEGOTIATE : 0) |
|
|
|
|
((fl & (1<<r)) ? T_RSELECTOFF : 0) |
|
1996-02-12 18:59:51 +03:00
|
|
|
T_NEED_TO_RESET;
|
1996-09-28 07:21:04 +04:00
|
|
|
ti->period = sc->sc_minsync;
|
|
|
|
ti->offset = 0;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
|
|
|
|
if (doreset) {
|
|
|
|
sc->sc_state = ESP_SBR;
|
|
|
|
ESPCMD(sc, ESPCMD_RSTSCSI);
|
1996-09-28 07:21:04 +04:00
|
|
|
} else {
|
|
|
|
sc->sc_state = ESP_IDLE;
|
1995-11-03 19:47:43 +03:00
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* Read the ESP registers, and save their contents for later use.
|
|
|
|
* ESP_STAT, ESP_STEP & ESP_INTR are mostly zeroed out when reading
|
|
|
|
* ESP_INTR - so make sure it is the last read.
|
|
|
|
*
|
|
|
|
* I think that (from reading the docs) most bits in these registers
|
|
|
|
* only make sense when he DMA CSR has an interrupt showing. Call only
|
|
|
|
* if an interrupt is pending.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
espreadregs(sc)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
{
|
|
|
|
|
1995-12-19 02:58:31 +03:00
|
|
|
sc->sc_espstat = ESP_READ_REG(sc, ESP_STAT);
|
1995-11-28 23:49:12 +03:00
|
|
|
/* Only the stepo bits are of interest */
|
1995-12-19 02:58:31 +03:00
|
|
|
sc->sc_espstep = ESP_READ_REG(sc, ESP_STEP) & ESPSTEP_MASK;
|
|
|
|
sc->sc_espintr = ESP_READ_REG(sc, ESP_INTR);
|
1996-09-28 05:49:06 +04:00
|
|
|
#ifndef SPARC_DRIVER
|
|
|
|
/* Clear the TCDS interrupt bit. */
|
|
|
|
(void)tcds_scsi_isintr(sc->sc_dma, 1);
|
|
|
|
#endif
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the SCSI bus phase, return either a real SCSI bus phase
|
|
|
|
* or some pseudo phase we use to detect certain exceptions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sc->sc_phase = (sc->sc_espintr & ESPINTR_DIS)
|
|
|
|
? /* Disconnected */ BUSFREE_PHASE
|
|
|
|
: sc->sc_espstat & ESPSTAT_PHASE;
|
|
|
|
|
|
|
|
ESP_MISC(("regs[intr=%02x,stat=%02x,step=%02x] ",
|
|
|
|
sc->sc_espintr, sc->sc_espstat, sc->sc_espstep));
|
|
|
|
}
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
/*
|
|
|
|
* Convert chip register Clock Per Byte value to Synchronous Transfer Period.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
esp_cpb2stp(sc, cpb)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
int cpb;
|
|
|
|
{
|
|
|
|
return ((250 * cpb) / sc->sc_freq);
|
|
|
|
}
|
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* Convert Synchronous Transfer Period to chip register Clock Per Byte value.
|
|
|
|
*/
|
1996-09-28 05:49:06 +04:00
|
|
|
static inline int
|
1995-11-28 23:49:12 +03:00
|
|
|
esp_stp2cpb(sc, period)
|
|
|
|
struct esp_softc *sc;
|
1996-03-14 22:44:30 +03:00
|
|
|
int period;
|
1995-11-28 23:49:12 +03:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
v = (sc->sc_freq * period) / 250;
|
|
|
|
if (esp_cpb2stp(sc, v) < period)
|
|
|
|
/* Correct round-down error */
|
|
|
|
v++;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
static inline void
|
|
|
|
esp_setsync(sc, ti)
|
1995-11-28 23:49:12 +03:00
|
|
|
struct esp_softc *sc;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_tinfo *ti;
|
1995-11-28 23:49:12 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
if (ti->flags & T_SYNCMODE) {
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCOFF, ti->offset);
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCTP, esp_stp2cpb(sc, ti->period));
|
|
|
|
} else {
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCOFF, 0);
|
|
|
|
ESP_WRITE_REG(sc, ESP_SYNCTP, 0);
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command to a target, set the driver state to ESP_SELECTING
|
|
|
|
* and let the caller take care of the rest.
|
|
|
|
*
|
|
|
|
* Keeping this as a function allows me to say that this may be done
|
|
|
|
* by DMA instead of programmed I/O soon.
|
|
|
|
*/
|
|
|
|
void
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_select(sc, ecb)
|
1995-11-28 23:49:12 +03:00
|
|
|
struct esp_softc *sc;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1995-11-28 23:49:12 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
struct scsi_link *sc_link = ecb->xs->sc_link;
|
|
|
|
int target = sc_link->target;
|
1995-11-28 23:49:12 +03:00
|
|
|
struct esp_tinfo *ti = &sc->sc_tinfo[target];
|
1996-09-28 05:49:06 +04:00
|
|
|
u_char *cmd;
|
|
|
|
int clen;
|
1995-11-28 23:49:12 +03:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
ESP_TRACE(("[esp_select(t%d,l%d,cmd:%x)] ", sc_link->target, sc_link->lun, ecb->cmd.opcode));
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
/* new state ESP_SELECTING */
|
|
|
|
sc->sc_state = ESP_SELECTING;
|
|
|
|
|
1996-02-12 18:59:51 +03:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* The docs say the target register is never reset, and I
|
|
|
|
* can't think of a better place to set it
|
|
|
|
*/
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_SELID, target);
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_setsync(sc, ti);
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Who am I. This is where we tell the target that we are
|
|
|
|
* happy for it to disconnect etc.
|
|
|
|
*/
|
1996-05-17 00:31:28 +04:00
|
|
|
ESP_WRITE_REG(sc, ESP_FIFO,
|
1996-09-28 05:49:06 +04:00
|
|
|
MSG_IDENTIFY(sc_link->lun, (ti->flags & T_RSELECTOFF)?0:1));
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
if (ti->flags & T_NEGOTIATE) {
|
|
|
|
/* Arbitrate, select and stop after IDENTIFY message */
|
|
|
|
ESPCMD(sc, ESPCMD_SELATNS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the command into the FIFO */
|
1996-09-28 05:49:06 +04:00
|
|
|
cmd = (u_char *)&ecb->cmd;
|
|
|
|
clen = ecb->clen;
|
|
|
|
while (clen--)
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_FIFO, *cmd++);
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
/* And get the targets attention */
|
|
|
|
ESPCMD(sc, ESPCMD_SELATN);
|
|
|
|
}
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
void
|
|
|
|
esp_free_ecb(sc, ecb, flags)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
ecb->flags = 0;
|
|
|
|
TAILQ_INSERT_HEAD(&sc->free_list, ecb, chain);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there were none, wake anybody waiting for one to come free,
|
|
|
|
* starting with queued entries.
|
|
|
|
*/
|
|
|
|
if (ecb->chain.tqe_next == 0)
|
|
|
|
wakeup(&sc->free_list);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct esp_ecb *
|
|
|
|
esp_get_ecb(sc, flags)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
while ((ecb = sc->free_list.tqh_first) == NULL &&
|
|
|
|
(flags & SCSI_NOSLEEP) == 0)
|
|
|
|
tsleep(&sc->free_list, PRIBIO, "especb", 0);
|
|
|
|
if (ecb) {
|
|
|
|
TAILQ_REMOVE(&sc->free_list, ecb, chain);
|
|
|
|
ecb->flags |= ECB_ALLOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return ecb;
|
|
|
|
}
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* DRIVER FUNCTIONS CALLABLE FROM HIGHER LEVEL DRIVERS
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* Start a SCSI-command
|
|
|
|
* This function is called by the higher level SCSI-driver to queue/run
|
|
|
|
* SCSI-commands.
|
|
|
|
*/
|
1996-04-01 02:38:29 +04:00
|
|
|
int
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_scsi_cmd(xs)
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
{
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct esp_softc *sc = sc_link->adapter_softc;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1994-09-18 03:48:32 +04:00
|
|
|
int s, flags;
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_scsi_cmd] "));
|
1996-04-01 02:38:29 +04:00
|
|
|
ESP_CMDS(("[0x%x, %d]->%d ", (int)xs->cmd->opcode, xs->cmdlen,
|
1994-09-18 03:48:32 +04:00
|
|
|
sc_link->target));
|
|
|
|
|
|
|
|
flags = xs->flags;
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((ecb = esp_get_ecb(sc, flags)) == NULL) {
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1994-09-18 03:48:32 +04:00
|
|
|
return TRY_AGAIN_LATER;
|
1994-05-27 06:38:15 +04:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
/* Initialize ecb */
|
|
|
|
ecb->xs = xs;
|
1996-09-28 05:49:06 +04:00
|
|
|
ecb->timeout = xs->timeout;
|
|
|
|
|
|
|
|
if (xs->flags & SCSI_RESET) {
|
|
|
|
ecb->flags |= ECB_RESET;
|
|
|
|
ecb->clen = 0;
|
|
|
|
ecb->dleft = 0;
|
|
|
|
} else {
|
|
|
|
bcopy(xs->cmd, &ecb->cmd, xs->cmdlen);
|
|
|
|
ecb->clen = xs->cmdlen;
|
|
|
|
ecb->daddr = xs->data;
|
|
|
|
ecb->dleft = xs->datalen;
|
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb->stat = 0;
|
1996-02-12 18:59:51 +03:00
|
|
|
|
1995-01-02 23:21:01 +03:00
|
|
|
s = splbio();
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->ready_list, ecb, chain);
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_state == ESP_IDLE)
|
|
|
|
esp_sched(sc);
|
|
|
|
|
1995-01-02 23:21:01 +03:00
|
|
|
splx(s);
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((flags & SCSI_POLL) == 0)
|
|
|
|
return SUCCESSFULLY_QUEUED;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
/* Not allowed to use interrupts, use polling instead */
|
|
|
|
if (esp_poll(sc, xs, ecb->timeout)) {
|
|
|
|
esp_timeout(ecb);
|
|
|
|
if (esp_poll(sc, xs, ecb->timeout))
|
|
|
|
esp_timeout(ecb);
|
|
|
|
}
|
|
|
|
return COMPLETE;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Used when interrupt driven I/O isn't allowed, e.g. during boot.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
int
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_poll(sc, xs, count)
|
1994-09-18 03:48:32 +04:00
|
|
|
struct esp_softc *sc;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
int count;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_poll] "));
|
1994-09-18 03:48:32 +04:00
|
|
|
while (count) {
|
|
|
|
if (DMA_ISINTR(sc->sc_dma)) {
|
|
|
|
espintr(sc);
|
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
#if alternatively
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_STAT) & ESPSTAT_INT)
|
1995-11-03 19:47:43 +03:00
|
|
|
espintr(sc);
|
|
|
|
#endif
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((xs->flags & ITSDONE) != 0)
|
|
|
|
return 0;
|
1995-06-02 17:43:30 +04:00
|
|
|
if (sc->sc_state == ESP_IDLE) {
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_poll: rescheduling] "));
|
1995-06-02 17:43:30 +04:00
|
|
|
esp_sched(sc);
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
DELAY(1000);
|
1994-09-18 03:48:32 +04:00
|
|
|
count--;
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
return 1;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1994-05-27 06:38:15 +04:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* LOW LEVEL SCSI UTILITIES
|
1994-05-27 06:38:15 +04:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1994-05-27 06:38:15 +04:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Schedule a scsi operation. This has now been pulled out of the interrupt
|
|
|
|
* handler so that we may call it from esp_scsi_cmd and esp_done. This may
|
|
|
|
* save us an unecessary interrupt just to get things going. Should only be
|
|
|
|
* called when state == ESP_IDLE and at bio pl.
|
1994-05-27 06:38:15 +04:00
|
|
|
*/
|
|
|
|
void
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_sched(sc)
|
|
|
|
struct esp_softc *sc;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1994-09-18 03:48:32 +04:00
|
|
|
struct scsi_link *sc_link;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_tinfo *ti;
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_sched] "));
|
|
|
|
if (sc->sc_state != ESP_IDLE)
|
|
|
|
panic("esp_sched: not IDLE (state=%d)", sc->sc_state);
|
|
|
|
|
1994-05-27 06:38:15 +04:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Find first ecb in ready queue that is for a target/lunit
|
|
|
|
* combinations that is not busy.
|
1994-05-27 06:38:15 +04:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
for (ecb = sc->ready_list.tqh_first; ecb; ecb = ecb->chain.tqe_next) {
|
|
|
|
sc_link = ecb->xs->sc_link;
|
1996-09-28 05:49:06 +04:00
|
|
|
ti = &sc->sc_tinfo[sc_link->target];
|
|
|
|
if ((ti->lubusy & (1 << sc_link->lun)) == 0) {
|
1994-09-18 03:48:32 +04:00
|
|
|
TAILQ_REMOVE(&sc->ready_list, ecb, chain);
|
|
|
|
sc->sc_nexus = ecb;
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_select(sc, ecb);
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
} else
|
1996-09-28 05:49:06 +04:00
|
|
|
ESP_MISC(("%d:%d busy\n",
|
|
|
|
sc_link->target, sc_link->lun));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
esp_sense(sc, ecb)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
{
|
|
|
|
struct scsi_xfer *xs = ecb->xs;
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct esp_tinfo *ti = &sc->sc_tinfo[sc_link->target];
|
|
|
|
struct scsi_sense *ss = (void *)&ecb->cmd;
|
|
|
|
|
|
|
|
ESP_MISC(("requesting sense "));
|
|
|
|
/* Next, setup a request sense command block */
|
|
|
|
bzero(ss, sizeof(*ss));
|
|
|
|
ss->opcode = REQUEST_SENSE;
|
|
|
|
ss->byte2 = sc_link->lun << 5;
|
|
|
|
ss->length = sizeof(struct scsi_sense_data);
|
|
|
|
ecb->clen = sizeof(*ss);
|
|
|
|
ecb->daddr = (char *)&xs->sense;
|
|
|
|
ecb->dleft = sizeof(struct scsi_sense_data);
|
|
|
|
ecb->flags |= ECB_SENSE;
|
|
|
|
ti->senses++;
|
|
|
|
if (ecb->flags & ECB_NEXUS)
|
|
|
|
ti->lubusy &= ~(1 << sc_link->lun);
|
|
|
|
if (ecb == sc->sc_nexus) {
|
|
|
|
esp_select(sc, ecb);
|
|
|
|
} else {
|
|
|
|
esp_dequeue(sc, ecb);
|
|
|
|
TAILQ_INSERT_HEAD(&sc->ready_list, ecb, chain);
|
|
|
|
if (sc->sc_state == ESP_IDLE)
|
|
|
|
esp_sched(sc);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* POST PROCESSING OF SCSI_CMD (usually current)
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
void
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_done(sc, ecb)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
struct esp_ecb *ecb;
|
1994-05-27 06:38:15 +04:00
|
|
|
{
|
1994-09-18 03:48:32 +04:00
|
|
|
struct scsi_xfer *xs = ecb->xs;
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
1995-10-24 19:03:57 +03:00
|
|
|
struct esp_tinfo *ti = &sc->sc_tinfo[sc_link->target];
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_done(error:%x)] ", xs->error));
|
1994-05-27 06:38:15 +04:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1996-04-01 02:38:29 +04:00
|
|
|
* Now, if we've come here with no error code, i.e. we've kept the
|
1994-09-18 03:48:32 +04:00
|
|
|
* initial XS_NOERROR, and the status code signals that we should
|
1996-04-01 02:38:29 +04:00
|
|
|
* check sense, we'll need to set up a request sense cmd block and
|
|
|
|
* push the command back into the ready queue *before* any other
|
1994-09-18 03:48:32 +04:00
|
|
|
* commands for this target/lunit, else we lose the sense info.
|
|
|
|
* We don't support chk sense conditions for the request sense cmd.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1995-10-24 19:03:57 +03:00
|
|
|
if (xs->error == XS_NOERROR) {
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((ecb->flags & ECB_ABORT) != 0) {
|
1996-09-28 07:21:04 +04:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-09-28 05:49:06 +04:00
|
|
|
} else if ((ecb->flags & ECB_SENSE) != 0) {
|
1995-10-24 19:03:57 +03:00
|
|
|
xs->error = XS_SENSE;
|
|
|
|
} else if ((ecb->stat & ST_MASK) == SCSI_CHECK) {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* First, save the return values */
|
|
|
|
xs->resid = ecb->dleft;
|
|
|
|
xs->status = ecb->stat;
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sense(sc, ecb);
|
1994-09-18 03:48:32 +04:00
|
|
|
return;
|
1995-10-24 19:03:57 +03:00
|
|
|
} else {
|
|
|
|
xs->resid = ecb->dleft;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
xs->flags |= ITSDONE;
|
|
|
|
|
1995-08-18 14:43:46 +04:00
|
|
|
#ifdef ESP_DEBUG
|
1994-09-18 03:48:32 +04:00
|
|
|
if (esp_debug & ESP_SHOWMISC) {
|
1996-09-28 05:49:06 +04:00
|
|
|
if (xs->resid != 0)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("resid=%d ", xs->resid);
|
1996-09-28 05:49:06 +04:00
|
|
|
if (xs->error == XS_SENSE)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("sense=0x%02x\n", xs->sense.error_code);
|
1996-09-28 05:49:06 +04:00
|
|
|
else
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("error=%d\n", xs->error);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
1995-10-24 19:03:57 +03:00
|
|
|
* Remove the ECB from whatever queue it's on.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1996-09-28 05:49:06 +04:00
|
|
|
if (ecb->flags & ECB_NEXUS)
|
|
|
|
ti->lubusy &= ~(1 << sc_link->lun);
|
|
|
|
if (ecb == sc->sc_nexus) {
|
1996-02-12 18:59:51 +03:00
|
|
|
sc->sc_nexus = NULL;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_state = ESP_IDLE;
|
|
|
|
esp_sched(sc);
|
1996-09-28 05:49:06 +04:00
|
|
|
} else
|
|
|
|
esp_dequeue(sc, ecb);
|
|
|
|
|
1996-09-28 07:21:04 +04:00
|
|
|
esp_free_ecb(sc, ecb, xs->flags);
|
1995-11-03 19:47:43 +03:00
|
|
|
ti->cmds++;
|
1994-09-18 03:48:32 +04:00
|
|
|
scsi_done(xs);
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
void
|
|
|
|
esp_dequeue(sc, ecb)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ecb->flags & ECB_NEXUS) {
|
|
|
|
TAILQ_REMOVE(&sc->nexus_list, ecb, chain);
|
|
|
|
} else {
|
|
|
|
TAILQ_REMOVE(&sc->ready_list, ecb, chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* INTERRUPT/PROTOCOL ENGINE
|
|
|
|
*/
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* Schedule an outgoing message by prioritizing it, and asserting
|
|
|
|
* attention on the bus. We can only do this when we are the initiator
|
|
|
|
* else there will be an illegal command interrupt.
|
|
|
|
*/
|
|
|
|
#define esp_sched_msgout(m) \
|
1996-09-28 05:49:06 +04:00
|
|
|
do { \
|
|
|
|
ESP_MISC(("esp_sched_msgout %d ", m)); \
|
|
|
|
ESPCMD(sc, ESPCMD_SETATN); \
|
|
|
|
sc->sc_flags |= ESP_ATN; \
|
|
|
|
sc->sc_msgpriq |= (m); \
|
1994-09-18 03:48:32 +04:00
|
|
|
} while (0)
|
|
|
|
|
1996-09-28 07:21:04 +04:00
|
|
|
int
|
|
|
|
esp_reselect(sc, message)
|
|
|
|
struct esp_softc *sc;
|
|
|
|
int message;
|
|
|
|
{
|
|
|
|
u_char selid, target, lun;
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
struct scsi_link *sc_link;
|
|
|
|
struct esp_tinfo *ti;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The SCSI chip made a snapshot of the data bus while the reselection
|
|
|
|
* was being negotiated. This enables us to determine which target did
|
|
|
|
* the reselect.
|
|
|
|
*/
|
|
|
|
selid = sc->sc_selid & ~(1 << sc->sc_id);
|
|
|
|
if (selid & (selid - 1)) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: reselect with invalid selid %02x; sending DEVICE RESET\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_dev.dv_xname, selid);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search wait queue for disconnected cmd
|
|
|
|
* The list should be short, so I haven't bothered with
|
|
|
|
* any more sophisticated structures than a simple
|
|
|
|
* singly linked list.
|
|
|
|
*/
|
|
|
|
target = ffs(selid) - 1;
|
|
|
|
lun = message & 0x07;
|
|
|
|
for (ecb = sc->nexus_list.tqh_first; ecb != NULL;
|
|
|
|
ecb = ecb->chain.tqe_next) {
|
|
|
|
sc_link = ecb->xs->sc_link;
|
|
|
|
if (sc_link->target == target && sc_link->lun == lun)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ecb == NULL) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: reselect from target %d lun %d with no nexus; sending ABORT\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_dev.dv_xname, target, lun);
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make this nexus active again. */
|
|
|
|
TAILQ_REMOVE(&sc->nexus_list, ecb, chain);
|
|
|
|
sc->sc_state = ESP_CONNECTED;
|
|
|
|
sc->sc_nexus = ecb;
|
|
|
|
ti = &sc->sc_tinfo[target];
|
|
|
|
ti->lubusy |= (1 << lun);
|
|
|
|
esp_setsync(sc, ti);
|
|
|
|
|
|
|
|
if (ecb->flags & ECB_RESET)
|
|
|
|
esp_sched_msgout(SEND_DEV_RESET);
|
|
|
|
else if (ecb->flags & ECB_ABORT)
|
|
|
|
esp_sched_msgout(SEND_ABORT);
|
|
|
|
|
|
|
|
/* Do an implicit RESTORE POINTERS. */
|
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
reset:
|
|
|
|
esp_sched_msgout(SEND_DEV_RESET);
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
abort:
|
|
|
|
esp_sched_msgout(SEND_ABORT);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
#define IS1BYTEMSG(m) (((m) != 1 && (m) < 0x20) || (m) & 0x80)
|
|
|
|
#define IS2BYTEMSG(m) (((m) & 0xf0) == 0x20)
|
|
|
|
#define ISEXTMSG(m) ((m) == 1)
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* Get an incoming message as initiator.
|
|
|
|
*
|
|
|
|
* The SCSI bus must already be in MESSAGE_IN_PHASE and there is a
|
|
|
|
* byte in the FIFO
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
esp_msgin(sc)
|
|
|
|
register struct esp_softc *sc;
|
|
|
|
{
|
1995-11-28 23:49:12 +03:00
|
|
|
register int v;
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_msgin(curmsglen:%d)] ", sc->sc_imlen));
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-12-19 02:58:31 +03:00
|
|
|
if ((ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) == 0) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: msgin: no msg byte available\n",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-09-18 03:48:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare for a new message. A message should (according
|
|
|
|
* to the SCSI standard) be transmitted in one single
|
|
|
|
* MESSAGE_IN_PHASE. If we have been in some other phase,
|
|
|
|
* then this is a new message.
|
|
|
|
*/
|
|
|
|
if (sc->sc_prevphase != MESSAGE_IN_PHASE) {
|
|
|
|
sc->sc_flags &= ~ESP_DROP_MSGI;
|
|
|
|
sc->sc_imlen = 0;
|
|
|
|
}
|
|
|
|
|
1995-12-19 02:58:31 +03:00
|
|
|
v = ESP_READ_REG(sc, ESP_FIFO);
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_MISC(("<msgbyte:0x%02x>", v));
|
|
|
|
|
|
|
|
#if 0
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_state == ESP_RESELECTED && sc->sc_imlen == 0) {
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Which target is reselecting us? (The ID bit really)
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_selid = v;
|
1994-09-18 03:48:32 +04:00
|
|
|
ESP_MISC(("selid=0x%2x ", sc->sc_selid));
|
1995-11-28 23:49:12 +03:00
|
|
|
return;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_imess[sc->sc_imlen] = v;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* If we're going to reject the message, don't bother storing
|
|
|
|
* the incoming bytes. But still, we need to ACK them.
|
|
|
|
*/
|
1995-11-03 19:47:43 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
if ((sc->sc_flags & ESP_DROP_MSGI)) {
|
|
|
|
ESPCMD(sc, ESPCMD_MSGOK);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("<dropping msg byte %x>",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_imess[sc->sc_imlen]);
|
|
|
|
return;
|
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
if (sc->sc_imlen >= ESP_MAX_MSG_LEN) {
|
|
|
|
esp_sched_msgout(SEND_REJECT);
|
|
|
|
sc->sc_flags |= ESP_DROP_MSGI;
|
|
|
|
} else {
|
|
|
|
sc->sc_imlen++;
|
1996-04-01 02:38:29 +04:00
|
|
|
/*
|
1995-11-28 23:49:12 +03:00
|
|
|
* This testing is suboptimal, but most
|
|
|
|
* messages will be of the one byte variety, so
|
|
|
|
* it should not effect performance
|
|
|
|
* significantly.
|
|
|
|
*/
|
|
|
|
if (sc->sc_imlen == 1 && IS1BYTEMSG(sc->sc_imess[0]))
|
|
|
|
goto gotit;
|
|
|
|
if (sc->sc_imlen == 2 && IS2BYTEMSG(sc->sc_imess[0]))
|
|
|
|
goto gotit;
|
|
|
|
if (sc->sc_imlen >= 3 && ISEXTMSG(sc->sc_imess[0]) &&
|
|
|
|
sc->sc_imlen == sc->sc_imess[1] + 2)
|
|
|
|
goto gotit;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
/* Ack what we have so far */
|
|
|
|
ESPCMD(sc, ESPCMD_MSGOK);
|
|
|
|
return;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
gotit:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("gotmsg(%x)", sc->sc_imess[0]));
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Now we should have a complete message (1 byte, 2 byte
|
|
|
|
* and moderately long extended messages). We only handle
|
|
|
|
* extended messages which total length is shorter than
|
|
|
|
* ESP_MAX_MSG_LEN. Longer messages will be amputated.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1996-09-28 07:21:04 +04:00
|
|
|
switch (sc->sc_state) {
|
|
|
|
struct esp_ecb *ecb;
|
|
|
|
struct esp_tinfo *ti;
|
|
|
|
|
|
|
|
case ESP_CONNECTED:
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->target];
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
switch (sc->sc_imess[0]) {
|
|
|
|
case MSG_CMDCOMPLETE:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("cmdcomplete "));
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_dleft < 0) {
|
|
|
|
struct scsi_link *sc_link = ecb->xs->sc_link;
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: %d extra bytes from %d:%d\n",
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_dev.dv_xname, -sc->sc_dleft,
|
|
|
|
sc_link->target, sc_link->lun);
|
1995-08-18 14:43:46 +04:00
|
|
|
sc->sc_dleft = 0;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
ecb->xs->resid = ecb->dleft = sc->sc_dleft;
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_state = ESP_CMDCOMPLETE;
|
1995-11-03 19:47:43 +03:00
|
|
|
break;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
case MSG_MESSAGE_REJECT:
|
1995-11-03 19:47:43 +03:00
|
|
|
if (esp_debug & ESP_SHOWMSGS)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: our msg rejected by target\n",
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 07:21:04 +04:00
|
|
|
switch (sc->sc_msgout) {
|
|
|
|
case SEND_SDTR:
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_flags &= ~ESP_SYNCHNEGO;
|
1996-09-28 05:49:06 +04:00
|
|
|
ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
|
|
|
|
esp_setsync(sc, ti);
|
1996-09-28 07:21:04 +04:00
|
|
|
break;
|
|
|
|
case SEND_INIT_DET_ERR:
|
|
|
|
goto abort;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case MSG_NOOP:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("noop "));
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case MSG_DISCONNECT:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("disconnect "));
|
1994-09-18 03:48:32 +04:00
|
|
|
ti->dconns++;
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_state = ESP_DISCONNECT;
|
1996-02-23 02:35:04 +03:00
|
|
|
if ((ecb->xs->sc_link->quirks & SDEV_AUTOSAVE) == 0)
|
|
|
|
break;
|
|
|
|
/*FALLTHROUGH*/
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case MSG_SAVEDATAPOINTER:
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_MSGS(("save datapointer "));
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb->daddr = sc->sc_dp;
|
1996-09-28 07:21:04 +04:00
|
|
|
ecb->dleft = sc->sc_dleft;
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case MSG_RESTOREPOINTERS:
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_MSGS(("restore datapointer "));
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case MSG_EXTENDED:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("extended(%x) ", sc->sc_imess[2]));
|
1994-09-18 03:48:32 +04:00
|
|
|
switch (sc->sc_imess[2]) {
|
|
|
|
case MSG_EXT_SDTR:
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_MSGS(("SDTR period %d, offset %d ",
|
|
|
|
sc->sc_imess[3], sc->sc_imess[4]));
|
1996-09-28 07:21:04 +04:00
|
|
|
if (sc->sc_imess[1] != 3)
|
|
|
|
goto reject;
|
1994-09-18 03:48:32 +04:00
|
|
|
ti->period = sc->sc_imess[3];
|
|
|
|
ti->offset = sc->sc_imess[4];
|
1996-09-28 07:21:04 +04:00
|
|
|
ti->flags &= ~T_NEGOTIATE;
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_minsync == 0 ||
|
|
|
|
ti->offset == 0 ||
|
|
|
|
ti->period > 124) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s:%d: async\n", "esp",
|
1995-11-28 23:49:12 +03:00
|
|
|
ecb->xs->sc_link->target);
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((sc->sc_flags&ESP_SYNCHNEGO) == 0) {
|
1996-09-28 07:21:04 +04:00
|
|
|
/* target initiated negotiation */
|
1996-09-28 05:49:06 +04:00
|
|
|
ti->offset = 0;
|
1996-09-28 07:21:04 +04:00
|
|
|
ti->flags &= ~T_SYNCMODE;
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sched_msgout(SEND_SDTR);
|
|
|
|
} else {
|
1996-09-28 07:21:04 +04:00
|
|
|
/* we are async */
|
1996-09-28 05:49:06 +04:00
|
|
|
ti->flags &= ~T_SYNCMODE;
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
} else {
|
|
|
|
int r = 250/ti->period;
|
|
|
|
int s = (100*250)/ti->period - 100*r;
|
|
|
|
int p;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
p = esp_stp2cpb(sc, ti->period);
|
|
|
|
ti->period = esp_cpb2stp(sc, p);
|
1996-02-26 17:48:30 +03:00
|
|
|
#ifdef ESP_DEBUG
|
|
|
|
sc_print_addr(ecb->xs->sc_link);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("max sync rate %d.%02dMb/s\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
r, s);
|
1996-02-26 17:48:30 +03:00
|
|
|
#endif
|
1995-11-28 23:49:12 +03:00
|
|
|
if ((sc->sc_flags&ESP_SYNCHNEGO) == 0) {
|
1996-09-28 07:21:04 +04:00
|
|
|
/* target initiated negotiation */
|
1996-05-31 02:19:10 +04:00
|
|
|
if (ti->period < sc->sc_minsync)
|
|
|
|
ti->period = sc->sc_minsync;
|
|
|
|
if (ti->offset > 15)
|
|
|
|
ti->offset = 15;
|
1996-09-28 07:21:04 +04:00
|
|
|
ti->flags &= ~T_SYNCMODE;
|
1995-11-28 23:49:12 +03:00
|
|
|
esp_sched_msgout(SEND_SDTR);
|
|
|
|
} else {
|
|
|
|
/* we are sync */
|
|
|
|
ti->flags |= T_SYNCMODE;
|
1996-02-26 17:48:30 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_flags &= ~ESP_SYNCHNEGO;
|
|
|
|
esp_setsync(sc, ti);
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unrecognized MESSAGE EXTENDED; sending REJECT\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto reject;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
break;
|
1996-09-28 07:21:04 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
default:
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_MSGS(("ident "));
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unrecognized MESSAGE; sending REJECT\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
reject:
|
|
|
|
esp_sched_msgout(SEND_REJECT);
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1994-05-27 06:38:15 +04:00
|
|
|
}
|
1996-09-28 07:21:04 +04:00
|
|
|
break;
|
1994-05-27 06:38:15 +04:00
|
|
|
|
1996-09-28 07:21:04 +04:00
|
|
|
case ESP_RESELECTED:
|
|
|
|
if (!MSG_ISIDENTIFY(sc->sc_imess[0])) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: reselect without IDENTIFY; sending DEVICE RESET\n",
|
1996-09-28 07:21:04 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto reset;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1996-09-28 07:21:04 +04:00
|
|
|
|
|
|
|
(void) esp_reselect(sc, sc->sc_imess[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unexpected MESSAGE IN; sending DEVICE RESET\n",
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 07:21:04 +04:00
|
|
|
reset:
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_sched_msgout(SEND_DEV_RESET);
|
1996-09-28 07:21:04 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
esp_sched_msgout(SEND_ABORT);
|
|
|
|
break;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
/* Ack last message byte */
|
|
|
|
ESPCMD(sc, ESPCMD_MSGOK);
|
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
/* Done, reset message pointer. */
|
|
|
|
sc->sc_flags &= ~ESP_DROP_MSGI;
|
|
|
|
sc->sc_imlen = 0;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* Send the highest priority, scheduled message
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
void
|
|
|
|
esp_msgout(sc)
|
|
|
|
register struct esp_softc *sc;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1994-09-18 03:48:32 +04:00
|
|
|
struct esp_tinfo *ti;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1996-02-12 18:59:51 +03:00
|
|
|
size_t size;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[esp_msgout(priq:%x, prevphase:%x)]", sc->sc_msgpriq, sc->sc_prevphase));
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_flags & ESP_ATN) {
|
|
|
|
if (sc->sc_prevphase != MESSAGE_OUT_PHASE) {
|
|
|
|
new:
|
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
sc->sc_msgoutq = 0;
|
|
|
|
sc->sc_omlen = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_prevphase == MESSAGE_OUT_PHASE) {
|
|
|
|
esp_sched_msgout(sc->sc_msgoutq);
|
|
|
|
goto new;
|
|
|
|
} else {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("esp at line %d: unexpected MESSAGE OUT phase\n", __LINE__);
|
1996-09-28 05:49:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_omlen == 0) {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* Pick up highest priority message */
|
|
|
|
sc->sc_msgout = sc->sc_msgpriq & -sc->sc_msgpriq;
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_msgoutq |= sc->sc_msgout;
|
|
|
|
sc->sc_msgpriq &= ~sc->sc_msgout;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_omlen = 1; /* "Default" message len */
|
|
|
|
switch (sc->sc_msgout) {
|
1995-11-28 23:49:12 +03:00
|
|
|
case SEND_SDTR:
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->target];
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_omess[0] = MSG_EXTENDED;
|
|
|
|
sc->sc_omess[1] = 3;
|
|
|
|
sc->sc_omess[2] = MSG_EXT_SDTR;
|
|
|
|
sc->sc_omess[3] = ti->period;
|
|
|
|
sc->sc_omess[4] = ti->offset;
|
|
|
|
sc->sc_omlen = 5;
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((sc->sc_flags & ESP_SYNCHNEGO) == 0) {
|
|
|
|
ti->flags |= T_SYNCMODE;
|
|
|
|
esp_setsync(sc, ti);
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
break;
|
1994-09-18 03:48:32 +04:00
|
|
|
case SEND_IDENTIFY:
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state != ESP_CONNECTED) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("esp at line %d: no nexus\n", __LINE__);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb = sc->sc_nexus;
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_omess[0] = MSG_IDENTIFY(ecb->xs->sc_link->lun,0);
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
1994-09-18 03:48:32 +04:00
|
|
|
case SEND_DEV_RESET:
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_flags |= ESP_ABORTING;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_omess[0] = MSG_BUS_DEV_RESET;
|
1995-11-28 23:49:12 +03:00
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->target];
|
|
|
|
ti->flags &= ~T_SYNCMODE;
|
|
|
|
ti->flags |= T_NEGOTIATE;
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
case SEND_PARITY_ERROR:
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_omess[0] = MSG_PARITY_ERROR;
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
case SEND_ABORT:
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_flags |= ESP_ABORTING;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_omess[0] = MSG_ABORT;
|
|
|
|
break;
|
|
|
|
case SEND_INIT_DET_ERR:
|
|
|
|
sc->sc_omess[0] = MSG_INITIATOR_DET_ERR;
|
|
|
|
break;
|
|
|
|
case SEND_REJECT:
|
|
|
|
sc->sc_omess[0] = MSG_MESSAGE_REJECT;
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
default:
|
1996-09-28 05:49:06 +04:00
|
|
|
ESPCMD(sc, ESPCMD_RSTATN);
|
|
|
|
sc->sc_flags &= ~ESP_ATN;
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_omess[0] = MSG_NOOP;
|
|
|
|
break;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_omp = sc->sc_omess;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
#if 1
|
1994-09-18 03:48:32 +04:00
|
|
|
/* (re)send the message */
|
1996-02-12 18:59:51 +03:00
|
|
|
size = min(sc->sc_omlen, sc->sc_maxxfer);
|
|
|
|
DMA_SETUP(sc->sc_dma, &sc->sc_omp, &sc->sc_omlen, 0, &size);
|
|
|
|
/* Program the SCSI counter */
|
|
|
|
ESP_WRITE_REG(sc, ESP_TCL, size);
|
|
|
|
ESP_WRITE_REG(sc, ESP_TCM, size >> 8);
|
1996-06-12 23:12:19 +04:00
|
|
|
if (sc->sc_cfg2 & ESPCFG2_FE) {
|
1996-02-12 18:59:51 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_TCH, size >> 16);
|
|
|
|
}
|
|
|
|
/* load the count in */
|
|
|
|
ESPCMD(sc, ESPCMD_NOP|ESPCMD_DMA);
|
1996-09-28 05:49:06 +04:00
|
|
|
ESPCMD(sc, ESPCMD_TRANS|ESPCMD_DMA);
|
1996-02-12 18:59:51 +03:00
|
|
|
DMA_GO(sc->sc_dma);
|
1995-11-28 23:49:12 +03:00
|
|
|
#else
|
|
|
|
{ int i;
|
|
|
|
for (i = 0; i < sc->sc_omlen; i++)
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, FIFO, sc->sc_omess[i]);
|
1995-11-28 23:49:12 +03:00
|
|
|
ESPCMD(sc, ESPCMD_TRANS);
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_omlen = 0;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* This is the most critical part of the driver, and has to know
|
|
|
|
* how to deal with *all* error conditions and phases from the SCSI
|
|
|
|
* bus. If there are no errors and the DMA was active, then call the
|
|
|
|
* DMA pseudo-interrupt handler. If this returns 1, then that was it
|
|
|
|
* and we can return from here without further processing.
|
|
|
|
*
|
|
|
|
* Most of this needs verifying.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1996-04-01 02:38:29 +04:00
|
|
|
int
|
1994-09-18 03:48:32 +04:00
|
|
|
espintr(sc)
|
|
|
|
register struct esp_softc *sc;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
register struct esp_ecb *ecb;
|
1994-09-18 03:48:32 +04:00
|
|
|
register struct scsi_link *sc_link;
|
|
|
|
struct esp_tinfo *ti;
|
|
|
|
int loop;
|
1996-02-12 18:59:51 +03:00
|
|
|
size_t size;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
ESP_TRACE(("[espintr]"));
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1994-05-27 06:38:15 +04:00
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* I have made some (maybe seriously flawed) assumptions here,
|
1996-10-13 06:59:38 +04:00
|
|
|
* but basic testing (uncomment the printf() below), show that
|
1994-09-18 03:48:32 +04:00
|
|
|
* certainly something happens when this loop is here.
|
|
|
|
*
|
|
|
|
* The idea is that many of the SCSI operations take very little
|
|
|
|
* time, and going away and getting interrupted is too high an
|
|
|
|
* overhead to pay. For example, selecting, sending a message
|
|
|
|
* and command and then doing some work can be done in one "pass".
|
|
|
|
*
|
|
|
|
* The DELAY is not variable because I do not understand that the
|
|
|
|
* DELAY loop should be fixed-time regardless of CPU speed, but
|
|
|
|
* I am *assuming* that the faster SCSI processors get things done
|
|
|
|
* quicker (sending a command byte etc), and so there is no
|
|
|
|
* need to be too slow.
|
|
|
|
*
|
|
|
|
* This is a heuristic. It is 2 when at 20Mhz, 2 at 25Mhz and 1
|
|
|
|
* at 40Mhz. This needs testing.
|
1994-05-27 06:38:15 +04:00
|
|
|
*/
|
1994-11-05 12:35:54 +03:00
|
|
|
for (loop = 0; 1;loop++, DELAY(50/sc->sc_freq)) {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* a feeling of deja-vu */
|
1995-10-24 19:03:57 +03:00
|
|
|
if (!DMA_ISINTR(sc->sc_dma))
|
|
|
|
return (loop != 0);
|
1994-09-18 03:48:32 +04:00
|
|
|
#if 0
|
|
|
|
if (loop)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("*");
|
1994-09-18 03:48:32 +04:00
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/* and what do the registers say... */
|
|
|
|
espreadregs(sc);
|
|
|
|
|
|
|
|
sc->sc_intrcnt.ev_count++;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
1994-09-18 03:48:32 +04:00
|
|
|
* At the moment, only a SCSI Bus Reset or Illegal
|
1995-11-28 23:49:12 +03:00
|
|
|
* Command are classed as errors. A disconnect is a
|
1994-09-18 03:48:32 +04:00
|
|
|
* valid condition, and we let the code check is the
|
|
|
|
* "ESP_BUSFREE_OK" flag was set before declaring it
|
|
|
|
* and error.
|
|
|
|
*
|
|
|
|
* Also, the status register tells us about "Gross
|
|
|
|
* Errors" and "Parity errors". Only the Gross Error
|
|
|
|
* is really bad, and the parity errors are dealt
|
|
|
|
* with later
|
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
* If there are too many parity error, go to slow
|
|
|
|
* cable mode ?
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
/* SCSI Reset */
|
|
|
|
if (sc->sc_espintr & ESPINTR_SBR) {
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) {
|
1995-11-03 19:47:43 +03:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
if (sc->sc_state != ESP_SBR) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: SCSI bus reset\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 0); /* Restart everything */
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
#if 0
|
1996-10-13 06:59:38 +04:00
|
|
|
/*XXX*/ printf("<expected bus reset: "
|
1995-11-28 23:49:12 +03:00
|
|
|
"[intr %x, stat %x, step %d]>\n",
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
1995-11-03 19:47:43 +03:00
|
|
|
#endif
|
|
|
|
if (sc->sc_nexus)
|
|
|
|
panic("%s: nexus in reset state",
|
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 05:49:06 +04:00
|
|
|
goto sched;
|
1995-11-03 19:47:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
|
|
|
|
#define ESPINTR_ERR (ESPINTR_SBR|ESPINTR_ILL)
|
|
|
|
if (sc->sc_espintr & ESPINTR_ERR ||
|
|
|
|
sc->sc_espstat & ESPSTAT_GE) {
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_espstat & ESPSTAT_GE) {
|
|
|
|
/* no target ? */
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) {
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state == ESP_CONNECTED ||
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_state == ESP_SELECTING) {
|
1994-09-18 03:48:32 +04:00
|
|
|
ecb->xs->error = XS_DRIVER_STUFFUP;
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_done(sc, ecb);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_espintr & ESPINTR_ILL) {
|
|
|
|
/* illegal command, out of sync ? */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: illegal command: 0x%x (state %d, phase %x, prevphase %x)\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_lastcmd,
|
1996-04-01 02:38:29 +04:00
|
|
|
sc->sc_state, sc->sc_phase,
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_prevphase);
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) {
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
esp_init(sc, 0); /* Restart everything */
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* Call if DMA is active.
|
|
|
|
*
|
|
|
|
* If DMA_INTR returns true, then maybe go 'round the loop
|
|
|
|
* again in case there is no more DMA queued, but a phase
|
|
|
|
* change is expected.
|
|
|
|
*/
|
1996-02-12 18:59:51 +03:00
|
|
|
if (DMA_ISACTIVE(sc->sc_dma)) {
|
|
|
|
DMA_INTR(sc->sc_dma);
|
1994-09-18 03:48:32 +04:00
|
|
|
/* If DMA active here, then go back to work... */
|
1996-02-12 18:59:51 +03:00
|
|
|
if (DMA_ISACTIVE(sc->sc_dma))
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
1996-02-12 18:59:51 +03:00
|
|
|
|
|
|
|
if (sc->sc_dleft == 0 &&
|
|
|
|
(sc->sc_espstat & ESPSTAT_TC) == 0)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: !TC [intr %x, stat %x, step %d]"
|
1996-02-12 18:59:51 +03:00
|
|
|
" prevphase %x, resid %x\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr,
|
|
|
|
sc->sc_espstat,
|
|
|
|
sc->sc_espstep,
|
|
|
|
sc->sc_prevphase,
|
|
|
|
ecb?ecb->dleft:-1);
|
|
|
|
}
|
|
|
|
|
1996-02-26 17:48:30 +03:00
|
|
|
#if 0 /* Unreliable on some ESP revisions? */
|
1996-02-12 18:59:51 +03:00
|
|
|
if ((sc->sc_espstat & ESPSTAT_INT) == 0) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: spurious interrupt\n", sc->sc_dev.dv_xname);
|
1996-02-12 18:59:51 +03:00
|
|
|
return 1;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1996-02-26 17:48:30 +03:00
|
|
|
#endif
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/*
|
|
|
|
* check for less serious errors
|
|
|
|
*/
|
|
|
|
if (sc->sc_espstat & ESPSTAT_PE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: SCSI bus parity error\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_prevphase == MESSAGE_IN_PHASE)
|
|
|
|
esp_sched_msgout(SEND_PARITY_ERROR);
|
1996-04-01 02:38:29 +04:00
|
|
|
else
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_sched_msgout(SEND_INIT_DET_ERR);
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
if (sc->sc_espintr & ESPINTR_DIS) {
|
1996-02-12 18:59:51 +03:00
|
|
|
ESP_MISC(("<DISC [intr %x, stat %x, step %d]>",
|
|
|
|
sc->sc_espintr,sc->sc_espstat,sc->sc_espstep));
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) {
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* This command must (apparently) be issued within
|
|
|
|
* 250mS of a disconnect. So here you are...
|
|
|
|
*/
|
|
|
|
ESPCMD(sc, ESPCMD_ENSEL);
|
1996-09-28 05:49:06 +04:00
|
|
|
switch (sc->sc_state) {
|
|
|
|
case ESP_RESELECTED:
|
|
|
|
goto sched;
|
|
|
|
|
|
|
|
case ESP_SELECTING:
|
|
|
|
ecb->xs->error = XS_SELTIMEOUT;
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
case ESP_CONNECTED:
|
1995-11-28 23:49:12 +03:00
|
|
|
if ((sc->sc_flags & ESP_SYNCHNEGO)) {
|
1996-03-05 12:29:58 +03:00
|
|
|
#ifdef ESP_DEBUG
|
|
|
|
if (ecb)
|
|
|
|
sc_print_addr(ecb->xs->sc_link);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("sync nego not completed!\n");
|
1996-03-05 12:29:58 +03:00
|
|
|
#endif
|
1996-09-28 05:49:06 +04:00
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->target];
|
1996-03-05 12:29:58 +03:00
|
|
|
sc->sc_flags &= ~ESP_SYNCHNEGO;
|
1996-09-28 05:49:06 +04:00
|
|
|
ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
/* it may be OK to disconnect */
|
1996-09-28 05:49:06 +04:00
|
|
|
if ((sc->sc_flags & ESP_ABORTING) == 0) {
|
|
|
|
/*
|
|
|
|
* Section 5.1.1 of the SCSI 2 spec
|
|
|
|
* suggests issuing a REQUEST SENSE
|
|
|
|
* following an unexpected disconnect.
|
|
|
|
* Some devices go into a contingent
|
|
|
|
* allegiance condition when
|
|
|
|
* disconnecting, and this is necessary
|
|
|
|
* to clean up their state.
|
|
|
|
*/
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unexpected disconnect; ",
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (ecb->flags & ECB_SENSE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("resetting\n");
|
1996-09-28 05:49:06 +04:00
|
|
|
goto reset;
|
1996-02-26 17:48:30 +03:00
|
|
|
}
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("sending REQUEST SENSE\n");
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sense(sc, ecb);
|
|
|
|
goto out;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
ecb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
case ESP_DISCONNECT:
|
|
|
|
TAILQ_INSERT_HEAD(&sc->nexus_list, ecb, chain);
|
|
|
|
sc->sc_nexus = NULL;
|
|
|
|
goto sched;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
case ESP_CMDCOMPLETE:
|
|
|
|
goto finish;
|
1996-03-05 12:29:58 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (sc->sc_state) {
|
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
case ESP_SBR:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: waiting for SCSI Bus Reset to happen\n",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 1;
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP_RESELECTED:
|
|
|
|
/*
|
|
|
|
* we must be continuing a message ?
|
|
|
|
*/
|
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: target didn't identify\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 1);
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("<<RESELECT CONT'd>>");
|
1995-11-28 23:49:12 +03:00
|
|
|
#if XXXX
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_msgin(sc);
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state != ESP_CONNECTED) {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* IDENTIFY fail?! */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: identify failed\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 1);
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
#endif
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP_IDLE:
|
1996-10-13 06:59:38 +04:00
|
|
|
if (sc->sc_flags & ESP_ICCS) printf("[[esp: BUMMER]]");
|
1994-09-18 03:48:32 +04:00
|
|
|
case ESP_SELECTING:
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_msgpriq = sc->sc_msgout = sc->sc_msgoutq = 0;
|
|
|
|
sc->sc_flags = 0;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
|
|
|
if (sc->sc_espintr & ESPINTR_RESEL) {
|
|
|
|
/*
|
|
|
|
* If we're trying to select a
|
|
|
|
* target ourselves, push our command
|
|
|
|
* back into the ready list.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state == ESP_SELECTING) {
|
|
|
|
ESP_MISC(("backoff selector "));
|
1995-11-28 23:49:12 +03:00
|
|
|
sc_link = sc->sc_nexus->xs->sc_link;
|
|
|
|
ti = &sc->sc_tinfo[sc_link->target];
|
1994-09-18 03:48:32 +04:00
|
|
|
TAILQ_INSERT_HEAD(&sc->ready_list,
|
|
|
|
sc->sc_nexus, chain);
|
1995-11-28 23:49:12 +03:00
|
|
|
ecb = sc->sc_nexus = NULL;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
sc->sc_state = ESP_RESELECTED;
|
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE) {
|
|
|
|
/*
|
|
|
|
* Things are seriously fucked up.
|
|
|
|
* Pull the brakes, i.e. reset
|
|
|
|
*/
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: target didn't identify\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 1);
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-12-19 02:58:31 +03:00
|
|
|
if ((ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) != 2) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: RESELECT: %d bytes in FIFO!\n",
|
1996-02-06 05:03:46 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ESP_READ_REG(sc, ESP_FFLAG) &
|
|
|
|
ESPFIFO_FF);
|
|
|
|
esp_init(sc, 1);
|
|
|
|
return 1;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
1995-12-19 02:58:31 +03:00
|
|
|
sc->sc_selid = ESP_READ_REG(sc, ESP_FIFO);
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_MISC(("selid=0x%2x ", sc->sc_selid));
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_msgin(sc); /* Handle identify message */
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state != ESP_CONNECTED) {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* IDENTIFY fail?! */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: identify failed\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1994-11-05 12:35:54 +03:00
|
|
|
esp_init(sc, 1);
|
1994-09-18 03:48:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
continue; /* ie. next phase expected soon */
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ESPINTR_DONE (ESPINTR_FC|ESPINTR_BS)
|
|
|
|
if ((sc->sc_espintr & ESPINTR_DONE) == ESPINTR_DONE) {
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
if (!ecb)
|
|
|
|
panic("esp: not nexus at sc->sc_nexus");
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
sc_link = ecb->xs->sc_link;
|
|
|
|
ti = &sc->sc_tinfo[sc_link->target];
|
|
|
|
|
1995-11-03 19:47:43 +03:00
|
|
|
switch (sc->sc_espstep) {
|
|
|
|
case 0:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: select timeout/no disconnect\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 05:49:06 +04:00
|
|
|
ecb->xs->error = XS_SELTIMEOUT;
|
|
|
|
goto finish;
|
1995-11-03 19:47:43 +03:00
|
|
|
case 1:
|
1995-11-28 23:49:12 +03:00
|
|
|
if ((ti->flags & T_NEGOTIATE) == 0) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: step 1 & !NEG\n",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 05:49:06 +04:00
|
|
|
goto reset;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
if (sc->sc_phase != MESSAGE_OUT_PHASE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: !MSGOUT\n",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1996-09-28 05:49:06 +04:00
|
|
|
goto reset;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
|
|
|
/* Start negotiating */
|
|
|
|
ti->period = sc->sc_minsync;
|
|
|
|
ti->offset = 15;
|
1996-02-26 17:48:30 +03:00
|
|
|
sc->sc_flags |= ESP_SYNCHNEGO;
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sched_msgout(SEND_SDTR);
|
1995-11-28 23:49:12 +03:00
|
|
|
break;
|
1995-11-03 19:47:43 +03:00
|
|
|
case 3:
|
1995-11-28 23:49:12 +03:00
|
|
|
/*
|
|
|
|
* Grr, this is supposed to mean
|
|
|
|
* "target left command phase
|
|
|
|
* prematurely". It seems to happen
|
|
|
|
* regularly when sync mode is on.
|
|
|
|
* Look at FIFO to see if command
|
|
|
|
* went out.
|
|
|
|
* (Timing problems?)
|
|
|
|
*/
|
1995-12-19 02:58:31 +03:00
|
|
|
if ((ESP_READ_REG(sc, ESP_FFLAG)&ESPFIFO_FF) == 0) {
|
1995-11-28 23:49:12 +03:00
|
|
|
/* Hope for the best.. */
|
|
|
|
break;
|
|
|
|
}
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("(%s:%d:%d): selection failed;"
|
1995-11-28 23:49:12 +03:00
|
|
|
" %d left in FIFO "
|
|
|
|
"[intr %x, stat %x, step %d]\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
1995-11-28 23:49:12 +03:00
|
|
|
sc_link->target,
|
|
|
|
sc_link->lun,
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF,
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
1996-02-12 18:59:51 +03:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
1995-11-28 23:49:12 +03:00
|
|
|
esp_sched_msgout(SEND_ABORT);
|
1995-11-03 19:47:43 +03:00
|
|
|
return 1;
|
|
|
|
case 2:
|
|
|
|
/* Select stuck at Command Phase */
|
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
case 4:
|
|
|
|
/* So far, everything went fine */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 0
|
1994-09-18 03:48:32 +04:00
|
|
|
if (ecb->xs->flags & SCSI_RESET)
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sched_msgout(SEND_DEV_RESET);
|
1995-11-28 23:49:12 +03:00
|
|
|
else if (ti->flags & T_NEGOTIATE)
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sched_msgout(
|
|
|
|
SEND_IDENTIFY | SEND_SDTR);
|
1994-09-18 03:48:32 +04:00
|
|
|
else
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_sched_msgout(SEND_IDENTIFY);
|
1995-11-03 19:47:43 +03:00
|
|
|
#endif
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
ecb->flags |= ECB_NEXUS;
|
|
|
|
ti->lubusy |= (1 << sc_link->lun);
|
|
|
|
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_prevphase = INVALID_PHASE; /* ?? */
|
1996-09-28 07:21:04 +04:00
|
|
|
/* Do an implicit RESTORE POINTERS. */
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
/* On our first connection, schedule a timeout. */
|
|
|
|
if ((ecb->xs->flags & SCSI_POLL) == 0)
|
|
|
|
timeout(esp_timeout, ecb, (ecb->timeout * hz) / 1000);
|
|
|
|
|
|
|
|
sc->sc_state = ESP_CONNECTED;
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
1995-11-28 23:49:12 +03:00
|
|
|
} else {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unexpected status after select"
|
1995-11-28 23:49:12 +03:00
|
|
|
": [intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
1996-09-28 05:49:06 +04:00
|
|
|
goto reset;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
if (sc->sc_state == ESP_IDLE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: stray interrupt\n", sc->sc_dev.dv_xname);
|
1995-11-28 23:49:12 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1994-09-18 03:48:32 +04:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
case ESP_CONNECTED:
|
1995-11-28 23:49:12 +03:00
|
|
|
if (sc->sc_flags & ESP_ICCS) {
|
1996-09-28 07:21:04 +04:00
|
|
|
u_char msg;
|
1995-11-28 23:49:12 +03:00
|
|
|
|
|
|
|
sc->sc_flags &= ~ESP_ICCS;
|
|
|
|
|
|
|
|
if (!(sc->sc_espintr & ESPINTR_DONE)) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: ICCS: "
|
1995-11-28 23:49:12 +03:00
|
|
|
": [intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
1995-12-19 02:58:31 +03:00
|
|
|
if ((ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) != 2) {
|
1996-09-28 07:21:04 +04:00
|
|
|
int i = (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) - 2;
|
|
|
|
while (i--)
|
|
|
|
(void) ESP_READ_REG(sc, ESP_FIFO);
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
1995-12-19 02:58:31 +03:00
|
|
|
ecb->stat = ESP_READ_REG(sc, ESP_FIFO);
|
|
|
|
msg = ESP_READ_REG(sc, ESP_FIFO);
|
1995-11-28 23:49:12 +03:00
|
|
|
ESP_PHASE(("<stat:(%x,%x)>", ecb->stat, msg));
|
|
|
|
if (msg == MSG_CMDCOMPLETE) {
|
|
|
|
ecb->xs->resid = ecb->dleft = sc->sc_dleft;
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_state = ESP_CMDCOMPLETE;
|
1995-11-28 23:49:12 +03:00
|
|
|
} else
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: STATUS_PHASE: msg %d\n",
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_dev.dv_xname, msg);
|
|
|
|
ESPCMD(sc, ESPCMD_MSGOK);
|
|
|
|
continue; /* ie. wait for disconnect */
|
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
default:
|
1995-11-03 19:47:43 +03:00
|
|
|
panic("%s: invalid state: %d",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_state);
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
1996-09-28 05:49:06 +04:00
|
|
|
* Driver is now in state ESP_CONNECTED, i.e. we
|
1994-09-18 03:48:32 +04:00
|
|
|
* have a current command working the SCSI bus.
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
1996-09-28 05:49:06 +04:00
|
|
|
if (sc->sc_state != ESP_CONNECTED || ecb == NULL) {
|
1994-09-18 03:48:32 +04:00
|
|
|
panic("esp no nexus");
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
switch (sc->sc_phase) {
|
|
|
|
case MESSAGE_OUT_PHASE:
|
|
|
|
ESP_PHASE(("MESSAGE_OUT_PHASE "));
|
|
|
|
esp_msgout(sc);
|
|
|
|
sc->sc_prevphase = MESSAGE_OUT_PHASE;
|
|
|
|
break;
|
|
|
|
case MESSAGE_IN_PHASE:
|
|
|
|
ESP_PHASE(("MESSAGE_IN_PHASE "));
|
1995-11-28 23:49:12 +03:00
|
|
|
if (sc->sc_espintr & ESPINTR_BS) {
|
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
sc->sc_flags |= ESP_WAITI;
|
|
|
|
ESPCMD(sc, ESPCMD_TRANS);
|
|
|
|
} else if (sc->sc_espintr & ESPINTR_FC) {
|
|
|
|
if ((sc->sc_flags & ESP_WAITI) == 0) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: MSGIN: unexpected FC bit: "
|
1995-11-28 23:49:12 +03:00
|
|
|
"[intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
|
|
|
sc->sc_flags &= ~ESP_WAITI;
|
|
|
|
esp_msgin(sc);
|
|
|
|
} else {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: MSGIN: weird bits: "
|
1995-11-28 23:49:12 +03:00
|
|
|
"[intr %x, stat %x, step %x]\n",
|
1995-11-03 19:47:43 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_prevphase = MESSAGE_IN_PHASE;
|
|
|
|
break;
|
1995-11-28 23:49:12 +03:00
|
|
|
case COMMAND_PHASE: {
|
1994-09-18 03:48:32 +04:00
|
|
|
/* well, this means send the command again */
|
1995-11-28 23:49:12 +03:00
|
|
|
u_char *cmd = (u_char *)&ecb->cmd;
|
|
|
|
int i;
|
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
ESP_PHASE(("COMMAND_PHASE 0x%02x (%d) ",
|
|
|
|
ecb->cmd.opcode, ecb->clen));
|
1995-12-19 02:58:31 +03:00
|
|
|
if (ESP_READ_REG(sc, ESP_FFLAG) & ESPFIFO_FF) {
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
|
|
|
DELAY(1);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1995-11-28 23:49:12 +03:00
|
|
|
/* Now the command into the FIFO */
|
|
|
|
for (i = 0; i < ecb->clen; i++)
|
1995-12-19 02:58:31 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_FIFO, *cmd++);
|
1995-11-28 23:49:12 +03:00
|
|
|
ESPCMD(sc, ESPCMD_TRANS);
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_prevphase = COMMAND_PHASE;
|
1995-11-28 23:49:12 +03:00
|
|
|
}
|
1994-09-18 03:48:32 +04:00
|
|
|
break;
|
|
|
|
case DATA_OUT_PHASE:
|
|
|
|
ESP_PHASE(("DATA_OUT_PHASE [%d] ", sc->sc_dleft));
|
1995-08-18 14:43:46 +04:00
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
1996-02-12 18:59:51 +03:00
|
|
|
size = min(sc->sc_dleft, sc->sc_maxxfer);
|
|
|
|
DMA_SETUP(sc->sc_dma, &sc->sc_dp, &sc->sc_dleft,
|
|
|
|
0, &size);
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_prevphase = DATA_OUT_PHASE;
|
1996-02-12 18:59:51 +03:00
|
|
|
goto setup_xfer;
|
1994-09-18 03:48:32 +04:00
|
|
|
case DATA_IN_PHASE:
|
|
|
|
ESP_PHASE(("DATA_IN_PHASE "));
|
1995-11-28 23:49:12 +03:00
|
|
|
if (sc->sc_rev == ESP100)
|
|
|
|
ESPCMD(sc, ESPCMD_FLUSH);
|
1996-02-12 18:59:51 +03:00
|
|
|
size = min(sc->sc_dleft, sc->sc_maxxfer);
|
|
|
|
DMA_SETUP(sc->sc_dma, &sc->sc_dp, &sc->sc_dleft,
|
|
|
|
1, &size);
|
1994-09-18 03:48:32 +04:00
|
|
|
sc->sc_prevphase = DATA_IN_PHASE;
|
1996-02-12 18:59:51 +03:00
|
|
|
setup_xfer:
|
|
|
|
/* Program the SCSI counter */
|
|
|
|
ESP_WRITE_REG(sc, ESP_TCL, size);
|
|
|
|
ESP_WRITE_REG(sc, ESP_TCM, size >> 8);
|
1996-06-12 23:12:19 +04:00
|
|
|
if (sc->sc_cfg2 & ESPCFG2_FE) {
|
1996-02-12 18:59:51 +03:00
|
|
|
ESP_WRITE_REG(sc, ESP_TCH, size >> 16);
|
|
|
|
}
|
|
|
|
/* load the count in */
|
|
|
|
ESPCMD(sc, ESPCMD_NOP|ESPCMD_DMA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that if `size' is 0, we've already transceived
|
|
|
|
* all the bytes we want but we're still in DATA PHASE.
|
|
|
|
* Apparently, the device needs padding. Also, a
|
|
|
|
* transfer size of 0 means "maximum" to the chip
|
|
|
|
* DMA logic.
|
|
|
|
*/
|
|
|
|
ESPCMD(sc,
|
|
|
|
(size==0?ESPCMD_TRPAD:ESPCMD_TRANS)|ESPCMD_DMA);
|
|
|
|
DMA_GO(sc->sc_dma);
|
1995-11-28 23:49:12 +03:00
|
|
|
return 1;
|
1994-09-18 03:48:32 +04:00
|
|
|
case STATUS_PHASE:
|
|
|
|
ESP_PHASE(("STATUS_PHASE "));
|
1995-11-28 23:49:12 +03:00
|
|
|
sc->sc_flags |= ESP_ICCS;
|
1994-09-18 03:48:32 +04:00
|
|
|
ESPCMD(sc, ESPCMD_ICCS);
|
|
|
|
sc->sc_prevphase = STATUS_PHASE;
|
|
|
|
break;
|
|
|
|
case INVALID_PHASE:
|
|
|
|
break;
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: unexpected bus phase; resetting\n",
|
1996-09-28 05:49:06 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto reset;
|
1994-09-18 03:48:32 +04:00
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1995-11-03 19:47:43 +03:00
|
|
|
panic("esp: should not get here..");
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
reset:
|
|
|
|
esp_init(sc, 1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
finish:
|
|
|
|
untimeout(esp_timeout, ecb);
|
|
|
|
esp_done(sc, ecb);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sched:
|
|
|
|
sc->sc_state = ESP_IDLE;
|
|
|
|
esp_sched(sc);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return 1;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
1995-10-24 19:03:57 +03:00
|
|
|
void
|
|
|
|
esp_abort(sc, ecb)
|
|
|
|
struct esp_softc *sc;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb;
|
1995-10-24 19:03:57 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
|
|
|
|
/* 2 secs for the abort */
|
|
|
|
ecb->timeout = ESP_ABORT_TIMEOUT;
|
|
|
|
ecb->flags |= ECB_ABORT;
|
|
|
|
|
1995-10-24 19:03:57 +03:00
|
|
|
if (ecb == sc->sc_nexus) {
|
1996-09-28 05:49:06 +04:00
|
|
|
/*
|
|
|
|
* If we're still selecting, the message will be scheduled
|
|
|
|
* after selection is complete.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state == ESP_CONNECTED)
|
1995-10-24 19:03:57 +03:00
|
|
|
esp_sched_msgout(SEND_ABORT);
|
|
|
|
} else {
|
1996-09-28 05:49:06 +04:00
|
|
|
esp_dequeue(sc, ecb);
|
|
|
|
TAILQ_INSERT_HEAD(&sc->ready_list, ecb, chain);
|
1995-10-24 19:03:57 +03:00
|
|
|
if (sc->sc_state == ESP_IDLE)
|
|
|
|
esp_sched(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
void
|
1994-09-18 03:48:32 +04:00
|
|
|
esp_timeout(arg)
|
|
|
|
void *arg;
|
1993-10-02 13:22:00 +03:00
|
|
|
{
|
1996-09-28 05:49:06 +04:00
|
|
|
struct esp_ecb *ecb = arg;
|
1996-04-01 02:38:29 +04:00
|
|
|
struct scsi_xfer *xs = ecb->xs;
|
1996-09-28 05:49:06 +04:00
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct esp_softc *sc = sc_link->adapter_softc;
|
|
|
|
int s;
|
1995-10-24 19:03:57 +03:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
sc_print_addr(sc_link);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: timed out [ecb %p (flags 0x%x, dleft %x, stat %x)], "
|
1996-03-14 22:44:30 +03:00
|
|
|
"<state %d, nexus %p, phase(c %x, p %x), resid %x, msg(q %x,o %x) %s>",
|
1996-02-12 18:59:51 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ecb, ecb->flags, ecb->dleft, ecb->stat,
|
|
|
|
sc->sc_state, sc->sc_nexus, sc->sc_phase, sc->sc_prevphase,
|
1996-02-26 17:48:30 +03:00
|
|
|
sc->sc_dleft, sc->sc_msgpriq, sc->sc_msgout,
|
|
|
|
DMA_ISACTIVE(sc->sc_dma) ? "DMA active" : "");
|
1996-02-12 18:59:51 +03:00
|
|
|
#if ESP_DEBUG > 0
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("TRACE: %s.", ecb->trace);
|
1996-02-12 18:59:51 +03:00
|
|
|
#endif
|
1995-10-24 19:03:57 +03:00
|
|
|
|
1996-09-28 05:49:06 +04:00
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
if (ecb->flags & ECB_ABORT) {
|
1995-10-24 19:03:57 +03:00
|
|
|
/* abort timed out */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" AGAIN\n");
|
1995-11-03 19:47:43 +03:00
|
|
|
esp_init(sc, 1);
|
1995-10-24 19:03:57 +03:00
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("\n");
|
1995-10-24 19:03:57 +03:00
|
|
|
xs->error = XS_TIMEOUT;
|
|
|
|
esp_abort(sc, ecb);
|
|
|
|
}
|
1996-09-28 05:49:06 +04:00
|
|
|
|
1994-09-18 03:48:32 +04:00
|
|
|
splx(s);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|