2001-03-29 06:58:38 +04:00
|
|
|
/* $NetBSD: ncr53c9x.c,v 1.71 2001/03/29 02:58:39 petrov Exp $ */
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-08-15 14:51:16 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
1997-02-27 04:12:07 +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:
|
1998-08-15 14:51:16 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1997-02-27 04:12:07 +03:00
|
|
|
*
|
1998-08-15 14:51:16 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Peter Galbavy
|
|
|
|
* Copyright (c) 1995 Paul Kranenburg
|
|
|
|
* 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 Peter Galbavy
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1997-02-27 04:12:07 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/buf.h>
|
1998-05-04 15:11:24 +04:00
|
|
|
#include <sys/malloc.h>
|
2000-12-01 07:37:54 +03:00
|
|
|
#include <sys/proc.h>
|
1997-02-27 04:12:07 +03:00
|
|
|
#include <sys/queue.h>
|
2000-11-30 03:19:25 +03:00
|
|
|
#include <sys/pool.h>
|
2000-11-13 18:24:22 +03:00
|
|
|
#include <sys/scsiio.h>
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
#include <dev/scsipi/scsi_message.h>
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
#include <dev/ic/ncr53c9xreg.h>
|
|
|
|
#include <dev/ic/ncr53c9xvar.h>
|
|
|
|
|
|
|
|
int ncr53c9x_debug = 0; /*NCR_SHOWPHASE|NCR_SHOWMISC|NCR_SHOWTRAC|NCR_SHOWCMDS;*/
|
2000-11-30 03:19:25 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
int ncr53c9x_notag = 0;
|
|
|
|
#endif
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-12-01 02:12:43 +03:00
|
|
|
/*static*/ void ncr53c9x_readregs(struct ncr53c9x_softc *);
|
|
|
|
/*static*/ void ncr53c9x_select(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
|
|
|
|
/*static*/ int ncr53c9x_reselect(struct ncr53c9x_softc *, int, int, int);
|
|
|
|
/*static*/ void ncr53c9x_scsi_reset(struct ncr53c9x_softc *);
|
|
|
|
/*static*/ int ncr53c9x_poll(struct ncr53c9x_softc *,
|
|
|
|
struct scsipi_xfer *, int);
|
|
|
|
/*static*/ void ncr53c9x_sched(struct ncr53c9x_softc *);
|
|
|
|
/*static*/ void ncr53c9x_done(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
|
|
|
|
/*static*/ void ncr53c9x_msgin(struct ncr53c9x_softc *);
|
|
|
|
/*static*/ void ncr53c9x_msgout(struct ncr53c9x_softc *);
|
|
|
|
/*static*/ void ncr53c9x_timeout(void *arg);
|
|
|
|
/*static*/ void ncr53c9x_watch(void *arg);
|
|
|
|
/*static*/ void ncr53c9x_abort(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
|
|
|
|
/*static*/ void ncr53c9x_dequeue(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
|
|
|
|
/*static*/ int ncr53c9x_ioctl(struct scsipi_link *, u_long,
|
|
|
|
caddr_t, int, struct proc *);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-12-01 02:12:43 +03:00
|
|
|
void ncr53c9x_sense(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
|
|
|
|
void ncr53c9x_free_ecb(struct ncr53c9x_softc *, struct ncr53c9x_ecb *, int);
|
|
|
|
struct ncr53c9x_ecb *ncr53c9x_get_ecb(struct ncr53c9x_softc *, int);
|
|
|
|
|
|
|
|
static inline int ncr53c9x_stp2cpb(struct ncr53c9x_softc *, int);
|
|
|
|
static inline void ncr53c9x_setsync(struct ncr53c9x_softc *,
|
|
|
|
struct ncr53c9x_tinfo *);
|
|
|
|
static struct ncr53c9x_linfo *ncr53c9x_lunsearch(struct ncr53c9x_tinfo *,
|
|
|
|
int64_t lun);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
static void ncr53c9x_wrfifo(struct ncr53c9x_softc *, u_char *, int);
|
|
|
|
|
|
|
|
static int ncr53c9x_rdfifo(struct ncr53c9x_softc *, int);
|
|
|
|
#define NCR_RDFIFO_START 0
|
|
|
|
#define NCR_RDFIFO_CONTINUE 1
|
|
|
|
|
|
|
|
|
|
|
|
#define NCR_SET_COUNT(sc, size) do { \
|
|
|
|
NCR_WRITE_REG((sc), NCR_TCL, (size)); \
|
|
|
|
NCR_WRITE_REG((sc), NCR_TCM, (size) >> 8); \
|
|
|
|
if ((sc->sc_cfg2 & NCRCFG2_FE) || \
|
|
|
|
(sc->sc_rev == NCR_VARIANT_FAS366)) { \
|
|
|
|
NCR_WRITE_REG((sc), NCR_TCH, (size) >> 16); \
|
|
|
|
} \
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) { \
|
|
|
|
NCR_WRITE_REG(sc, NCR_RCH, 0); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
static int ecb_pool_initialized = 0;
|
|
|
|
static struct pool ecb_pool;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Names for the NCR53c9x variants, correspnding to the variant tags
|
|
|
|
* in ncr53c9xvar.h.
|
|
|
|
*/
|
2000-06-05 11:59:50 +04:00
|
|
|
static const char *ncr53c9x_variant_names[] = {
|
1997-02-27 04:12:07 +03:00
|
|
|
"ESP100",
|
|
|
|
"ESP100A",
|
|
|
|
"ESP200",
|
|
|
|
"NCR53C94",
|
1997-02-27 16:59:32 +03:00
|
|
|
"NCR53C96",
|
1997-05-02 02:16:24 +04:00
|
|
|
"ESP406",
|
|
|
|
"FAS408",
|
1997-10-04 07:59:00 +04:00
|
|
|
"FAS216",
|
1999-01-06 22:19:38 +03:00
|
|
|
"AM53C974",
|
2001-03-29 06:58:38 +04:00
|
|
|
"FAS366/HME",
|
1997-02-27 04:12:07 +03:00
|
|
|
};
|
|
|
|
|
2000-06-05 11:59:50 +04:00
|
|
|
static struct scsipi_adapter ncr53c9x_adapter = {
|
|
|
|
0, /* adapter refcnt */
|
|
|
|
ncr53c9x_scsi_cmd, /* cmd */
|
|
|
|
minphys, /* minphys */
|
2000-11-13 18:24:22 +03:00
|
|
|
ncr53c9x_ioctl, /* ioctl */
|
2000-06-05 19:19:42 +04:00
|
|
|
NULL, /* enable */
|
2000-06-05 11:59:50 +04:00
|
|
|
NULL, /* getgeom */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct scsipi_device ncr53c9x_device = {
|
|
|
|
NULL, /* use default error handler */
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL, /* use default 'done' routine */
|
|
|
|
};
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
/*
|
|
|
|
* Search linked list for LUN info by LUN id.
|
|
|
|
*/
|
|
|
|
static struct ncr53c9x_linfo *
|
|
|
|
ncr53c9x_lunsearch(ti, lun)
|
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
int64_t lun;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
LIST_FOREACH(li, &ti->luns, link)
|
|
|
|
if (li->lun == lun)
|
|
|
|
return (li);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* Attach this instance, and then all the sub-devices
|
|
|
|
*/
|
|
|
|
void
|
2000-06-05 11:59:50 +04:00
|
|
|
ncr53c9x_attach(sc, adapter, device)
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_softc *sc;
|
2000-06-05 11:59:50 +04:00
|
|
|
struct scsipi_adapter *adapter;
|
|
|
|
struct scsipi_device *device;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
callout_init(&sc->sc_watchdog);
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
1998-05-04 15:11:24 +04:00
|
|
|
* Allocate SCSI message buffers.
|
|
|
|
* Front-ends can override allocation to avoid alignment
|
|
|
|
* handling in the DMA engines. Note that that ncr53c9x_msgout()
|
|
|
|
* can request a 1 byte DMA transfer.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1998-05-04 15:11:24 +04:00
|
|
|
if (sc->sc_omess == NULL)
|
|
|
|
sc->sc_omess = malloc(NCR_MAX_MSG_LEN, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (sc->sc_imess == NULL)
|
|
|
|
sc->sc_imess = malloc(NCR_MAX_MSG_LEN+1, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (sc->sc_omess == NULL || sc->sc_imess == NULL) {
|
|
|
|
printf("out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 15:11:24 +04:00
|
|
|
/*
|
|
|
|
* Note, the front-end has set us up to print the chip variation.
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_rev >= NCR_VARIANT_MAX) {
|
|
|
|
printf("\n%s: unknown variant %d, devices not attached\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_rev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(": %s, %dMHz, SCSI ID %d\n",
|
|
|
|
ncr53c9x_variant_names[sc->sc_rev], sc->sc_freq, sc->sc_id);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
1997-08-27 15:22:52 +04:00
|
|
|
* fill in the prototype scsipi_link.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1997-08-27 15:22:52 +04:00
|
|
|
sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_link.adapter_softc = sc;
|
1997-08-27 15:22:52 +04:00
|
|
|
sc->sc_link.scsipi_scsi.adapter_target = sc->sc_id;
|
2000-06-05 11:59:50 +04:00
|
|
|
sc->sc_link.adapter = (adapter) ? adapter : &ncr53c9x_adapter;
|
|
|
|
sc->sc_link.device = (device) ? device : &ncr53c9x_device;
|
2001-01-20 02:04:23 +03:00
|
|
|
sc->sc_link.openings = 2;
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_link.scsipi_scsi.max_target = 7; /* XXX fas has 16(not supported) */
|
1998-12-05 22:43:33 +03:00
|
|
|
sc->sc_link.scsipi_scsi.max_lun = 7;
|
1997-08-27 15:22:52 +04:00
|
|
|
sc->sc_link.type = BUS_SCSI;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/*
|
2000-03-20 00:25:49 +03:00
|
|
|
* Add reference to adapter so that we drop the reference after
|
|
|
|
* config_found() to make sure the adatper is disabled.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
2000-03-20 00:25:49 +03:00
|
|
|
if (scsipi_adapter_addref(&sc->sc_link) != 0) {
|
|
|
|
printf("%s: unable to enable controller\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset state & bus */
|
|
|
|
sc->sc_cfflags = sc->sc_dev.dv_cfdata->cf_flags;
|
|
|
|
sc->sc_state = 0;
|
|
|
|
ncr53c9x_init(sc, 1);
|
1997-05-02 02:16:24 +04:00
|
|
|
|
|
|
|
/*
|
2000-03-20 00:25:49 +03:00
|
|
|
* Now try to attach all the sub-devices
|
1997-05-02 02:16:24 +04:00
|
|
|
*/
|
2000-03-20 00:25:49 +03:00
|
|
|
sc->sc_child = config_found(&sc->sc_dev, &sc->sc_link, scsiprint);
|
|
|
|
|
|
|
|
scsipi_adapter_delref(&sc->sc_link);
|
2000-11-30 03:19:25 +03:00
|
|
|
callout_reset(&sc->sc_watchdog, 60*hz, ncr53c9x_watch, sc);
|
2000-03-20 00:25:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncr53c9x_detach(sc, flags)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->sc_child) {
|
|
|
|
error = config_detach(sc->sc_child, flags);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(sc->sc_imess, M_DEVBUF);
|
|
|
|
free(sc->sc_omess, M_DEVBUF);
|
1998-05-04 15:11:24 +04:00
|
|
|
|
2000-03-20 00:25:49 +03:00
|
|
|
return (0);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-11-30 10:44:24 +03:00
|
|
|
* This is the generic ncr53c9x reset function. It does not reset the SCSI bus,
|
|
|
|
* only this controller, but kills any on-going commands, and also stops
|
1997-02-27 04:12:07 +03:00
|
|
|
* and resets the DMA.
|
|
|
|
*
|
|
|
|
* After reset, registers are loaded with the defaults from the attach
|
|
|
|
* routine above.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_reset(sc)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* reset DMA first */
|
|
|
|
NCRDMA_RESET(sc);
|
|
|
|
|
|
|
|
/* reset SCSI chip */
|
|
|
|
NCRCMD(sc, NCRCMD_RSTCHIP);
|
|
|
|
NCRCMD(sc, NCRCMD_NOP);
|
|
|
|
DELAY(500);
|
|
|
|
|
|
|
|
/* do these backwards, and fall through */
|
|
|
|
switch (sc->sc_rev) {
|
1997-05-02 02:16:24 +04:00
|
|
|
case NCR_VARIANT_ESP406:
|
|
|
|
case NCR_VARIANT_FAS408:
|
2000-03-20 03:49:42 +03:00
|
|
|
NCR_WRITE_REG(sc, NCR_CFG5, sc->sc_cfg5 | NCRCFG5_SINT);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG4, sc->sc_cfg4);
|
1999-01-06 22:19:38 +03:00
|
|
|
case NCR_VARIANT_AM53C974:
|
1997-10-04 07:59:00 +04:00
|
|
|
case NCR_VARIANT_FAS216:
|
1997-02-27 04:12:07 +03:00
|
|
|
case NCR_VARIANT_NCR53C94:
|
1997-02-27 16:59:32 +03:00
|
|
|
case NCR_VARIANT_NCR53C96:
|
1997-02-27 04:12:07 +03:00
|
|
|
case NCR_VARIANT_ESP200:
|
1998-05-27 03:17:34 +04:00
|
|
|
sc->sc_features |= NCR_F_HASCFG3;
|
1997-02-27 04:12:07 +03:00
|
|
|
NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
|
|
|
|
case NCR_VARIANT_ESP100A:
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
|
|
|
|
case NCR_VARIANT_ESP100:
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
|
|
|
|
NCR_WRITE_REG(sc, NCR_SYNCOFF, 0);
|
|
|
|
NCR_WRITE_REG(sc, NCR_TIMEOUT, sc->sc_timeout);
|
|
|
|
break;
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
case NCR_VARIANT_FAS366:
|
|
|
|
sc->sc_features |= NCR_F_HASCFG3 | NCR_F_FASTSCSI;
|
|
|
|
sc->sc_cfg3 = NCRFASCFG3_FASTCLK | NCRFASCFG3_OBAUTO;
|
|
|
|
sc->sc_cfg3_fscsi = NCRFASCFG3_FASTSCSI;
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
|
|
|
|
sc->sc_cfg2 = 0; /* NCRCFG2_HMEFE| NCRCFG2_HME32 */
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
|
|
|
|
NCR_WRITE_REG(sc, NCR_SYNCOFF, 0);
|
|
|
|
NCR_WRITE_REG(sc, NCR_TIMEOUT, sc->sc_timeout);
|
|
|
|
break;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
default:
|
|
|
|
printf("%s: unknown revision code, assuming ESP100\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
|
|
|
|
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
|
|
|
|
NCR_WRITE_REG(sc, NCR_SYNCOFF, 0);
|
|
|
|
NCR_WRITE_REG(sc, NCR_TIMEOUT, sc->sc_timeout);
|
|
|
|
}
|
1999-01-06 22:19:38 +03:00
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_AM53C974)
|
2000-03-20 08:48:28 +03:00
|
|
|
NCR_WRITE_REG(sc, NCR_AMDCFG4, sc->sc_cfg4);
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("%s: ncr53c9x_reset: revision %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_rev);
|
|
|
|
printf("%s: ncr53c9x_reset: cfg1 0x%x, cfg2 0x%x, cfg3 0x%x, ccf 0x%x, timeout 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_cfg1, sc->sc_cfg2, sc->sc_cfg3,
|
|
|
|
sc->sc_ccf, sc->sc_timeout);
|
|
|
|
#endif
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the SCSI bus, but not the chip
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_scsi_reset(sc)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
(*sc->sc_glue->gl_dma_stop)(sc);
|
|
|
|
|
|
|
|
printf("%s: resetting SCSI bus\n", sc->sc_dev.dv_xname);
|
|
|
|
NCRCMD(sc, NCRCMD_RSTSCSI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-11-30 10:44:24 +03:00
|
|
|
* Initialize ncr53c9x state machine
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_init(sc, doreset)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
int doreset;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int i, r;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_TRACE(("[NCR_INIT(%d) %d] ", doreset, sc->sc_state));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
if (!ecb_pool_initialized) {
|
|
|
|
/* All instances share this pool */
|
|
|
|
pool_init(&ecb_pool, sizeof(struct ncr53c9x_ecb), 0, 0, 0,
|
|
|
|
"ncr53c9x_ecb", 0, NULL, NULL, 0);
|
|
|
|
ecb_pool_initialized = 1;
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state == 0) {
|
|
|
|
/* First time through; initialize. */
|
2000-11-30 03:19:25 +03:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
TAILQ_INIT(&sc->ready_list);
|
|
|
|
sc->sc_nexus = NULL;
|
|
|
|
bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
|
2000-12-01 02:01:03 +03:00
|
|
|
for (r = 0; r < NCR_NTARG; r++) {
|
2000-11-30 03:19:25 +03:00
|
|
|
LIST_INIT(&sc->sc_tinfo[r].luns);
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
} else {
|
|
|
|
/* Cancel any active commands. */
|
|
|
|
sc->sc_state = NCR_CLEANING;
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_msgify = 0;
|
1997-02-27 04:12:07 +03:00
|
|
|
if ((ecb = sc->sc_nexus) != NULL) {
|
1997-07-30 16:01:53 +04:00
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_done(sc, ecb);
|
|
|
|
}
|
2000-11-30 03:19:25 +03:00
|
|
|
/* Cancel outstanding disconnected commands on each LUN */
|
2000-12-01 02:01:03 +03:00
|
|
|
for (r = 0; r < 8; r++) {
|
2000-11-30 03:19:25 +03:00
|
|
|
LIST_FOREACH(li, &sc->sc_tinfo[r].luns, link) {
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((ecb = li->untagged) != NULL) {
|
2000-11-30 03:19:25 +03:00
|
|
|
li->untagged = NULL;
|
|
|
|
/*
|
|
|
|
* XXXXXXX
|
|
|
|
*
|
|
|
|
* Should we terminate a command
|
|
|
|
* that never reached the disk?
|
|
|
|
*/
|
|
|
|
li->busy = 0;
|
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
|
|
|
ncr53c9x_done(sc, ecb);
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
for (i = 0; i < 256; i++)
|
2000-11-30 03:19:25 +03:00
|
|
|
if ((ecb = li->queued[i])) {
|
|
|
|
li->queued[i] = NULL;
|
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
|
|
|
ncr53c9x_done(sc, ecb);
|
|
|
|
}
|
|
|
|
li->used = 0;
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset the chip to a known state
|
|
|
|
*/
|
|
|
|
ncr53c9x_reset(sc);
|
|
|
|
|
|
|
|
sc->sc_phase = sc->sc_prevphase = INVALID_PHASE;
|
|
|
|
for (r = 0; r < 8; r++) {
|
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[r];
|
|
|
|
/* XXX - config flags per target: low bits: no reselect; high bits: no synch */
|
|
|
|
|
2001-01-20 02:04:23 +03:00
|
|
|
ti->flags = ((sc->sc_minsync && !(sc->sc_cfflags & (1<<(r+8))))
|
2000-12-19 17:08:17 +03:00
|
|
|
? 0 : T_SYNCHOFF) |
|
2000-11-30 03:19:25 +03:00
|
|
|
((sc->sc_cfflags & (1<<r)) ? T_RSELECTOFF : 0) |
|
|
|
|
T_NEED_TO_RESET;
|
|
|
|
#ifdef DEBUG
|
2000-11-30 12:58:03 +03:00
|
|
|
if (ncr53c9x_notag)
|
2001-01-20 02:04:23 +03:00
|
|
|
ti->flags &= ~T_TAG;
|
2000-11-30 03:19:25 +03:00
|
|
|
#endif
|
1997-02-27 04:12:07 +03:00
|
|
|
ti->period = sc->sc_minsync;
|
|
|
|
ti->offset = 0;
|
2001-03-29 06:58:38 +04:00
|
|
|
ti->cfg3 = 0;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doreset) {
|
|
|
|
sc->sc_state = NCR_SBR;
|
|
|
|
NCRCMD(sc, NCRCMD_RSTSCSI);
|
|
|
|
} else {
|
|
|
|
sc->sc_state = NCR_IDLE;
|
1997-07-30 02:26:01 +04:00
|
|
|
ncr53c9x_sched(sc);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the NCR registers, and save their contents for later use.
|
|
|
|
* NCR_STAT, NCR_STEP & NCR_INTR are mostly zeroed out when reading
|
|
|
|
* NCR_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.
|
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
__inline__ void
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_readregs(sc)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
sc->sc_espstat = NCR_READ_REG(sc, NCR_STAT);
|
|
|
|
/* Only the stepo bits are of interest */
|
|
|
|
sc->sc_espstep = NCR_READ_REG(sc, NCR_STEP) & NCRSTEP_MASK;
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366)
|
|
|
|
sc->sc_espstat2 = NCR_READ_REG(sc, NCR_STAT2);
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_espintr = NCR_READ_REG(sc, NCR_INTR);
|
|
|
|
|
|
|
|
if (sc->sc_glue->gl_clear_latched_intr != NULL)
|
|
|
|
(*sc->sc_glue->gl_clear_latched_intr)(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 & NCRINTR_DIS)
|
|
|
|
? /* Disconnected */ BUSFREE_PHASE
|
|
|
|
: sc->sc_espstat & NCRSTAT_PHASE;
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("regs[intr=%02x,stat=%02x,step=%02x,stat2=%02x] ",
|
|
|
|
sc->sc_espintr, sc->sc_espstat, sc->sc_espstep, sc->sc_espstat2));
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert Synchronous Transfer Period to chip register Clock Per Byte value.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
ncr53c9x_stp2cpb(sc, period)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
int period;
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
v = (sc->sc_freq * period) / 250;
|
|
|
|
if (ncr53c9x_cpb2stp(sc, v) < period)
|
|
|
|
/* Correct round-down error */
|
|
|
|
v++;
|
1998-05-04 18:47:48 +04:00
|
|
|
return (v);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ncr53c9x_setsync(sc, ti)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
{
|
2001-03-29 06:58:38 +04:00
|
|
|
u_char syncoff, synctp;
|
|
|
|
u_char cfg3 = sc->sc_cfg3 | ti->cfg3;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
if (ti->flags & T_SYNCMODE) {
|
1998-05-27 03:17:34 +04:00
|
|
|
syncoff = ti->offset;
|
|
|
|
synctp = ncr53c9x_stp2cpb(sc, ti->period);
|
|
|
|
if (sc->sc_features & NCR_F_FASTSCSI) {
|
|
|
|
/*
|
|
|
|
* If the period is 200ns or less (ti->period <= 50),
|
|
|
|
* put the chip in Fast SCSI mode.
|
|
|
|
*/
|
|
|
|
if (ti->period <= 50)
|
1999-09-22 07:31:23 +04:00
|
|
|
/*
|
|
|
|
* There are (at least) 4 variations of the
|
|
|
|
* configuration 3 register. The drive attach
|
|
|
|
* routine sets the appropriate bit to put the
|
|
|
|
* chip into Fast SCSI mode so that it doesn't
|
|
|
|
* have to be figured out here each time.
|
|
|
|
*/
|
|
|
|
cfg3 |= sc->sc_cfg3_fscsi;
|
1998-05-27 03:17:34 +04:00
|
|
|
}
|
1999-01-06 22:19:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Am53c974 requires different SYNCTP values when the
|
|
|
|
* FSCSI bit is off.
|
|
|
|
*/
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_AM53C974 &&
|
|
|
|
(cfg3 & NCRAMDCFG3_FSCSI) == 0)
|
|
|
|
synctp--;
|
1997-02-27 04:12:07 +03:00
|
|
|
} else {
|
1998-05-27 03:17:34 +04:00
|
|
|
syncoff = 0;
|
|
|
|
synctp = 0;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-27 03:17:34 +04:00
|
|
|
|
|
|
|
if (sc->sc_features & NCR_F_HASCFG3)
|
|
|
|
NCR_WRITE_REG(sc, NCR_CFG3, cfg3);
|
|
|
|
|
|
|
|
NCR_WRITE_REG(sc, NCR_SYNCOFF, syncoff);
|
|
|
|
NCR_WRITE_REG(sc, NCR_SYNCTP, synctp);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command to a target, set the driver state to NCR_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
|
|
|
|
ncr53c9x_select(sc, ecb)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_link *sc_link = ecb->xs->sc_link;
|
|
|
|
int target = sc_link->scsipi_scsi.target;
|
1998-01-24 18:33:35 +03:00
|
|
|
int lun = sc_link->scsipi_scsi.lun;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[target];
|
1998-01-24 18:33:35 +03:00
|
|
|
int tiflags = ti->flags;
|
1997-02-27 04:12:07 +03:00
|
|
|
u_char *cmd;
|
|
|
|
int clen;
|
2000-12-10 22:25:07 +03:00
|
|
|
int selatn3 = 1;
|
|
|
|
int selandstop = 0;
|
1999-11-10 08:02:53 +03:00
|
|
|
size_t dmasize;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
NCR_TRACE(("[ncr53c9x_select(t%d,l%d,cmd:%x,tag:%x,%x)] ",
|
|
|
|
target, lun, ecb->cmd.cmd.opcode, ecb->tag[0], ecb->tag[1]));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
sc->sc_state = NCR_SELECTING;
|
1997-04-02 02:10:04 +04:00
|
|
|
/*
|
|
|
|
* Schedule the timeout now, the first time we will go away
|
|
|
|
* expecting to come back due to an interrupt, because it is
|
|
|
|
* always possible that the interrupt may never happen.
|
|
|
|
*/
|
2000-07-04 05:10:18 +04:00
|
|
|
if ((ecb->xs->xs_control & XS_CTL_POLL) == 0) {
|
|
|
|
int timeout = ecb->timeout;
|
|
|
|
|
|
|
|
if (hz > 100 && timeout > 1000)
|
|
|
|
timeout = (timeout / 1000) * hz;
|
|
|
|
else
|
|
|
|
timeout = (timeout * hz) / 1000;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
2000-07-04 05:10:18 +04:00
|
|
|
callout_reset(&ecb->xs->xs_callout, timeout,
|
2000-12-01 02:01:03 +03:00
|
|
|
ncr53c9x_timeout, ecb);
|
2000-07-04 05:10:18 +04:00
|
|
|
}
|
1997-04-02 02:10:04 +04:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* The docs say the target register is never reset, and I
|
|
|
|
* can't think of a better place to set it
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
NCR_WRITE_REG(sc, NCR_SELID, target | NCR_BUSID_HME);
|
|
|
|
} else {
|
|
|
|
NCR_WRITE_REG(sc, NCR_SELID, target);
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
|
2000-12-10 22:25:07 +03:00
|
|
|
/*
|
|
|
|
* Check to see if we can use SELATN3.
|
|
|
|
*/
|
|
|
|
switch (sc->sc_rev) {
|
|
|
|
case NCR_VARIANT_ESP100:
|
|
|
|
/* Don't have NCRCMD_SELATN3 */
|
|
|
|
selatn3 = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((ecb->flags & ECB_SENSE) != 0) {
|
1999-11-10 07:21:30 +03:00
|
|
|
/*
|
|
|
|
* For REQUEST SENSE, we should not send an IDENTIFY or
|
|
|
|
* otherwise mangle the target. There should be no MESSAGE IN
|
|
|
|
* phase.
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_features & NCR_F_DMASELECT) {
|
1999-11-10 08:02:53 +03:00
|
|
|
/* setup DMA transfer for command */
|
|
|
|
dmasize = clen = ecb->clen;
|
|
|
|
sc->sc_cmdlen = clen;
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_cmdp = (caddr_t)&ecb->cmd.cmd;
|
1999-11-10 08:02:53 +03:00
|
|
|
|
|
|
|
/* Program the SCSI counter */
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_SET_COUNT(sc, dmasize);
|
1999-11-10 08:02:53 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_rev != NCR_VARIANT_FAS366)
|
|
|
|
NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
|
1999-11-10 08:02:53 +03:00
|
|
|
|
|
|
|
/* And get the targets attention */
|
|
|
|
NCRCMD(sc, NCRCMD_SELNATN | NCRCMD_DMA);
|
2001-03-29 06:58:38 +04:00
|
|
|
NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0, &dmasize);
|
1999-11-10 08:02:53 +03:00
|
|
|
NCRDMA_GO(sc);
|
|
|
|
} else {
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
ncr53c9x_wrfifo(sc, (u_char *)&ecb->cmd.cmd, ecb->clen);
|
1999-11-10 08:02:53 +03:00
|
|
|
|
|
|
|
NCRCMD(sc, NCRCMD_SELNATN);
|
|
|
|
}
|
1999-11-10 07:21:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-10 22:25:07 +03:00
|
|
|
if (tiflags & T_NEGOTIATE) selandstop = 1;
|
2000-12-19 02:39:44 +03:00
|
|
|
cmd = (u_char *)&ecb->cmd.cmd;
|
2000-12-20 18:49:03 +03:00
|
|
|
|
|
|
|
if (ecb->tag[0] && !selatn3)
|
|
|
|
selandstop = 1;
|
|
|
|
|
2000-12-19 02:39:44 +03:00
|
|
|
if (ecb->tag[0] && selatn3 && !selandstop) {
|
2000-11-30 03:19:25 +03:00
|
|
|
/* We'll use tags */
|
|
|
|
clen = ecb->clen + 3;
|
2000-12-19 02:39:44 +03:00
|
|
|
cmd -= 3;
|
|
|
|
cmd[0] = MSG_IDENTIFY(lun, 1); /* msg[0] */
|
|
|
|
cmd[1] = ecb->tag[0]; /* msg[1] */
|
|
|
|
cmd[2] = ecb->tag[1]; /* msg[2] */
|
2000-11-30 03:19:25 +03:00
|
|
|
} else {
|
2000-12-20 18:49:03 +03:00
|
|
|
selatn3 = 0; /* Do not use selatn3 even if we have it */
|
2000-11-30 03:19:25 +03:00
|
|
|
clen = ecb->clen + 1;
|
2000-12-19 02:39:44 +03:00
|
|
|
cmd -= 1;
|
|
|
|
cmd[0] = MSG_IDENTIFY(lun, (tiflags & T_RSELECTOFF)?0:1);
|
2000-11-30 03:19:25 +03:00
|
|
|
}
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
if ((sc->sc_features & NCR_F_DMASELECT) && !selandstop) {
|
1998-01-24 18:33:35 +03:00
|
|
|
|
1997-04-28 02:08:51 +04:00
|
|
|
/* setup DMA transfer for command */
|
2000-11-30 03:19:25 +03:00
|
|
|
dmasize = clen;
|
1997-04-28 02:08:51 +04:00
|
|
|
sc->sc_cmdlen = clen;
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_cmdp = cmd;
|
1998-01-24 18:33:35 +03:00
|
|
|
|
1997-04-28 02:08:51 +04:00
|
|
|
/* Program the SCSI counter */
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_SET_COUNT(sc, dmasize);
|
1997-04-28 02:08:51 +04:00
|
|
|
|
1998-01-24 18:33:35 +03:00
|
|
|
/* load the count in */
|
2001-03-29 06:58:38 +04:00
|
|
|
/* if (sc->sc_rev != NCR_VARIANT_FAS366) */
|
|
|
|
NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
|
1998-01-24 18:33:35 +03:00
|
|
|
|
1997-04-28 02:08:51 +04:00
|
|
|
/* And get the targets attention */
|
2000-12-20 18:49:03 +03:00
|
|
|
if (selatn3) {
|
2000-12-19 02:39:44 +03:00
|
|
|
sc->sc_msgout = SEND_TAG;
|
|
|
|
sc->sc_flags |= NCR_ATN;
|
2000-11-30 03:19:25 +03:00
|
|
|
NCRCMD(sc, NCRCMD_SELATN3 | NCRCMD_DMA);
|
2000-12-19 02:39:44 +03:00
|
|
|
} else
|
2000-11-30 03:19:25 +03:00
|
|
|
NCRCMD(sc, NCRCMD_SELATN | NCRCMD_DMA);
|
2001-03-29 06:58:38 +04:00
|
|
|
NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0, &dmasize);
|
1997-04-28 02:08:51 +04:00
|
|
|
NCRDMA_GO(sc);
|
|
|
|
return;
|
|
|
|
}
|
1998-01-24 18:33:35 +03:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* Who am I. This is where we tell the target that we are
|
|
|
|
* happy for it to disconnect etc.
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
ncr53c9x_wrfifo(sc, cmd, 1);
|
|
|
|
cmd++; clen--;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-12-10 22:25:07 +03:00
|
|
|
if (selandstop) {
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("SELATNS \n"));
|
1997-02-27 04:12:07 +03:00
|
|
|
/* Arbitrate, select and stop after IDENTIFY message */
|
|
|
|
NCRCMD(sc, NCRCMD_SELATNS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
/* Now get the command into the FIFO */
|
2001-03-29 06:58:38 +04:00
|
|
|
ncr53c9x_wrfifo(sc, cmd, clen);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/* And get the targets attention */
|
2000-12-20 18:49:03 +03:00
|
|
|
if (selatn3) {
|
2000-12-19 02:39:44 +03:00
|
|
|
sc->sc_msgout = SEND_TAG;
|
|
|
|
sc->sc_flags |= NCR_ATN;
|
2000-12-04 02:25:24 +03:00
|
|
|
NCRCMD(sc, NCRCMD_SELATN3);
|
2000-12-19 02:39:44 +03:00
|
|
|
} else
|
2000-12-04 02:25:24 +03:00
|
|
|
NCRCMD(sc, NCRCMD_SELATN);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_free_ecb(sc, ecb, flags)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
ecb->flags = 0;
|
2000-11-30 03:19:25 +03:00
|
|
|
pool_put(&ecb_pool, (void *)ecb);
|
1997-02-27 04:12:07 +03:00
|
|
|
splx(s);
|
2000-11-30 03:19:25 +03:00
|
|
|
return;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ncr53c9x_ecb *
|
|
|
|
ncr53c9x_get_ecb(sc, flags)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
2000-11-30 03:19:25 +03:00
|
|
|
int s, wait = 0;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
if ((curproc != NULL) && ((flags & XS_CTL_NOSLEEP) == 0))
|
|
|
|
wait = PR_WAITOK;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
s = splbio();
|
|
|
|
ecb = (struct ncr53c9x_ecb *)pool_get(&ecb_pool, wait);
|
1997-02-27 04:12:07 +03:00
|
|
|
splx(s);
|
2000-11-30 03:19:25 +03:00
|
|
|
bzero(ecb, sizeof(*ecb));
|
|
|
|
if (ecb)
|
|
|
|
ecb->flags |= ECB_ALLOC;
|
1998-05-04 18:47:48 +04:00
|
|
|
return (ecb);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DRIVER FUNCTIONS CALLABLE FROM HIGHER LEVEL DRIVERS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a SCSI-command
|
|
|
|
* This function is called by the higher level SCSI-driver to queue/run
|
|
|
|
* SCSI-commands.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ncr53c9x_scsi_cmd(xs)
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_link *sc_link = xs->sc_link;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_softc *sc = sc_link->adapter_softc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int64_t lun = sc_link->scsipi_scsi.lun;
|
1997-02-27 04:12:07 +03:00
|
|
|
int s, flags;
|
|
|
|
|
|
|
|
NCR_TRACE(("[ncr53c9x_scsi_cmd] "));
|
|
|
|
NCR_CMDS(("[0x%x, %d]->%d ", (int)xs->cmd->opcode, xs->cmdlen,
|
1997-08-27 15:22:52 +04:00
|
|
|
sc_link->scsipi_scsi.target));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
/*
|
|
|
|
* Find the LUN info structure and allocate one if it does
|
|
|
|
* not exist.
|
|
|
|
*/
|
1999-10-01 03:04:39 +04:00
|
|
|
flags = xs->xs_control;
|
2000-11-30 03:19:25 +03:00
|
|
|
ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
|
|
|
li = TINFO_LUN(ti, lun);
|
|
|
|
if (li == NULL) {
|
|
|
|
int wait = M_NOWAIT;
|
|
|
|
|
|
|
|
/* Initialize LUN info and add to list. */
|
|
|
|
if ((curproc != NULL) && ((flags & XS_CTL_NOSLEEP) == 0))
|
|
|
|
wait = M_WAITOK;
|
|
|
|
if ((li = malloc(sizeof(*li), M_DEVBUF, M_NOWAIT)) == NULL) {
|
|
|
|
return (TRY_AGAIN_LATER);
|
|
|
|
}
|
|
|
|
bzero(li, sizeof(*li));
|
|
|
|
li->last_used = time.tv_sec;
|
|
|
|
li->lun = lun;
|
|
|
|
s = splbio();
|
|
|
|
LIST_INSERT_HEAD(&ti->luns, li, link);
|
|
|
|
if (lun < NCR_NLUN)
|
|
|
|
ti->lun[lun] = li;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1997-07-30 16:01:53 +04:00
|
|
|
if ((ecb = ncr53c9x_get_ecb(sc, flags)) == NULL)
|
1998-05-04 18:47:48 +04:00
|
|
|
return (TRY_AGAIN_LATER);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/* Initialize ecb */
|
|
|
|
ecb->xs = xs;
|
|
|
|
ecb->timeout = xs->timeout;
|
|
|
|
|
1999-10-01 03:04:39 +04:00
|
|
|
if (flags & XS_CTL_RESET) {
|
1997-02-27 04:12:07 +03:00
|
|
|
ecb->flags |= ECB_RESET;
|
|
|
|
ecb->clen = 0;
|
|
|
|
ecb->dleft = 0;
|
|
|
|
} else {
|
1997-04-28 02:08:51 +04:00
|
|
|
bcopy(xs->cmd, &ecb->cmd.cmd, xs->cmdlen);
|
1997-02-27 04:12:07 +03:00
|
|
|
ecb->clen = xs->cmdlen;
|
|
|
|
ecb->daddr = xs->data;
|
|
|
|
ecb->dleft = xs->datalen;
|
|
|
|
}
|
|
|
|
ecb->stat = 0;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->ready_list, ecb, chain);
|
2000-11-30 03:19:25 +03:00
|
|
|
ecb->flags |= ECB_READY;
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state == NCR_IDLE)
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
1999-10-01 03:04:39 +04:00
|
|
|
if ((flags & XS_CTL_POLL) == 0)
|
1998-05-04 18:47:48 +04:00
|
|
|
return (SUCCESSFULLY_QUEUED);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/* Not allowed to use interrupts, use polling instead */
|
|
|
|
if (ncr53c9x_poll(sc, xs, ecb->timeout)) {
|
|
|
|
ncr53c9x_timeout(ecb);
|
|
|
|
if (ncr53c9x_poll(sc, xs, ecb->timeout))
|
|
|
|
ncr53c9x_timeout(ecb);
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
return (COMPLETE);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used when interrupt driven I/O isn't allowed, e.g. during boot.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ncr53c9x_poll(sc, xs, count)
|
|
|
|
struct ncr53c9x_softc *sc;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1997-02-27 04:12:07 +03:00
|
|
|
int count;
|
|
|
|
{
|
|
|
|
|
|
|
|
NCR_TRACE(("[ncr53c9x_poll] "));
|
|
|
|
while (count) {
|
|
|
|
if (NCRDMA_ISINTR(sc)) {
|
|
|
|
ncr53c9x_intr(sc);
|
|
|
|
}
|
|
|
|
#if alternatively
|
|
|
|
if (NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT)
|
|
|
|
ncr53c9x_intr(sc);
|
|
|
|
#endif
|
1999-10-01 03:04:39 +04:00
|
|
|
if ((xs->xs_status & XS_STS_DONE) != 0)
|
1998-05-04 18:47:48 +04:00
|
|
|
return (0);
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state == NCR_IDLE) {
|
|
|
|
NCR_TRACE(("[ncr53c9x_poll: rescheduling] "));
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
}
|
|
|
|
DELAY(1000);
|
|
|
|
count--;
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
2000-11-13 18:24:22 +03:00
|
|
|
int
|
|
|
|
ncr53c9x_ioctl(link, cmd, arg, flag, p)
|
|
|
|
struct scsipi_link *link;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t arg;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_softc *sc = link->adapter_softc;
|
2000-12-04 14:18:49 +03:00
|
|
|
int s, error = 0;
|
2000-11-13 18:24:22 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SCBUSACCEL: {
|
|
|
|
struct scbusaccel_args *sp = (struct scbusaccel_args *)arg;
|
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[sp->sa_target];
|
|
|
|
|
|
|
|
if (sp->sa_lun != 0)
|
|
|
|
break;
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("%s: SCBUSACCEL flag 0x%x\n", sc->sc_dev.dv_xname,
|
|
|
|
sp->sa_flags));
|
|
|
|
|
|
|
|
if ((sp->sa_flags & SC_ACCEL_WIDE) != 0) {
|
|
|
|
NCR_MISC(("%s: target %d: wide scsi negotiation\n",
|
|
|
|
sc->sc_dev.dv_xname, sp->sa_target));
|
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) {
|
|
|
|
ti->flags |= T_WIDE;
|
|
|
|
ti->width = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-13 18:24:22 +03:00
|
|
|
if ((sp->sa_flags & SC_ACCEL_SYNC) != 0) {
|
|
|
|
/* If this adapter can't do sync; drop it */
|
|
|
|
if (sc->sc_minsync == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether target is already clamped at
|
|
|
|
* non-sync operation on user request.
|
|
|
|
*/
|
|
|
|
if ((ti->flags & T_SYNCHOFF) != 0)
|
|
|
|
break;
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("%s: target %d: sync negotiation\n",
|
|
|
|
sc->sc_dev.dv_xname, sp->sa_target));
|
2000-11-13 18:24:22 +03:00
|
|
|
ti->flags |= T_NEGOTIATE;
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
|
2001-01-20 02:04:23 +03:00
|
|
|
if ((sp->sa_flags & SC_ACCEL_TAGS) != 0) {
|
|
|
|
if ((sc->sc_cfflags & (1<<((sp->sa_target)+16))) == 0) {
|
|
|
|
ti->flags |= T_TAG;
|
|
|
|
link->openings = 255;
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
printf("%s: target %d: tags\n",
|
|
|
|
sc->sc_dev.dv_xname, sp->sa_target);
|
2001-01-20 02:04:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-11-13 18:24:22 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LOW LEVEL SCSI UTILITIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Schedule a scsi operation. This has now been pulled out of the interrupt
|
|
|
|
* handler so that we may call it from ncr53c9x_scsi_cmd and ncr53c9x_done.
|
|
|
|
* This may save us an unecessary interrupt just to get things going.
|
|
|
|
* Should only be called when state == NCR_IDLE and at bio pl.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_sched(sc)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_link *sc_link;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_tinfo *ti;
|
2000-11-30 03:19:25 +03:00
|
|
|
int lun;
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int s, tag;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
NCR_TRACE(("[ncr53c9x_sched] "));
|
|
|
|
if (sc->sc_state != NCR_IDLE)
|
|
|
|
panic("ncr53c9x_sched: not IDLE (state=%d)", sc->sc_state);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find first ecb in ready queue that is for a target/lunit
|
|
|
|
* combinations that is not busy.
|
|
|
|
*/
|
2000-12-01 02:01:03 +03:00
|
|
|
for (ecb = TAILQ_FIRST(&sc->ready_list); ecb != NULL;
|
|
|
|
ecb = TAILQ_NEXT(ecb, chain)) {
|
1997-02-27 04:12:07 +03:00
|
|
|
sc_link = ecb->xs->sc_link;
|
1997-08-27 15:22:52 +04:00
|
|
|
ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
2000-11-30 03:19:25 +03:00
|
|
|
lun = sc_link->scsipi_scsi.lun;
|
|
|
|
|
|
|
|
/* Select type of tag for this command */
|
2001-01-20 02:04:23 +03:00
|
|
|
if ((ti->flags & (T_RSELECTOFF)) != 0)
|
|
|
|
tag = 0;
|
|
|
|
else if ((ti->flags & (T_TAG)) == 0)
|
2000-12-01 02:01:03 +03:00
|
|
|
tag = 0;
|
|
|
|
else if ((ecb->flags & ECB_SENSE) != 0)
|
|
|
|
tag = 0;
|
|
|
|
else if (ecb->xs->xs_control & XS_CTL_URGENT)
|
2000-11-30 03:19:25 +03:00
|
|
|
tag = MSG_HEAD_OF_Q_TAG;
|
|
|
|
else
|
|
|
|
tag = MSG_SIMPLE_Q_TAG;
|
|
|
|
#if 0
|
|
|
|
/* XXXX Use tags for polled commands? */
|
|
|
|
if (ecb->xs->xs_control & XS_CTL_POLL)
|
|
|
|
tag = 0;
|
|
|
|
#endif
|
2000-12-01 02:01:03 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
s = splbio();
|
|
|
|
li = TINFO_LUN(ti, lun);
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li == NULL) {
|
2000-11-30 03:19:25 +03:00
|
|
|
int wait = M_NOWAIT;
|
|
|
|
int flags = ecb->xs->xs_control;
|
|
|
|
|
|
|
|
/* Initialize LUN info and add to list. */
|
|
|
|
if ((curproc != NULL) && ((flags & XS_CTL_NOSLEEP) == 0))
|
|
|
|
wait = M_WAITOK;
|
|
|
|
if ((li = malloc(sizeof(*li), M_DEVBUF, M_NOWAIT)) == NULL) {
|
|
|
|
splx(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bzero(li, sizeof(*li));
|
|
|
|
li->lun = lun;
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&ti->luns, li, link);
|
|
|
|
if (lun < NCR_NLUN)
|
|
|
|
ti->lun[lun] = li;
|
|
|
|
}
|
|
|
|
li->last_used = time.tv_sec;
|
2000-12-01 02:01:03 +03:00
|
|
|
if (tag == 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
/* Try to issue this as an un-tagged command */
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->untagged == NULL)
|
2000-11-30 03:19:25 +03:00
|
|
|
li->untagged = ecb;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->untagged != NULL) {
|
2000-11-30 03:19:25 +03:00
|
|
|
tag = 0;
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((li->busy != 1) && li->used == 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
/* We need to issue this untagged command now */
|
|
|
|
ecb = li->untagged;
|
|
|
|
sc_link = ecb->xs->sc_link;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Not ready yet */
|
|
|
|
splx(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ecb->tag[0] = tag;
|
2000-12-01 02:01:03 +03:00
|
|
|
if (tag != 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Allocate a tag */
|
|
|
|
if (li->used == 255) {
|
|
|
|
/* no free tags */
|
|
|
|
splx(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Start from the last used location */
|
2000-12-01 02:01:03 +03:00
|
|
|
for (i = li->avail; i < 256; i++) {
|
2000-11-30 03:19:25 +03:00
|
|
|
if (li->queued[i] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Couldn't find one, start again from the beginning */
|
|
|
|
if (i == 256) {
|
2000-12-01 02:01:03 +03:00
|
|
|
for (i = 0; i < 256; i++) {
|
2000-11-30 03:19:25 +03:00
|
|
|
if (li->queued[i] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* There's supposed to be at least 1 tag avail */
|
|
|
|
if (i == 256)
|
|
|
|
panic("ncr53c9x_sched: tag alloc failure\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Save where to start next time. */
|
|
|
|
li->avail = i+1;
|
|
|
|
li->used ++;
|
|
|
|
|
|
|
|
li->queued[i] = ecb;
|
|
|
|
ecb->tag[1] = i;
|
|
|
|
}
|
|
|
|
splx(s);
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->untagged != NULL && (li->busy != 1)) {
|
2000-11-30 03:19:25 +03:00
|
|
|
li->busy = 1;
|
|
|
|
TAILQ_REMOVE(&sc->ready_list, ecb, chain);
|
|
|
|
ecb->flags &= ~ECB_READY;
|
|
|
|
sc->sc_nexus = ecb;
|
|
|
|
ncr53c9x_select(sc, ecb);
|
|
|
|
break;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->untagged == NULL && tag != 0) {
|
1997-02-27 04:12:07 +03:00
|
|
|
TAILQ_REMOVE(&sc->ready_list, ecb, chain);
|
2000-11-30 03:19:25 +03:00
|
|
|
ecb->flags &= ~ECB_READY;
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_nexus = ecb;
|
|
|
|
ncr53c9x_select(sc, ecb);
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
NCR_MISC(("%d:%d busy\n",
|
1998-01-24 18:33:35 +03:00
|
|
|
sc_link->scsipi_scsi.target,
|
|
|
|
sc_link->scsipi_scsi.lun));
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_sense(sc, ecb)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = ecb->xs;
|
|
|
|
struct scsipi_link *sc_link = xs->sc_link;
|
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
|
|
|
struct scsipi_sense *ss = (void *)&ecb->cmd.cmd;
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int lun = sc_link->scsipi_scsi.lun;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
NCR_MISC(("requesting sense "));
|
|
|
|
/* Next, setup a request sense command block */
|
|
|
|
bzero(ss, sizeof(*ss));
|
|
|
|
ss->opcode = REQUEST_SENSE;
|
1997-08-27 15:22:52 +04:00
|
|
|
ss->byte2 = sc_link->scsipi_scsi.lun << 5;
|
|
|
|
ss->length = sizeof(struct scsipi_sense_data);
|
1997-02-27 04:12:07 +03:00
|
|
|
ecb->clen = sizeof(*ss);
|
1997-08-27 15:22:52 +04:00
|
|
|
ecb->daddr = (char *)&xs->sense.scsi_sense;
|
|
|
|
ecb->dleft = sizeof(struct scsipi_sense_data);
|
1997-02-27 04:12:07 +03:00
|
|
|
ecb->flags |= ECB_SENSE;
|
1997-04-02 02:10:04 +04:00
|
|
|
ecb->timeout = NCR_SENSE_TIMEOUT;
|
1997-02-27 04:12:07 +03:00
|
|
|
ti->senses++;
|
2000-11-30 03:19:25 +03:00
|
|
|
li = TINFO_LUN(ti, lun);
|
|
|
|
if (li->busy) li->busy = 0;
|
|
|
|
ncr53c9x_dequeue(sc, ecb);
|
|
|
|
li->untagged = ecb; /* must be executed first to fix C/A */
|
|
|
|
li->busy = 2;
|
1997-02-27 04:12:07 +03:00
|
|
|
if (ecb == sc->sc_nexus) {
|
|
|
|
ncr53c9x_select(sc, ecb);
|
|
|
|
} else {
|
|
|
|
TAILQ_INSERT_HEAD(&sc->ready_list, ecb, chain);
|
2000-11-30 03:19:25 +03:00
|
|
|
ecb->flags |= ECB_READY;
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state == NCR_IDLE)
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* POST PROCESSING OF SCSI_CMD (usually current)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_done(sc, ecb)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = ecb->xs;
|
|
|
|
struct scsipi_link *sc_link = xs->sc_link;
|
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
2000-11-30 03:19:25 +03:00
|
|
|
int lun = sc_link->scsipi_scsi.lun;
|
|
|
|
struct ncr53c9x_linfo *li = TINFO_LUN(ti, lun);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
NCR_TRACE(("[ncr53c9x_done(error:%x)] ", xs->error));
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&ecb->xs->xs_callout);
|
1997-04-02 02:10:04 +04:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
if (ecb->stat == SCSI_QUEUE_FULL) {
|
|
|
|
/*
|
|
|
|
* Set current throttle -- we should reset
|
|
|
|
* this periodically
|
|
|
|
*/
|
|
|
|
sc_link->openings = li->used - 1;
|
|
|
|
printf("\n%s: QFULL -- throttling to %d commands\n",
|
|
|
|
sc->sc_dev.dv_xname, sc_link->openings);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* Now, if we've come here with no error code, i.e. we've kept the
|
|
|
|
* initial XS_NOERROR, and the status code signals that we should
|
|
|
|
* 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
|
|
|
|
* commands for this target/lunit, else we lose the sense info.
|
|
|
|
* We don't support chk sense conditions for the request sense cmd.
|
|
|
|
*/
|
|
|
|
if (xs->error == XS_NOERROR) {
|
1997-07-20 01:54:16 +04:00
|
|
|
xs->status = ecb->stat;
|
1997-02-27 04:12:07 +03:00
|
|
|
if ((ecb->flags & ECB_ABORT) != 0) {
|
1997-07-30 16:01:53 +04:00
|
|
|
xs->error = XS_TIMEOUT;
|
1997-02-27 04:12:07 +03:00
|
|
|
} else if ((ecb->flags & ECB_SENSE) != 0) {
|
|
|
|
xs->error = XS_SENSE;
|
|
|
|
} else if ((ecb->stat & ST_MASK) == SCSI_CHECK) {
|
|
|
|
/* First, save the return values */
|
|
|
|
xs->resid = ecb->dleft;
|
|
|
|
ncr53c9x_sense(sc, ecb);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
xs->resid = ecb->dleft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-01 03:04:39 +04:00
|
|
|
xs->xs_status |= XS_STS_DONE;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
#ifdef NCR53C9X_DEBUG
|
|
|
|
if (ncr53c9x_debug & NCR_SHOWMISC) {
|
|
|
|
if (xs->resid != 0)
|
|
|
|
printf("resid=%d ", xs->resid);
|
|
|
|
if (xs->error == XS_SENSE)
|
1997-08-27 15:22:52 +04:00
|
|
|
printf("sense=0x%02x\n", xs->sense.scsi_sense.error_code);
|
1997-02-27 04:12:07 +03:00
|
|
|
else
|
|
|
|
printf("error=%d\n", xs->error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the ECB from whatever queue it's on.
|
|
|
|
*/
|
2000-11-30 03:19:25 +03:00
|
|
|
ncr53c9x_dequeue(sc, ecb);
|
1997-02-27 04:12:07 +03:00
|
|
|
if (ecb == sc->sc_nexus) {
|
|
|
|
sc->sc_nexus = NULL;
|
1997-07-30 02:26:01 +04:00
|
|
|
if (sc->sc_state != NCR_CLEANING) {
|
|
|
|
sc->sc_state = NCR_IDLE;
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
}
|
2000-11-30 03:19:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xs->error == XS_SELTIMEOUT) {
|
|
|
|
/* Selection timeout -- discard this LUN if empty */
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->untagged == NULL && li->used == 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
if (lun < NCR_NLUN)
|
|
|
|
ti->lun[lun] = NULL;
|
|
|
|
LIST_REMOVE(li, link);
|
|
|
|
free(li, M_DEVBUF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-01 03:04:39 +04:00
|
|
|
ncr53c9x_free_ecb(sc, ecb, xs->xs_control);
|
1997-02-27 04:12:07 +03:00
|
|
|
ti->cmds++;
|
1997-08-27 15:22:52 +04:00
|
|
|
scsipi_done(xs);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_dequeue(sc, ecb)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
{
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_tinfo *ti =
|
|
|
|
&sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int64_t lun = ecb->xs->sc_link->scsipi_scsi.lun;
|
|
|
|
|
|
|
|
li = TINFO_LUN(ti, lun);
|
|
|
|
#ifdef DIAGNOSTIC
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li == NULL || li->lun != lun)
|
2000-11-30 03:19:25 +03:00
|
|
|
panic("ncr53c9x_dequeue: lun %qx for ecb %p does not exist\n",
|
2000-11-30 17:41:46 +03:00
|
|
|
(long long) lun, ecb);
|
2000-11-30 03:19:25 +03:00
|
|
|
#endif
|
|
|
|
if (li->untagged == ecb) {
|
|
|
|
li->busy = 0;
|
|
|
|
li->untagged = NULL;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
if (ecb->tag[0] && li->queued[ecb->tag[1]] != NULL) {
|
2000-11-30 03:19:25 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->queued[ecb->tag[1]] != NULL &&
|
|
|
|
(li->queued[ecb->tag[1]] != ecb))
|
2000-11-30 03:19:25 +03:00
|
|
|
panic("ncr53c9x_dequeue: slot %d for lun %qx has %p "
|
2000-11-30 17:41:46 +03:00
|
|
|
"instead of ecb %p\n", ecb->tag[1],
|
|
|
|
(long long) lun,
|
2000-11-30 03:19:25 +03:00
|
|
|
li->queued[ecb->tag[1]], ecb);
|
|
|
|
#endif
|
|
|
|
li->queued[ecb->tag[1]] = NULL;
|
|
|
|
li->used --;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
|
|
|
|
if ((ecb->flags & ECB_READY) != 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
ecb->flags &= ~ECB_READY;
|
1997-02-27 04:12:07 +03:00
|
|
|
TAILQ_REMOVE(&sc->ready_list, ecb, chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INTERRUPT/PROTOCOL ENGINE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 ncr53c9x_sched_msgout(m) \
|
|
|
|
do { \
|
2000-11-30 03:19:25 +03:00
|
|
|
NCR_MISC(("ncr53c9x_sched_msgout %x %d", m, __LINE__)); \
|
1997-02-27 04:12:07 +03:00
|
|
|
NCRCMD(sc, NCRCMD_SETATN); \
|
|
|
|
sc->sc_flags |= NCR_ATN; \
|
|
|
|
sc->sc_msgpriq |= (m); \
|
|
|
|
} while (0)
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncr53c9x_flushfifo(struct ncr53c9x_softc *sc)
|
|
|
|
{
|
|
|
|
NCR_MISC(("[flushfifo] "));
|
|
|
|
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
|
|
|
|
if (sc->sc_phase == COMMAND_PHASE ||
|
|
|
|
sc->sc_phase == MESSAGE_OUT_PHASE)
|
|
|
|
DELAY(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncr53c9x_rdfifo(struct ncr53c9x_softc *sc, int how)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
u_char *buf;
|
|
|
|
|
|
|
|
switch(how) {
|
|
|
|
case NCR_RDFIFO_START:
|
|
|
|
buf = sc->sc_imess;
|
|
|
|
sc->sc_imlen = 0;
|
|
|
|
break;
|
|
|
|
case NCR_RDFIFO_CONTINUE:
|
|
|
|
buf = sc->sc_imess + sc->sc_imlen;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("ncr53c9x_rdfifo: bad flag\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX buffer (sc_imess) size for message
|
|
|
|
*/
|
|
|
|
|
|
|
|
n = NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF;
|
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) {
|
|
|
|
n *= 2;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
buf[i] = NCR_READ_REG(sc, NCR_FIFO);
|
|
|
|
|
|
|
|
if (sc->sc_espstat2 & FAS_STAT2_ISHUTTLE) {
|
|
|
|
|
|
|
|
NCR_WRITE_REG(sc, NCR_FIFO, 0);
|
|
|
|
buf[i++] = NCR_READ_REG(sc, NCR_FIFO);
|
|
|
|
|
|
|
|
NCR_READ_REG(sc, NCR_FIFO);
|
|
|
|
|
|
|
|
ncr53c9x_flushfifo(sc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
buf[i] = NCR_READ_REG(sc, NCR_FIFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_imlen += i;
|
|
|
|
|
|
|
|
#ifdef NCR53C9X_DEBUG
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
NCR_TRACE(("\n[rdfifo %s (%d):",
|
|
|
|
(how == NCR_RDFIFO_START) ? "start" : "cont",
|
|
|
|
(int)sc->sc_imlen));
|
|
|
|
if (ncr53c9x_debug & NCR_SHOWTRAC) {
|
|
|
|
for (j = 0; j < sc->sc_imlen; j++)
|
|
|
|
printf(" %02x", sc->sc_imess[j]);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return sc->sc_imlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncr53c9x_wrfifo(struct ncr53c9x_softc *sc, u_char *p, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef NCR53C9X_DEBUG
|
|
|
|
NCR_MISC(("[wrfifo(%d):", len));
|
|
|
|
if (ncr53c9x_debug & NCR_SHOWTRAC) {
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
printf(" %02x", p[i]);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
NCR_WRITE_REG(sc, NCR_FIFO, p[i]);
|
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366)
|
|
|
|
NCR_WRITE_REG(sc, NCR_FIFO, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
int
|
2000-11-30 03:19:25 +03:00
|
|
|
ncr53c9x_reselect(sc, message, tagtype, tagid)
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
int message;
|
2000-11-30 03:19:25 +03:00
|
|
|
int tagtype, tagid;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
|
|
|
u_char selid, target, lun;
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_ecb *ecb = NULL;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_tinfo *ti;
|
2000-11-30 03:19:25 +03:00
|
|
|
struct ncr53c9x_linfo *li;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) {
|
|
|
|
target = sc->sc_selid;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* 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)) {
|
|
|
|
printf("%s: reselect with invalid selid %02x;"
|
|
|
|
" sending DEVICE RESET\n", sc->sc_dev.dv_xname, selid);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = ffs(selid) - 1;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
lun = message & 0x07;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2000-11-30 03:19:25 +03:00
|
|
|
ti = &sc->sc_tinfo[target];
|
|
|
|
li = TINFO_LUN(ti, lun);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can get as far as the LUN with the IDENTIFY
|
|
|
|
* message. Check to see if we're running an
|
|
|
|
* un-tagged command. Otherwise ack the IDENTIFY
|
|
|
|
* and wait for a tag message.
|
|
|
|
*/
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li != NULL) {
|
|
|
|
if (li->untagged != NULL && li->busy)
|
|
|
|
ecb = li->untagged;
|
2000-11-30 03:19:25 +03:00
|
|
|
else if (tagtype != MSG_SIMPLE_Q_TAG) {
|
|
|
|
/* Wait for tag to come by */
|
|
|
|
sc->sc_state = NCR_IDENTIFIED;
|
|
|
|
return (0);
|
2000-12-01 02:01:03 +03:00
|
|
|
} else if (tagtype)
|
|
|
|
ecb = li->queued[tagid];
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
if (ecb == NULL) {
|
2000-11-30 03:19:25 +03:00
|
|
|
printf("%s: reselect from target %d lun %d tag %x:%x with no nexus;"
|
2000-12-01 02:01:03 +03:00
|
|
|
" sending ABORT\n",
|
|
|
|
sc->sc_dev.dv_xname, target, lun, tagtype, tagid);
|
1997-02-27 04:12:07 +03:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make this nexus active again. */
|
|
|
|
sc->sc_state = NCR_CONNECTED;
|
|
|
|
sc->sc_nexus = ecb;
|
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
|
|
|
|
if (ecb->flags & ECB_RESET)
|
|
|
|
ncr53c9x_sched_msgout(SEND_DEV_RESET);
|
|
|
|
else if (ecb->flags & ECB_ABORT)
|
|
|
|
ncr53c9x_sched_msgout(SEND_ABORT);
|
|
|
|
|
|
|
|
/* Do an implicit RESTORE POINTERS. */
|
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
reset:
|
|
|
|
ncr53c9x_sched_msgout(SEND_DEV_RESET);
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
abort:
|
|
|
|
ncr53c9x_sched_msgout(SEND_ABORT);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX this might be common thing(check with scsipi)
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
#define IS1BYTEMSG(m) (((m) != 1 && (m) < 0x20) || (m) & 0x80)
|
|
|
|
#define IS2BYTEMSG(m) (((m) & 0xf0) == 0x20)
|
|
|
|
#define ISEXTMSG(m) ((m) == 1)
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
static inline int
|
|
|
|
__verify_msg_format(u_char *p, int len)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (len == 1 && IS1BYTEMSG(p[0]))
|
|
|
|
return 1;
|
|
|
|
if (len == 2 && IS2BYTEMSG(p[0]))
|
|
|
|
return 1;
|
|
|
|
if (len >= 3 && ISEXTMSG(p[0]) &&
|
|
|
|
len == p[1] + 2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-02-27 04:12:07 +03: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
|
|
|
|
ncr53c9x_msgin(sc)
|
2000-03-29 17:57:51 +04:00
|
|
|
struct ncr53c9x_softc *sc;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_TRACE(("[ncr53c9x_msgin(curmsglen:%ld)] ", (long)sc->sc_imlen));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_imlen == 0) {
|
|
|
|
printf("%s: msgin: no msg byte available\n", sc->sc_dev.dv_xname);
|
1997-02-27 04:12:07 +03: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.
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_prevphase != MESSAGE_IN_PHASE && sc->sc_state != NCR_RESELECTED) {
|
|
|
|
printf("%s: phase change, dropping message, prev %d, state %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_prevphase, sc->sc_state);
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_flags &= ~NCR_DROP_MSGI;
|
|
|
|
sc->sc_imlen = 0;
|
|
|
|
}
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_TRACE(("<msgbyte:0x%02x>", sc->sc_imess[0]));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're going to reject the message, don't bother storing
|
|
|
|
* the incoming bytes. But still, we need to ACK them.
|
|
|
|
*/
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_flags & NCR_DROP_MSGI) != 0) {
|
1997-02-27 04:12:07 +03:00
|
|
|
NCRCMD(sc, NCRCMD_MSGOK);
|
|
|
|
printf("<dropping msg byte %x>",
|
|
|
|
sc->sc_imess[sc->sc_imlen]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_imlen >= NCR_MAX_MSG_LEN) {
|
|
|
|
ncr53c9x_sched_msgout(SEND_REJECT);
|
|
|
|
sc->sc_flags |= NCR_DROP_MSGI;
|
|
|
|
} else {
|
2001-03-29 06:58:38 +04:00
|
|
|
u_char *pb;
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
switch (sc->sc_state) {
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
2001-03-29 06:58:38 +04:00
|
|
|
* if received message is the first of reselection
|
|
|
|
* then first byte is selid, and then message
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
case NCR_RESELECTED:
|
|
|
|
pb = sc->sc_imess + 1;
|
|
|
|
plen = sc->sc_imlen - 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pb = sc->sc_imess;
|
|
|
|
plen = sc->sc_imlen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (__verify_msg_format(pb, plen))
|
1997-02-27 04:12:07 +03:00
|
|
|
goto gotit;
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/* Ack what we have so far */
|
|
|
|
NCRCMD(sc, NCRCMD_MSGOK);
|
|
|
|
return;
|
|
|
|
|
|
|
|
gotit:
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MSGS(("gotmsg(%x) state %d", sc->sc_imess[0], sc->sc_state));
|
|
|
|
/* we got complete message, flush the imess, XXX nobody uses imlen below */
|
|
|
|
sc->sc_imlen = 0;
|
1997-02-27 04:12:07 +03: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
|
|
|
|
* NCR_MAX_MSG_LEN. Longer messages will be amputated.
|
|
|
|
*/
|
|
|
|
switch (sc->sc_state) {
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
struct ncr53c9x_tinfo *ti;
|
2000-12-19 02:39:44 +03:00
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int lun;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
case NCR_CONNECTED:
|
|
|
|
ecb = sc->sc_nexus;
|
1997-08-27 15:22:52 +04:00
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
switch (sc->sc_imess[0]) {
|
|
|
|
case MSG_CMDCOMPLETE:
|
|
|
|
NCR_MSGS(("cmdcomplete "));
|
|
|
|
if (sc->sc_dleft < 0) {
|
1998-11-30 10:44:24 +03:00
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
|
|
|
printf("got %ld extra bytes\n",
|
1998-11-30 10:54:29 +03:00
|
|
|
-(long)sc->sc_dleft);
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dleft = 0;
|
|
|
|
}
|
1997-07-20 20:46:17 +04:00
|
|
|
ecb->dleft = (ecb->flags & ECB_TENTATIVE_DONE)
|
|
|
|
? 0
|
|
|
|
: sc->sc_dleft;
|
|
|
|
if ((ecb->flags & ECB_SENSE) == 0)
|
|
|
|
ecb->xs->resid = ecb->dleft;
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_state = NCR_CMDCOMPLETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_MESSAGE_REJECT:
|
1998-02-01 02:37:51 +03:00
|
|
|
NCR_MSGS(("msg reject (msgout=%x) ", sc->sc_msgout));
|
1997-02-27 04:12:07 +03:00
|
|
|
switch (sc->sc_msgout) {
|
2000-12-19 02:39:44 +03:00
|
|
|
case SEND_TAG:
|
|
|
|
/*
|
|
|
|
* Target does not like tagged queuing.
|
|
|
|
* - Flush the command queue
|
|
|
|
* - Disable tagged queuing for the target
|
|
|
|
* - Dequeue ecb from the queued array.
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
printf("%s: tagged queuing rejected: target %d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ecb->xs->sc_link->scsipi_scsi.target);
|
|
|
|
|
2000-12-19 02:39:44 +03:00
|
|
|
NCR_MSGS(("(rejected sent tag)"));
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
DELAY(1);
|
2001-01-20 02:04:23 +03:00
|
|
|
ti->flags &= ~T_TAG;
|
2000-12-19 02:39:44 +03:00
|
|
|
lun = ecb->xs->sc_link->scsipi_scsi.lun;
|
|
|
|
li = TINFO_LUN(ti, lun);
|
|
|
|
if (ecb->tag[0] &&
|
|
|
|
li->queued[ecb->tag[1]] != NULL) {
|
|
|
|
li->queued[ecb->tag[1]] = NULL;
|
|
|
|
li->used --;
|
|
|
|
}
|
|
|
|
ecb->tag[0] = ecb->tag[1] = 0;
|
|
|
|
li->untagged = ecb;
|
|
|
|
li->busy = 1;
|
|
|
|
break;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
case SEND_SDTR:
|
2001-03-29 06:58:38 +04:00
|
|
|
printf("%s: sync transfer rejected: target %d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ecb->xs->sc_link->scsipi_scsi.target);
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_flags &= ~NCR_SYNCHNEGO;
|
|
|
|
ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
|
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
break;
|
2000-12-19 02:39:44 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
case SEND_WDTR:
|
|
|
|
printf("%s: wide transfer rejected: target %d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ecb->xs->sc_link->scsipi_scsi.target);
|
|
|
|
ti->flags &= ~T_WIDE;
|
|
|
|
break;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
case SEND_INIT_DET_ERR:
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_NOOP:
|
|
|
|
NCR_MSGS(("noop "));
|
|
|
|
break;
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
case MSG_HEAD_OF_Q_TAG:
|
|
|
|
case MSG_SIMPLE_Q_TAG:
|
|
|
|
case MSG_ORDERED_Q_TAG:
|
|
|
|
NCR_MSGS(("TAG %x:%x", sc->sc_imess[0], sc->sc_imess[1]));
|
|
|
|
break;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
case MSG_DISCONNECT:
|
|
|
|
NCR_MSGS(("disconnect "));
|
|
|
|
ti->dconns++;
|
|
|
|
sc->sc_state = NCR_DISCONNECT;
|
1997-04-28 02:08:51 +04:00
|
|
|
|
1997-07-20 20:46:17 +04:00
|
|
|
/*
|
|
|
|
* Mark the fact that all bytes have moved. The
|
|
|
|
* target may not bother to do a SAVE POINTERS
|
|
|
|
* at this stage. This flag will set the residual
|
|
|
|
* count to zero on MSG COMPLETE.
|
|
|
|
*/
|
|
|
|
if (sc->sc_dleft == 0)
|
|
|
|
ecb->flags |= ECB_TENTATIVE_DONE;
|
|
|
|
|
|
|
|
break;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
case MSG_SAVEDATAPOINTER:
|
|
|
|
NCR_MSGS(("save datapointer "));
|
|
|
|
ecb->daddr = sc->sc_dp;
|
|
|
|
ecb->dleft = sc->sc_dleft;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_RESTOREPOINTERS:
|
|
|
|
NCR_MSGS(("restore datapointer "));
|
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_EXTENDED:
|
|
|
|
NCR_MSGS(("extended(%x) ", sc->sc_imess[2]));
|
|
|
|
switch (sc->sc_imess[2]) {
|
|
|
|
case MSG_EXT_SDTR:
|
|
|
|
NCR_MSGS(("SDTR period %d, offset %d ",
|
|
|
|
sc->sc_imess[3], sc->sc_imess[4]));
|
|
|
|
if (sc->sc_imess[1] != 3)
|
|
|
|
goto reject;
|
|
|
|
ti->period = sc->sc_imess[3];
|
|
|
|
ti->offset = sc->sc_imess[4];
|
|
|
|
ti->flags &= ~T_NEGOTIATE;
|
|
|
|
if (sc->sc_minsync == 0 ||
|
|
|
|
ti->offset == 0 ||
|
|
|
|
ti->period > 124) {
|
1998-11-30 10:34:06 +03:00
|
|
|
#ifdef NCR53C9X_DEBUG
|
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
|
|
|
printf("async mode\n");
|
|
|
|
#endif
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_flags&NCR_SYNCHNEGO) == 0) {
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* target initiated negotiation
|
|
|
|
*/
|
|
|
|
ti->offset = 0;
|
|
|
|
ti->flags &= ~T_SYNCMODE;
|
|
|
|
ncr53c9x_sched_msgout(
|
|
|
|
SEND_SDTR);
|
|
|
|
} else {
|
|
|
|
/* we are async */
|
|
|
|
ti->flags &= ~T_SYNCMODE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int r = 250/ti->period;
|
|
|
|
int s = (100*250)/ti->period - 100*r;
|
|
|
|
int p;
|
|
|
|
|
|
|
|
p = ncr53c9x_stp2cpb(sc, ti->period);
|
|
|
|
ti->period = ncr53c9x_cpb2stp(sc, p);
|
|
|
|
#ifdef NCR53C9X_DEBUG
|
1997-08-27 15:22:52 +04:00
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
2000-03-10 02:19:26 +03:00
|
|
|
printf("max sync rate %d.%02dMB/s\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
r, s);
|
|
|
|
#endif
|
1998-01-24 18:33:35 +03:00
|
|
|
if ((sc->sc_flags&NCR_SYNCHNEGO) == 0) {
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* target initiated negotiation
|
|
|
|
*/
|
|
|
|
if (ti->period <
|
|
|
|
sc->sc_minsync)
|
|
|
|
ti->period =
|
|
|
|
sc->sc_minsync;
|
|
|
|
if (ti->offset > 15)
|
|
|
|
ti->offset = 15;
|
|
|
|
ti->flags &= ~T_SYNCMODE;
|
|
|
|
ncr53c9x_sched_msgout(
|
|
|
|
SEND_SDTR);
|
|
|
|
} else {
|
|
|
|
/* we are sync */
|
|
|
|
ti->flags |= T_SYNCMODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_flags &= ~NCR_SYNCHNEGO;
|
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
break;
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
case MSG_EXT_WDTR:
|
|
|
|
printf("%s: wide mode %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_imess[3]);
|
|
|
|
if (sc->sc_imess[3] == 1) {
|
|
|
|
ti->cfg3 |= NCRFASCFG3_EWIDE;
|
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
}
|
|
|
|
ti->flags &= ~T_WIDE;
|
|
|
|
break;
|
1997-02-27 04:12:07 +03:00
|
|
|
default:
|
1998-11-30 10:44:24 +03:00
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
|
|
|
printf("unrecognized MESSAGE EXTENDED;"
|
|
|
|
" sending REJECT\n");
|
1997-02-27 04:12:07 +03:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NCR_MSGS(("ident "));
|
1998-11-30 10:44:24 +03:00
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
|
|
|
printf("unrecognized MESSAGE; sending REJECT\n");
|
1997-02-27 04:12:07 +03:00
|
|
|
reject:
|
|
|
|
ncr53c9x_sched_msgout(SEND_REJECT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
case NCR_IDENTIFIED:
|
2001-03-29 06:58:38 +04:00
|
|
|
/*
|
|
|
|
* IDENTIFY message was received and queue tag is expected now
|
|
|
|
*/
|
|
|
|
if ((sc->sc_imess[0] != MSG_SIMPLE_Q_TAG) ||
|
|
|
|
(sc->sc_msgify == 0)) {
|
|
|
|
printf("%s: TAG reselect without IDENTIFY;"
|
|
|
|
" MSG %x;"
|
|
|
|
" sending DEVICE RESET\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_imess[0]);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
(void) ncr53c9x_reselect(sc, sc->sc_msgify,
|
|
|
|
sc->sc_imess[0], sc->sc_imess[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NCR_RESELECTED:
|
|
|
|
if (MSG_ISIDENTIFY(sc->sc_imess[1])) {
|
|
|
|
sc->sc_msgify = sc->sc_imess[1];
|
2000-11-30 03:19:25 +03:00
|
|
|
} else {
|
1998-11-30 10:54:29 +03:00
|
|
|
printf("%s: reselect without IDENTIFY;"
|
2000-11-30 03:19:25 +03:00
|
|
|
" MSG %x;"
|
1998-11-30 10:54:29 +03:00
|
|
|
" sending DEVICE RESET\n",
|
2000-11-30 12:58:03 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_imess[1]);
|
1997-02-27 04:12:07 +03:00
|
|
|
goto reset;
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
(void) ncr53c9x_reselect(sc, sc->sc_msgify, 0, 0);
|
1997-02-27 04:12:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1998-11-30 10:54:29 +03:00
|
|
|
printf("%s: unexpected MESSAGE IN; sending DEVICE RESET\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-02-27 04:12:07 +03:00
|
|
|
reset:
|
|
|
|
ncr53c9x_sched_msgout(SEND_DEV_RESET);
|
|
|
|
break;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
ncr53c9x_sched_msgout(SEND_ABORT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-20 06:19:34 +03:00
|
|
|
/* if we have more messages to send set ATN */
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_msgpriq)
|
|
|
|
NCRCMD(sc, NCRCMD_SETATN);
|
2000-12-20 06:19:34 +03:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/* Ack last message byte */
|
|
|
|
NCRCMD(sc, NCRCMD_MSGOK);
|
|
|
|
|
|
|
|
/* Done, reset message pointer. */
|
|
|
|
sc->sc_flags &= ~NCR_DROP_MSGI;
|
|
|
|
sc->sc_imlen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the highest priority, scheduled message
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ncr53c9x_msgout(sc)
|
2000-03-29 17:57:51 +04:00
|
|
|
struct ncr53c9x_softc *sc;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
NCR_TRACE(("[ncr53c9x_msgout(priq:%x, prevphase:%x)]",
|
|
|
|
sc->sc_msgpriq, sc->sc_prevphase));
|
|
|
|
|
1998-01-24 18:33:35 +03:00
|
|
|
/*
|
|
|
|
* XXX - the NCR_ATN flag is not in sync with the actual ATN
|
|
|
|
* condition on the SCSI bus. The 53c9x chip
|
|
|
|
* automatically turns off ATN before sending the
|
|
|
|
* message byte. (see also the comment below in the
|
|
|
|
* default case when picking out a message to send)
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_flags & NCR_ATN) {
|
|
|
|
if (sc->sc_prevphase != MESSAGE_OUT_PHASE) {
|
|
|
|
new:
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
2000-12-20 06:19:34 +03:00
|
|
|
/* DELAY(1); */
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_msgoutq = 0;
|
|
|
|
sc->sc_omlen = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_prevphase == MESSAGE_OUT_PHASE) {
|
|
|
|
ncr53c9x_sched_msgout(sc->sc_msgoutq);
|
|
|
|
goto new;
|
|
|
|
} else {
|
|
|
|
printf("%s at line %d: unexpected MESSAGE OUT phase\n",
|
|
|
|
sc->sc_dev.dv_xname, __LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_omlen == 0) {
|
|
|
|
/* Pick up highest priority message */
|
|
|
|
sc->sc_msgout = sc->sc_msgpriq & -sc->sc_msgpriq;
|
|
|
|
sc->sc_msgoutq |= sc->sc_msgout;
|
|
|
|
sc->sc_msgpriq &= ~sc->sc_msgout;
|
|
|
|
sc->sc_omlen = 1; /* "Default" message len */
|
|
|
|
switch (sc->sc_msgout) {
|
|
|
|
case SEND_SDTR:
|
|
|
|
ecb = sc->sc_nexus;
|
1997-08-27 15:22:52 +04:00
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
1997-02-27 04:12:07 +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;
|
|
|
|
if ((sc->sc_flags & NCR_SYNCHNEGO) == 0) {
|
|
|
|
ti->flags |= T_SYNCMODE;
|
|
|
|
ncr53c9x_setsync(sc, ti);
|
|
|
|
}
|
|
|
|
break;
|
2001-03-29 06:58:38 +04:00
|
|
|
case SEND_WDTR:
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
|
|
|
sc->sc_omess[0] = MSG_EXTENDED;
|
|
|
|
sc->sc_omess[1] = 2;
|
|
|
|
sc->sc_omess[2] = MSG_EXT_WDTR;
|
|
|
|
sc->sc_omess[3] = ti->width;
|
|
|
|
sc->sc_omlen = 4;
|
|
|
|
break;
|
2000-11-30 03:19:25 +03:00
|
|
|
case SEND_IDENTIFY:
|
|
|
|
if (sc->sc_state != NCR_CONNECTED) {
|
|
|
|
printf("%s at line %d: no nexus\n",
|
|
|
|
sc->sc_dev.dv_xname, __LINE__);
|
|
|
|
}
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
sc->sc_omess[0] =
|
|
|
|
MSG_IDENTIFY(ecb->xs->sc_link->scsipi_scsi.lun, 0);
|
|
|
|
break;
|
|
|
|
case SEND_TAG:
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state != NCR_CONNECTED) {
|
|
|
|
printf("%s at line %d: no nexus\n",
|
|
|
|
sc->sc_dev.dv_xname, __LINE__);
|
|
|
|
}
|
|
|
|
ecb = sc->sc_nexus;
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_omess[0] = ecb->tag[0];
|
|
|
|
sc->sc_omess[1] = ecb->tag[1];
|
|
|
|
sc->sc_omlen = 2;
|
1997-02-27 04:12:07 +03:00
|
|
|
break;
|
|
|
|
case SEND_DEV_RESET:
|
|
|
|
sc->sc_flags |= NCR_ABORTING;
|
|
|
|
sc->sc_omess[0] = MSG_BUS_DEV_RESET;
|
|
|
|
ecb = sc->sc_nexus;
|
1997-08-27 15:22:52 +04:00
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
1997-02-27 04:12:07 +03:00
|
|
|
ti->flags &= ~T_SYNCMODE;
|
2000-11-13 18:24:22 +03:00
|
|
|
if ((ti->flags & T_SYNCHOFF) == 0)
|
|
|
|
/* We can re-start sync negotiation */
|
|
|
|
ti->flags |= T_NEGOTIATE;
|
1997-02-27 04:12:07 +03:00
|
|
|
break;
|
|
|
|
case SEND_PARITY_ERROR:
|
|
|
|
sc->sc_omess[0] = MSG_PARITY_ERROR;
|
|
|
|
break;
|
|
|
|
case SEND_ABORT:
|
|
|
|
sc->sc_flags |= NCR_ABORTING;
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
default:
|
1998-01-24 18:33:35 +03:00
|
|
|
/*
|
|
|
|
* We normally do not get here, since the chip
|
|
|
|
* automatically turns off ATN before the last
|
|
|
|
* byte of a message is sent to the target.
|
|
|
|
* However, if the target rejects our (multi-byte)
|
|
|
|
* message early by switching to MSG IN phase
|
|
|
|
* ATN remains on, so the target may return to
|
|
|
|
* MSG OUT phase. If there are no scheduled messages
|
|
|
|
* left we send a NO-OP.
|
|
|
|
*
|
|
|
|
* XXX - Note that this leaves no useful purpose for
|
|
|
|
* the NCR_ATN flag.
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_flags &= ~NCR_ATN;
|
|
|
|
sc->sc_omess[0] = MSG_NOOP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_omp = sc->sc_omess;
|
|
|
|
}
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("<msgout:"));
|
2000-12-01 02:01:03 +03:00
|
|
|
for (i = 0; i < sc->sc_omlen; i++)
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC((" %02x", sc->sc_omess[i]));
|
|
|
|
NCR_MISC(("> "));
|
2000-11-30 03:19:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_rev == NCR_VARIANT_FAS366) {
|
|
|
|
/*
|
|
|
|
* XXX fifo size
|
|
|
|
*/
|
|
|
|
ncr53c9x_flushfifo(sc);
|
|
|
|
ncr53c9x_wrfifo(sc, sc->sc_omp, sc->sc_omlen);
|
|
|
|
NCRCMD(sc, NCRCMD_TRANS);
|
|
|
|
} else {
|
|
|
|
/* (re)send the message */
|
|
|
|
size = min(sc->sc_omlen, sc->sc_maxxfer);
|
|
|
|
NCRDMA_SETUP(sc, &sc->sc_omp, &sc->sc_omlen, 0, &size);
|
|
|
|
/* Program the SCSI counter */
|
|
|
|
NCR_SET_COUNT(sc, size);
|
|
|
|
|
|
|
|
/* Load the count in and start the message-out transfer */
|
|
|
|
NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
|
|
|
|
NCRCMD(sc, NCRCMD_TRANS|NCRCMD_DMA);
|
|
|
|
NCRDMA_GO(sc);
|
1997-02-27 04:12:07 +03: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.
|
|
|
|
*/
|
|
|
|
int
|
2000-03-19 01:09:32 +03:00
|
|
|
ncr53c9x_intr(arg)
|
|
|
|
void *arg;
|
1997-02-27 04:12:07 +03:00
|
|
|
{
|
2000-03-29 17:57:51 +04:00
|
|
|
struct ncr53c9x_softc *sc = arg;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
struct scsipi_link *sc_link;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
size_t size;
|
1997-03-27 03:29:57 +03:00
|
|
|
int nfifo;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_MISC(("[ncr53c9x_intr: state %d]", sc->sc_state));
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
if (!NCRDMA_ISINTR(sc))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
again:
|
|
|
|
/* and what do the registers say... */
|
|
|
|
ncr53c9x_readregs(sc);
|
|
|
|
|
|
|
|
sc->sc_intrcnt.ev_count++;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04:00
|
|
|
* At the moment, only a SCSI Bus Reset or Illegal
|
|
|
|
* Command are classed as errors. A disconnect is a
|
|
|
|
* valid condition, and we let the code check is the
|
|
|
|
* "NCR_BUSFREE_OK" flag was set before declaring it
|
|
|
|
* and error.
|
1997-02-27 04:12:07 +03:00
|
|
|
*
|
1998-05-04 18:47:48 +04:00
|
|
|
* 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
|
1997-02-27 04:12:07 +03:00
|
|
|
*
|
1998-05-04 18:47:48 +04:00
|
|
|
* TODO
|
|
|
|
* If there are too many parity error, go to slow
|
|
|
|
* cable mode ?
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
|
|
|
|
/* SCSI Reset */
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espintr & NCRINTR_SBR) != 0) {
|
|
|
|
if ((NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
if (sc->sc_state != NCR_SBR) {
|
|
|
|
printf("%s: SCSI bus reset\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
ncr53c9x_init(sc, 0); /* Restart everything */
|
|
|
|
return (1);
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
#if 0
|
1998-05-04 18:47:48 +04:00
|
|
|
/*XXX*/ printf("<expected bus reset: "
|
|
|
|
"[intr %x, stat %x, step %d]>\n",
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
1997-02-27 04:12:07 +03:00
|
|
|
#endif
|
2000-12-01 02:01:03 +03:00
|
|
|
if (sc->sc_nexus != NULL)
|
1998-05-04 18:47:48 +04:00
|
|
|
panic("%s: nexus in reset state",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto sched;
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
ecb = sc->sc_nexus;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
#define NCRINTR_ERR (NCRINTR_SBR|NCRINTR_ILL)
|
|
|
|
if (sc->sc_espintr & NCRINTR_ERR ||
|
|
|
|
sc->sc_espstat & NCRSTAT_GE) {
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espstat & NCRSTAT_GE) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
/* Gross Error; no target ? */
|
1997-02-27 04:12:07 +03:00
|
|
|
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
if (sc->sc_state == NCR_CONNECTED ||
|
|
|
|
sc->sc_state == NCR_SELECTING) {
|
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
|
|
|
ncr53c9x_done(sc, ecb);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espintr & NCRINTR_ILL) != 0) {
|
|
|
|
if ((sc->sc_flags & NCR_EXPECT_ILLCMD) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
/*
|
|
|
|
* Eat away "Illegal command" interrupt
|
|
|
|
* on a ESP100 caused by a re-selection
|
|
|
|
* while we were trying to select
|
|
|
|
* another target.
|
|
|
|
*/
|
1997-09-01 03:09:58 +04:00
|
|
|
#ifdef DEBUG
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("%s: ESP100 work-around activated\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-09-01 03:09:58 +04:00
|
|
|
#endif
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_flags &= ~NCR_EXPECT_ILLCMD;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
/* illegal command, out of sync ? */
|
|
|
|
printf("%s: illegal command: 0x%x "
|
|
|
|
"(state %d, phase %x, prevphase %x)\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_lastcmd,
|
|
|
|
sc->sc_state, sc->sc_phase,
|
|
|
|
sc->sc_prevphase);
|
|
|
|
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
DELAY(1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_init(sc, 1); /* Restart everything */
|
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
|
|
|
sc->sc_flags &= ~NCR_EXPECT_ILLCMD;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +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.
|
|
|
|
*/
|
|
|
|
if (NCRDMA_ISACTIVE(sc)) {
|
|
|
|
int r = NCRDMA_INTR(sc);
|
|
|
|
if (r == -1) {
|
|
|
|
printf("%s: DMA error; resetting\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
}
|
|
|
|
/* If DMA active here, then go back to work... */
|
|
|
|
if (NCRDMA_ISACTIVE(sc))
|
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
|
|
|
|
/*
|
|
|
|
* DMA not completed. If we can not find a
|
|
|
|
* acceptable explanation, print a diagnostic.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state == NCR_SELECTING)
|
1998-01-24 18:33:35 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04:00
|
|
|
* This can happen if we are reselected
|
|
|
|
* while using DMA to select a target.
|
1998-01-24 18:33:35 +03:00
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
/*void*/;
|
|
|
|
else if (sc->sc_prevphase == MESSAGE_OUT_PHASE) {
|
|
|
|
/*
|
|
|
|
* Our (multi-byte) message (eg SDTR) was
|
|
|
|
* interrupted by the target to send
|
|
|
|
* a MSG REJECT.
|
|
|
|
* Print diagnostic if current phase
|
|
|
|
* is not MESSAGE IN.
|
|
|
|
*/
|
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE)
|
|
|
|
printf("%s: !TC on MSG OUT"
|
|
|
|
" [intr %x, stat %x, step %d]"
|
1999-02-12 03:50:09 +03:00
|
|
|
" prevphase %x, resid %lx\n",
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr,
|
|
|
|
sc->sc_espstat,
|
|
|
|
sc->sc_espstep,
|
|
|
|
sc->sc_prevphase,
|
1999-02-12 03:50:09 +03:00
|
|
|
(u_long)sc->sc_omlen);
|
1998-05-04 18:47:48 +04:00
|
|
|
} else if (sc->sc_dleft == 0) {
|
|
|
|
/*
|
|
|
|
* The DMA operation was started for
|
|
|
|
* a DATA transfer. Print a diagnostic
|
|
|
|
* if the DMA counter and TC bit
|
|
|
|
* appear to be out of sync.
|
|
|
|
*/
|
|
|
|
printf("%s: !TC on DATA XFER"
|
|
|
|
" [intr %x, stat %x, step %d]"
|
|
|
|
" 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);
|
1998-01-24 18:33:35 +03:00
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
/*
|
|
|
|
* Check for less serious errors.
|
|
|
|
*/
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espstat & NCRSTAT_PE) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("%s: SCSI bus parity error\n", sc->sc_dev.dv_xname);
|
|
|
|
if (sc->sc_prevphase == MESSAGE_IN_PHASE)
|
|
|
|
ncr53c9x_sched_msgout(SEND_PARITY_ERROR);
|
|
|
|
else
|
|
|
|
ncr53c9x_sched_msgout(SEND_INIT_DET_ERR);
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espintr & NCRINTR_DIS) != 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_msgify = 0;
|
1998-05-04 18:47:48 +04:00
|
|
|
NCR_MISC(("<DISC [intr %x, stat %x, step %d]>",
|
|
|
|
sc->sc_espintr,sc->sc_espstat,sc->sc_espstep));
|
|
|
|
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
2000-12-20 06:19:34 +03:00
|
|
|
/* DELAY(1); */
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04:00
|
|
|
* This command must (apparently) be issued within
|
|
|
|
* 250mS of a disconnect. So here you are...
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
NCRCMD(sc, NCRCMD_ENSEL);
|
1998-01-24 18:33:35 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
switch (sc->sc_state) {
|
|
|
|
case NCR_RESELECTED:
|
|
|
|
goto sched;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
case NCR_SELECTING:
|
|
|
|
{
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
ecb->xs->error = XS_SELTIMEOUT;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
/* Selection timeout -- discard all LUNs if empty */
|
|
|
|
sc_link = ecb->xs->sc_link;
|
|
|
|
ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_FIRST(&ti->luns);
|
|
|
|
while (li != NULL) {
|
|
|
|
if (li->untagged == NULL && li->used == 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
if (li->lun < NCR_NLUN)
|
|
|
|
ti->lun[li->lun] = NULL;
|
|
|
|
LIST_REMOVE(li, link);
|
|
|
|
free(li, M_DEVBUF);
|
|
|
|
/* Restart the search at the beginning */
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_FIRST(&ti->luns);
|
2000-11-30 03:19:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_NEXT(li, link);
|
2000-11-30 03:19:25 +03:00
|
|
|
}
|
|
|
|
goto finish;
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_CONNECTED:
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_flags & NCR_SYNCHNEGO) != 0) {
|
1997-02-27 04:12:07 +03:00
|
|
|
#ifdef NCR53C9X_DEBUG
|
2000-12-01 02:01:03 +03:00
|
|
|
if (ecb != NULL)
|
1998-05-04 18:47:48 +04:00
|
|
|
scsi_print_addr(ecb->xs->sc_link);
|
|
|
|
printf("sync nego not completed!\n");
|
1997-02-27 04:12:07 +03:00
|
|
|
#endif
|
1998-05-04 18:47:48 +04:00
|
|
|
ti = &sc->sc_tinfo[ecb->xs->sc_link->scsipi_scsi.target];
|
|
|
|
sc->sc_flags &= ~NCR_SYNCHNEGO;
|
|
|
|
ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
/* it may be OK to disconnect */
|
|
|
|
if ((sc->sc_flags & NCR_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.
|
|
|
|
*/
|
|
|
|
printf("%s: unexpected disconnect; ",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((ecb->flags & ECB_SENSE) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("resetting\n");
|
|
|
|
goto reset;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("sending REQUEST SENSE\n");
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&ecb->xs->xs_callout);
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_sense(sc, ecb);
|
|
|
|
goto out;
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
|
|
|
goto finish;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_DISCONNECT:
|
|
|
|
sc->sc_nexus = NULL;
|
|
|
|
goto sched;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_CMDCOMPLETE:
|
|
|
|
goto finish;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
switch (sc->sc_state) {
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_SBR:
|
|
|
|
printf("%s: waiting for SCSI Bus Reset to happen\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
case NCR_RESELECTED:
|
|
|
|
/*
|
|
|
|
* we must be continuing a message ?
|
|
|
|
*/
|
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE) {
|
|
|
|
printf("%s: target didn't identify\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
printf("<<RESELECT CONT'd>>");
|
|
|
|
#if XXXX
|
|
|
|
ncr53c9x_msgin(sc);
|
|
|
|
if (sc->sc_state != NCR_CONNECTED) {
|
|
|
|
/* IDENTIFY fail?! */
|
|
|
|
printf("%s: identify failed\n",
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_dev.dv_xname, sc->sc_state);
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
case NCR_IDENTIFIED:
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE) {
|
|
|
|
int i = (NCR_READ_REG(sc, NCR_FFLAG)
|
|
|
|
& NCRFIFO_FF);
|
|
|
|
/*
|
|
|
|
* Things are seriously fucked up.
|
|
|
|
* Pull the brakes, i.e. reset
|
|
|
|
*/
|
|
|
|
printf("%s: target didn't send tag: %d bytes in fifo\n",
|
|
|
|
sc->sc_dev.dv_xname, i);
|
|
|
|
/* Drain and display fifo */
|
|
|
|
while (i-- > 0)
|
|
|
|
printf("[%d] ", NCR_READ_REG(sc, NCR_FIFO));
|
|
|
|
|
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
return (1);
|
|
|
|
} else
|
|
|
|
goto msgin;
|
|
|
|
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_IDLE:
|
|
|
|
case NCR_SELECTING:
|
|
|
|
ecb = sc->sc_nexus;
|
|
|
|
if (sc->sc_espintr & NCRINTR_RESEL) {
|
2000-12-19 02:39:44 +03:00
|
|
|
sc->sc_msgpriq = sc->sc_msgout = sc->sc_msgoutq = 0;
|
|
|
|
sc->sc_flags = 0;
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04:00
|
|
|
* If we're trying to select a
|
|
|
|
* target ourselves, push our command
|
|
|
|
* back into the ready list.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
if (sc->sc_state == NCR_SELECTING) {
|
|
|
|
NCR_MISC(("backoff selector "));
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&ecb->xs->xs_callout);
|
2000-11-30 03:19:25 +03:00
|
|
|
ncr53c9x_dequeue(sc, ecb);
|
1998-05-04 18:47:48 +04:00
|
|
|
TAILQ_INSERT_HEAD(&sc->ready_list, ecb, chain);
|
2000-11-30 03:19:25 +03:00
|
|
|
ecb->flags |= ECB_READY;
|
1998-05-04 18:47:48 +04:00
|
|
|
ecb = sc->sc_nexus = NULL;
|
|
|
|
}
|
|
|
|
sc->sc_state = NCR_RESELECTED;
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_phase != MESSAGE_IN_PHASE) {
|
1998-05-04 18:47:48 +04:00
|
|
|
/*
|
|
|
|
* Things are seriously fucked up.
|
|
|
|
* Pull the brakes, i.e. reset
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
printf("%s: target didn't identify\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
ncr53c9x_init(sc, 1);
|
1998-05-04 18:47:48 +04:00
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
/*
|
|
|
|
* The C90 only inhibits FIFO writes until
|
|
|
|
* reselection is complete, instead of
|
|
|
|
* waiting until the interrupt status register
|
|
|
|
* has been read. So, if the reselect happens
|
|
|
|
* while we were entering a command bytes (for
|
|
|
|
* another target) some of those bytes can
|
|
|
|
* appear in the FIFO here, after the
|
|
|
|
* interrupt is taken.
|
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
nfifo = ncr53c9x_rdfifo(sc, NCR_RDFIFO_START);
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
if (nfifo < 2 ||
|
|
|
|
(nfifo > 2 &&
|
|
|
|
sc->sc_rev != NCR_VARIANT_ESP100)) {
|
|
|
|
printf("%s: RESELECT: %d bytes in FIFO! "
|
|
|
|
"[intr %x, stat %x, step %d, prevphase %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
nfifo,
|
|
|
|
sc->sc_espintr,
|
|
|
|
sc->sc_espstat,
|
|
|
|
sc->sc_espstep,
|
|
|
|
sc->sc_prevphase);
|
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
return (1);
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_selid = sc->sc_imess[0];
|
|
|
|
NCR_MISC(("selid=%02x ", sc->sc_selid));
|
1998-05-04 18:47:48 +04:00
|
|
|
|
|
|
|
/* Handle identify message */
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_msgin(sc);
|
1998-05-04 18:47:48 +04:00
|
|
|
if (nfifo != 2) {
|
|
|
|
/*
|
|
|
|
* Note: this should not happen
|
|
|
|
* with `dmaselect' on.
|
|
|
|
*/
|
|
|
|
sc->sc_flags |= NCR_EXPECT_ILLCMD;
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
2001-03-29 06:58:38 +04:00
|
|
|
} else if (sc->sc_features & NCR_F_DMASELECT &&
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_rev == NCR_VARIANT_ESP100) {
|
|
|
|
sc->sc_flags |= NCR_EXPECT_ILLCMD;
|
|
|
|
}
|
|
|
|
|
2000-11-30 03:19:25 +03:00
|
|
|
if (sc->sc_state != NCR_CONNECTED &&
|
|
|
|
sc->sc_state != NCR_IDENTIFIED) {
|
1997-02-27 04:12:07 +03:00
|
|
|
/* IDENTIFY fail?! */
|
2001-03-29 06:58:38 +04:00
|
|
|
printf("%s: identify failed, state %d, intr %02x\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_state,
|
|
|
|
sc->sc_espintr);
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_init(sc, 1);
|
1998-05-04 18:47:48 +04:00
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
goto shortcut; /* ie. next phase expected soon */
|
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
#define NCRINTR_DONE (NCRINTR_FC|NCRINTR_BS)
|
|
|
|
if ((sc->sc_espintr & NCRINTR_DONE) == NCRINTR_DONE) {
|
|
|
|
/*
|
|
|
|
* Arbitration won; examine the `step' register
|
|
|
|
* to determine how far the selection could progress.
|
|
|
|
*/
|
1997-04-02 02:10:04 +04:00
|
|
|
ecb = sc->sc_nexus;
|
2000-12-01 02:01:03 +03:00
|
|
|
if (ecb == NULL)
|
1998-11-30 10:44:24 +03:00
|
|
|
panic("ncr53c9x: no nexus");
|
1998-05-04 18:47:48 +04:00
|
|
|
|
|
|
|
sc_link = ecb->xs->sc_link;
|
|
|
|
ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
switch (sc->sc_espstep) {
|
|
|
|
case 0:
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04:00
|
|
|
* The target did not respond with a
|
|
|
|
* message out phase - probably an old
|
|
|
|
* device that doesn't recognize ATN.
|
|
|
|
* Clear ATN and just continue, the
|
|
|
|
* target should be in the command
|
|
|
|
* phase.
|
|
|
|
* XXXX check for command phase?
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
1998-05-04 18:47:48 +04:00
|
|
|
NCRCMD(sc, NCRCMD_RSTATN);
|
|
|
|
break;
|
|
|
|
case 1:
|
2000-12-10 22:25:07 +03:00
|
|
|
if ((ti->flags & T_NEGOTIATE) == 0 &&
|
|
|
|
ecb->tag[0] == 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("%s: step 1 & !NEG\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto reset;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
if (sc->sc_phase != MESSAGE_OUT_PHASE) {
|
|
|
|
printf("%s: !MSGOUT\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1998-05-04 18:47:48 +04:00
|
|
|
goto reset;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
if (ti->flags & T_WIDE) {
|
|
|
|
ncr53c9x_sched_msgout(SEND_WDTR);
|
|
|
|
}
|
2000-12-10 22:25:07 +03:00
|
|
|
if (ti->flags & T_NEGOTIATE) {
|
|
|
|
/* Start negotiating */
|
|
|
|
ti->period = sc->sc_minsync;
|
|
|
|
ti->offset = 15;
|
|
|
|
sc->sc_flags |= NCR_SYNCHNEGO;
|
|
|
|
if (ecb->tag[0])
|
|
|
|
ncr53c9x_sched_msgout(SEND_TAG|SEND_SDTR);
|
|
|
|
else
|
|
|
|
ncr53c9x_sched_msgout(SEND_SDTR);
|
|
|
|
} else {
|
|
|
|
/* Could not do ATN3 so send TAG */
|
|
|
|
ncr53c9x_sched_msgout(SEND_TAG);
|
|
|
|
}
|
2000-11-30 03:19:25 +03:00
|
|
|
sc->sc_prevphase = MESSAGE_OUT_PHASE; /* XXXX */
|
1998-05-04 18:47:48 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
1997-03-27 03:29:57 +03:00
|
|
|
/*
|
1998-05-04 18:47:48 +04: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?)
|
1997-03-27 03:29:57 +03:00
|
|
|
*/
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_features & NCR_F_DMASELECT) {
|
1998-05-04 18:47:48 +04:00
|
|
|
if (sc->sc_cmdlen == 0)
|
1997-04-28 02:08:51 +04:00
|
|
|
/* Hope for the best.. */
|
|
|
|
break;
|
1998-05-04 18:47:48 +04:00
|
|
|
} else if ((NCR_READ_REG(sc, NCR_FFLAG)
|
1997-02-27 04:12:07 +03:00
|
|
|
& NCRFIFO_FF) == 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
/* Hope for the best.. */
|
1997-02-27 04:12:07 +03:00
|
|
|
break;
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
printf("(%s:%d:%d): selection failed;"
|
|
|
|
" %d left in FIFO "
|
|
|
|
"[intr %x, stat %x, step %d]\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
1998-05-04 18:47:48 +04:00
|
|
|
sc_link->scsipi_scsi.target,
|
|
|
|
sc_link->scsipi_scsi.lun,
|
|
|
|
NCR_READ_REG(sc, NCR_FFLAG)
|
|
|
|
& NCRFIFO_FF,
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_sched_msgout(SEND_ABORT);
|
|
|
|
return (1);
|
|
|
|
case 2:
|
|
|
|
/* Select stuck at Command Phase */
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
1999-11-10 03:42:37 +03:00
|
|
|
break;
|
1998-05-04 18:47:48 +04:00
|
|
|
case 4:
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_features & NCR_F_DMASELECT &&
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_cmdlen != 0)
|
|
|
|
printf("(%s:%d:%d): select; "
|
1999-02-12 03:50:09 +03:00
|
|
|
"%lu left in DMA buffer "
|
1998-05-04 18:47:48 +04:00
|
|
|
"[intr %x, stat %x, step %d]\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
1998-05-04 18:47:48 +04:00
|
|
|
sc_link->scsipi_scsi.target,
|
|
|
|
sc_link->scsipi_scsi.lun,
|
1999-02-12 03:50:09 +03:00
|
|
|
(u_long)sc->sc_cmdlen,
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_espintr,
|
|
|
|
sc->sc_espstat,
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_espstep);
|
1998-05-04 18:47:48 +04:00
|
|
|
/* So far, everything went fine */
|
|
|
|
break;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
|
|
|
|
sc->sc_prevphase = INVALID_PHASE; /* ?? */
|
|
|
|
/* Do an implicit RESTORE POINTERS. */
|
|
|
|
sc->sc_dp = ecb->daddr;
|
|
|
|
sc->sc_dleft = ecb->dleft;
|
|
|
|
sc->sc_state = NCR_CONNECTED;
|
1997-02-27 04:12:07 +03:00
|
|
|
break;
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
printf("%s: unexpected status after select"
|
|
|
|
": [intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
DELAY(1);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
if (sc->sc_state == NCR_IDLE) {
|
2000-12-01 02:01:03 +03:00
|
|
|
printf("%s: stray interrupt\n", sc->sc_dev.dv_xname);
|
|
|
|
return (0);
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
break;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case NCR_CONNECTED:
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_flags & NCR_ICCS) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
/* "Initiate Command Complete Steps" in progress */
|
|
|
|
u_char msg;
|
|
|
|
|
|
|
|
sc->sc_flags &= ~NCR_ICCS;
|
|
|
|
|
|
|
|
if (!(sc->sc_espintr & NCRINTR_DONE)) {
|
|
|
|
printf("%s: ICCS: "
|
|
|
|
": [intr %x, stat %x, step %x]\n",
|
1997-02-27 04:12:07 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
ncr53c9x_rdfifo(sc, NCR_RDFIFO_START);
|
|
|
|
if (sc->sc_imlen < 2)
|
|
|
|
printf("%s: can't get status, only %d bytes\n",
|
|
|
|
sc->sc_dev.dv_xname, (int)sc->sc_imlen);
|
|
|
|
ecb->stat = sc->sc_imess[sc->sc_imlen - 2];
|
|
|
|
msg = sc->sc_imess[sc->sc_imlen - 1];
|
1998-05-04 18:47:48 +04:00
|
|
|
NCR_PHASE(("<stat:(%x,%x)>", ecb->stat, msg));
|
|
|
|
if (msg == MSG_CMDCOMPLETE) {
|
|
|
|
ecb->dleft = (ecb->flags & ECB_TENTATIVE_DONE)
|
|
|
|
? 0
|
|
|
|
: sc->sc_dleft;
|
|
|
|
if ((ecb->flags & ECB_SENSE) == 0)
|
|
|
|
ecb->xs->resid = ecb->dleft;
|
|
|
|
sc->sc_state = NCR_CMDCOMPLETE;
|
|
|
|
} else
|
|
|
|
printf("%s: STATUS_PHASE: msg %d\n",
|
|
|
|
sc->sc_dev.dv_xname, msg);
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_imlen = 0;
|
1998-05-04 18:47:48 +04:00
|
|
|
NCRCMD(sc, NCRCMD_MSGOK);
|
|
|
|
goto shortcut; /* ie. wait for disconnect */
|
|
|
|
}
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
default:
|
2001-03-29 06:58:38 +04:00
|
|
|
/* Don't panic: reset. */
|
|
|
|
printf("%s: invalid state: %d",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_state);
|
|
|
|
ncr53c9x_scsi_reset(sc);
|
|
|
|
goto out;
|
|
|
|
#if 0
|
1998-05-04 18:47:48 +04:00
|
|
|
panic("%s: invalid state: %d",
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_state);
|
|
|
|
#endif
|
|
|
|
break;
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
1997-04-28 02:08:51 +04:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
/*
|
|
|
|
* Driver is now in state NCR_CONNECTED, i.e. we
|
|
|
|
* have a current command working the SCSI bus.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state != NCR_CONNECTED || ecb == NULL) {
|
1998-11-30 10:44:24 +03:00
|
|
|
panic("ncr53c9x: no nexus");
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (sc->sc_phase) {
|
|
|
|
case MESSAGE_OUT_PHASE:
|
|
|
|
NCR_PHASE(("MESSAGE_OUT_PHASE "));
|
|
|
|
ncr53c9x_msgout(sc);
|
|
|
|
sc->sc_prevphase = MESSAGE_OUT_PHASE;
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case MESSAGE_IN_PHASE:
|
2000-11-30 03:19:25 +03:00
|
|
|
msgin:
|
1998-05-04 18:47:48 +04:00
|
|
|
NCR_PHASE(("MESSAGE_IN_PHASE "));
|
2000-12-01 02:01:03 +03:00
|
|
|
if ((sc->sc_espintr & NCRINTR_BS) != 0) {
|
2001-03-29 06:58:38 +04:00
|
|
|
if ((sc->sc_rev != NCR_VARIANT_FAS366) ||
|
|
|
|
!(sc->sc_espstat2 & FAS_STAT2_EMPTY)) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
sc->sc_flags |= NCR_WAITI;
|
|
|
|
NCRCMD(sc, NCRCMD_TRANS);
|
2000-12-01 02:01:03 +03:00
|
|
|
} else if ((sc->sc_espintr & NCRINTR_FC) != 0) {
|
1998-05-04 18:47:48 +04:00
|
|
|
if ((sc->sc_flags & NCR_WAITI) == 0) {
|
|
|
|
printf("%s: MSGIN: unexpected FC bit: "
|
|
|
|
"[intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
|
|
|
sc->sc_flags &= ~NCR_WAITI;
|
2001-03-29 06:58:38 +04:00
|
|
|
ncr53c9x_rdfifo(sc,
|
|
|
|
(sc->sc_prevphase == sc->sc_phase) ?
|
|
|
|
NCR_RDFIFO_CONTINUE : NCR_RDFIFO_START);
|
1998-05-04 18:47:48 +04:00
|
|
|
ncr53c9x_msgin(sc);
|
|
|
|
} else {
|
|
|
|
printf("%s: MSGIN: weird bits: "
|
|
|
|
"[intr %x, stat %x, step %x]\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_espintr, sc->sc_espstat,
|
|
|
|
sc->sc_espstep);
|
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
sc->sc_prevphase = MESSAGE_IN_PHASE;
|
1998-05-04 18:47:48 +04:00
|
|
|
goto shortcut; /* i.e. expect data to be ready */
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case COMMAND_PHASE:
|
|
|
|
/*
|
|
|
|
* Send the command block. Normally we don't see this
|
|
|
|
* phase because the SEL_ATN command takes care of
|
|
|
|
* all this. However, we end up here if either the
|
|
|
|
* target or we wanted to exchange some more messages
|
|
|
|
* first (e.g. to start negotiations).
|
|
|
|
*/
|
1997-07-20 20:46:17 +04:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
NCR_PHASE(("COMMAND_PHASE 0x%02x (%d) ",
|
|
|
|
ecb->cmd.cmd.opcode, ecb->clen));
|
|
|
|
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) {
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
2000-12-20 06:19:34 +03:00
|
|
|
/* DELAY(1);*/
|
1998-05-04 18:47:48 +04:00
|
|
|
}
|
2001-03-29 06:58:38 +04:00
|
|
|
if (sc->sc_features & NCR_F_DMASELECT) {
|
1998-05-04 18:47:48 +04:00
|
|
|
size_t size;
|
|
|
|
/* setup DMA transfer for command */
|
|
|
|
size = ecb->clen;
|
|
|
|
sc->sc_cmdlen = size;
|
|
|
|
sc->sc_cmdp = (caddr_t)&ecb->cmd.cmd;
|
|
|
|
NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen,
|
|
|
|
0, &size);
|
1997-02-27 04:12:07 +03:00
|
|
|
/* Program the SCSI counter */
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_SET_COUNT(sc, size);
|
1998-05-04 18:47:48 +04:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/* load the count in */
|
|
|
|
NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
/* start the command transfer */
|
|
|
|
NCRCMD(sc, NCRCMD_TRANS | NCRCMD_DMA);
|
1997-02-27 04:12:07 +03:00
|
|
|
NCRDMA_GO(sc);
|
1998-05-04 18:47:48 +04:00
|
|
|
} else {
|
2001-03-29 06:58:38 +04:00
|
|
|
ncr53c9x_wrfifo(sc, (u_char *)&ecb->cmd.cmd, ecb->clen);
|
1998-05-04 18:47:48 +04:00
|
|
|
NCRCMD(sc, NCRCMD_TRANS);
|
|
|
|
}
|
|
|
|
sc->sc_prevphase = COMMAND_PHASE;
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case DATA_OUT_PHASE:
|
|
|
|
NCR_PHASE(("DATA_OUT_PHASE [%ld] ",(long)sc->sc_dleft));
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
size = min(sc->sc_dleft, sc->sc_maxxfer);
|
|
|
|
NCRDMA_SETUP(sc, &sc->sc_dp, &sc->sc_dleft,
|
|
|
|
0, &size);
|
|
|
|
sc->sc_prevphase = DATA_OUT_PHASE;
|
|
|
|
goto setup_xfer;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case DATA_IN_PHASE:
|
|
|
|
NCR_PHASE(("DATA_IN_PHASE "));
|
|
|
|
if (sc->sc_rev == NCR_VARIANT_ESP100)
|
|
|
|
NCRCMD(sc, NCRCMD_FLUSH);
|
|
|
|
size = min(sc->sc_dleft, sc->sc_maxxfer);
|
|
|
|
NCRDMA_SETUP(sc, &sc->sc_dp, &sc->sc_dleft,
|
|
|
|
1, &size);
|
|
|
|
sc->sc_prevphase = DATA_IN_PHASE;
|
|
|
|
setup_xfer:
|
|
|
|
/* Target returned to data phase: wipe "done" memory */
|
|
|
|
ecb->flags &= ~ECB_TENTATIVE_DONE;
|
|
|
|
|
|
|
|
/* Program the SCSI counter */
|
2001-03-29 06:58:38 +04:00
|
|
|
NCR_SET_COUNT(sc, size);
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
/* load the count in */
|
|
|
|
NCRCMD(sc, NCRCMD_NOP|NCRCMD_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.
|
|
|
|
*/
|
|
|
|
NCRCMD(sc,
|
|
|
|
(size==0?NCRCMD_TRPAD:NCRCMD_TRANS)|NCRCMD_DMA);
|
|
|
|
NCRDMA_GO(sc);
|
|
|
|
return (1);
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case STATUS_PHASE:
|
|
|
|
NCR_PHASE(("STATUS_PHASE "));
|
|
|
|
sc->sc_flags |= NCR_ICCS;
|
|
|
|
NCRCMD(sc, NCRCMD_ICCS);
|
|
|
|
sc->sc_prevphase = STATUS_PHASE;
|
|
|
|
goto shortcut; /* i.e. expect status results soon */
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
case INVALID_PHASE:
|
|
|
|
break;
|
2000-12-01 02:01:03 +03:00
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
default:
|
|
|
|
printf("%s: unexpected bus phase; resetting\n",
|
2000-12-01 02:01:03 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
1998-05-04 18:47:48 +04:00
|
|
|
goto reset;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
return (1);
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
reset:
|
|
|
|
ncr53c9x_init(sc, 1);
|
1998-05-04 18:47:48 +04:00
|
|
|
goto out;
|
1997-02-27 04:12:07 +03:00
|
|
|
|
|
|
|
finish:
|
|
|
|
ncr53c9x_done(sc, ecb);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sched:
|
|
|
|
sc->sc_state = NCR_IDLE;
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
goto out;
|
|
|
|
|
1998-05-04 18:47:48 +04:00
|
|
|
shortcut:
|
|
|
|
/*
|
|
|
|
* 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 a heuristic. It is 2 when at 20Mhz, 2 at 25Mhz and 1
|
|
|
|
* at 40Mhz. This needs testing.
|
|
|
|
*/
|
2000-12-20 06:19:34 +03:00
|
|
|
{
|
|
|
|
struct timeval wait, cur;
|
|
|
|
|
|
|
|
microtime(&wait);
|
|
|
|
wait.tv_usec += 50/sc->sc_freq;
|
|
|
|
if (wait.tv_usec > 1000000) {
|
|
|
|
wait.tv_sec++;
|
|
|
|
wait.tv_usec -= 1000000;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (NCRDMA_ISINTR(sc))
|
|
|
|
goto again;
|
|
|
|
microtime(&cur);
|
|
|
|
} while (cur.tv_sec <= wait.tv_sec &&
|
|
|
|
cur.tv_usec <= wait.tv_usec);
|
|
|
|
}
|
1998-05-04 18:47:48 +04:00
|
|
|
goto out;
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_abort(sc, ecb)
|
|
|
|
struct ncr53c9x_softc *sc;
|
|
|
|
struct ncr53c9x_ecb *ecb;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* 2 secs for the abort */
|
|
|
|
ecb->timeout = NCR_ABORT_TIMEOUT;
|
|
|
|
ecb->flags |= ECB_ABORT;
|
|
|
|
|
|
|
|
if (ecb == sc->sc_nexus) {
|
2000-07-04 05:10:18 +04:00
|
|
|
int timeout;
|
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
/*
|
|
|
|
* If we're still selecting, the message will be scheduled
|
|
|
|
* after selection is complete.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state == NCR_CONNECTED)
|
|
|
|
ncr53c9x_sched_msgout(SEND_ABORT);
|
|
|
|
|
|
|
|
/*
|
2000-03-23 10:01:25 +03:00
|
|
|
* Reschedule timeout.
|
1997-02-27 04:12:07 +03:00
|
|
|
*/
|
2000-07-04 05:10:18 +04:00
|
|
|
timeout = ecb->timeout;
|
|
|
|
if (hz > 100 && timeout > 1000)
|
|
|
|
timeout = (timeout / 1000) * hz;
|
|
|
|
else
|
|
|
|
timeout = (timeout * hz) / 1000;
|
|
|
|
callout_reset(&ecb->xs->xs_callout, timeout,
|
2000-03-23 10:01:25 +03:00
|
|
|
ncr53c9x_timeout, ecb);
|
1997-02-27 04:12:07 +03:00
|
|
|
} else {
|
1998-02-01 02:37:51 +03:00
|
|
|
/*
|
2000-11-30 03:19:25 +03:00
|
|
|
* Just leave the command where it is.
|
1998-02-01 02:37:51 +03:00
|
|
|
* XXX - what choice do we have but to reset the SCSI
|
|
|
|
* eventually?
|
|
|
|
*/
|
1997-02-27 04:12:07 +03:00
|
|
|
if (sc->sc_state == NCR_IDLE)
|
|
|
|
ncr53c9x_sched(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_timeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_ecb *ecb = arg;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = ecb->xs;
|
|
|
|
struct scsipi_link *sc_link = xs->sc_link;
|
1997-02-27 04:12:07 +03:00
|
|
|
struct ncr53c9x_softc *sc = sc_link->adapter_softc;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[sc_link->scsipi_scsi.target];
|
1997-02-27 04:12:07 +03:00
|
|
|
int s;
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
scsi_print_addr(sc_link);
|
1997-02-27 04:12:07 +03:00
|
|
|
printf("%s: timed out [ecb %p (flags 0x%x, dleft %x, stat %x)], "
|
1998-02-01 02:37:51 +03:00
|
|
|
"<state %d, nexus %p, phase(l %x, c %x, p %x), resid %lx, "
|
1997-02-27 04:12:07 +03:00
|
|
|
"msg(q %x,o %x) %s>",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ecb, ecb->flags, ecb->dleft, ecb->stat,
|
1998-02-01 02:37:51 +03:00
|
|
|
sc->sc_state, sc->sc_nexus,
|
|
|
|
NCR_READ_REG(sc, NCR_STAT),
|
|
|
|
sc->sc_phase, sc->sc_prevphase,
|
1997-02-27 04:12:07 +03:00
|
|
|
(long)sc->sc_dleft, sc->sc_msgpriq, sc->sc_msgout,
|
|
|
|
NCRDMA_ISACTIVE(sc) ? "DMA active" : "");
|
1997-04-02 02:10:04 +04:00
|
|
|
#if NCR53C9X_DEBUG > 1
|
1997-02-27 04:12:07 +03:00
|
|
|
printf("TRACE: %s.", ecb->trace);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
if (ecb->flags & ECB_ABORT) {
|
|
|
|
/* abort timed out */
|
|
|
|
printf(" AGAIN\n");
|
1997-07-30 16:01:53 +04:00
|
|
|
|
1997-02-27 04:12:07 +03:00
|
|
|
ncr53c9x_init(sc, 1);
|
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
|
|
|
printf("\n");
|
|
|
|
xs->error = XS_TIMEOUT;
|
|
|
|
ncr53c9x_abort(sc, ecb);
|
1997-07-30 16:01:53 +04:00
|
|
|
|
|
|
|
/* Disable sync mode if stuck in a data phase */
|
|
|
|
if (ecb == sc->sc_nexus &&
|
|
|
|
(ti->flags & T_SYNCMODE) != 0 &&
|
|
|
|
(sc->sc_phase & (MSGI|CDI)) == 0) {
|
1997-08-27 15:22:52 +04:00
|
|
|
scsi_print_addr(sc_link);
|
1997-07-30 16:01:53 +04:00
|
|
|
printf("sync negotiation disabled\n");
|
1997-08-27 15:22:52 +04:00
|
|
|
sc->sc_cfflags |= (1<<(sc_link->scsipi_scsi.target+8));
|
1997-07-30 16:01:53 +04:00
|
|
|
}
|
1997-02-27 04:12:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
2000-11-30 03:19:25 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
ncr53c9x_watch(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
|
|
|
|
struct ncr53c9x_tinfo *ti;
|
|
|
|
struct ncr53c9x_linfo *li;
|
|
|
|
int t, s;
|
|
|
|
/* Delete any structures that have not been used in 10min. */
|
|
|
|
time_t old = time.tv_sec - (10*60);
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
for (t=0; t<NCR_NTARG; t++) {
|
|
|
|
ti = &sc->sc_tinfo[t];
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_FIRST(&ti->luns);
|
2000-11-30 03:19:25 +03:00
|
|
|
while (li) {
|
2000-12-01 02:01:03 +03:00
|
|
|
if (li->last_used < old && li->untagged == NULL &&
|
|
|
|
li->used == 0) {
|
2000-11-30 03:19:25 +03:00
|
|
|
if (li->lun < NCR_NLUN)
|
|
|
|
ti->lun[li->lun] = NULL;
|
|
|
|
LIST_REMOVE(li, link);
|
|
|
|
free(li, M_DEVBUF);
|
|
|
|
/* Restart the search at the beginning */
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_FIRST(&ti->luns);
|
2000-11-30 03:19:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-12-01 02:01:03 +03:00
|
|
|
li = LIST_NEXT(li, link);
|
2000-11-30 03:19:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
callout_reset(&sc->sc_watchdog, 60*hz, ncr53c9x_watch, sc);
|
|
|
|
}
|
2000-12-04 02:25:24 +03:00
|
|
|
|