2001-07-14 00:38:51 +00:00
|
|
|
/* $NecBSD: tmc18c30.c,v 1.28.12.3 2001/06/19 04:35:48 honda Exp $ */
|
2000-10-23 12:55:51 +00:00
|
|
|
/* $NetBSD$ */
|
|
|
|
|
|
|
|
#define STG_DEBUG
|
|
|
|
#define STG_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
#define STG_IO_CONTROL_FLAGS (STG_FIFO_INTERRUPTS | STG_WAIT_FOR_SELECT)
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2000-10-23 12:55:51 +00:00
|
|
|
* [NetBSD for NEC PC-98 series]
|
2001-07-14 00:38:51 +00:00
|
|
|
* Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001
|
2000-10-23 12:55:51 +00:00
|
|
|
* NetBSD/pc98 porting staff. All rights reserved.
|
2001-07-14 00:38:51 +00:00
|
|
|
* Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001
|
2000-10-23 12:55:51 +00:00
|
|
|
* Naofumi HONDA. All rights reserved.
|
|
|
|
* Copyright (c) 1996, 1997, 1998, 1999
|
|
|
|
* Kouichi Matsuda. 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. 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.
|
|
|
|
*/
|
2003-08-24 18:17:24 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
|
|
|
|
#include <sys/bio.h>
|
2001-07-14 00:38:51 +00:00
|
|
|
#endif /* __FreeBSD__ */
|
2000-10-23 12:55:51 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#ifdef __NetBSD__
|
2001-07-14 00:38:51 +00:00
|
|
|
#include <sys/device.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
#include <dev/scsipi/scsi_disk.h>
|
|
|
|
|
|
|
|
#include <machine/dvcfg.h>
|
|
|
|
#include <machine/physio_proc.h>
|
|
|
|
|
|
|
|
#include <i386/Cbus/dev/scsi_low.h>
|
|
|
|
#include <i386/Cbus/dev/tmc18c30reg.h>
|
|
|
|
#include <i386/Cbus/dev/tmc18c30var.h>
|
|
|
|
#endif /* __NetBSD__ */
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2004-03-13 19:46:27 +00:00
|
|
|
#include <compat/netbsd/dvcfg.h>
|
|
|
|
#include <compat/netbsd/physio_proc.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
#include <cam/scsi/scsi_low.h>
|
|
|
|
#include <dev/stg/tmc18c30reg.h>
|
|
|
|
#include <dev/stg/tmc18c30var.h>
|
|
|
|
#endif /* __FreeBSD__ */
|
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* USER SETTINGS
|
|
|
|
***************************************************/
|
|
|
|
/* DEVICE CONFIGURATION FLAGS (MINOR)
|
|
|
|
*
|
|
|
|
* 0x01 DISCONECT OFF
|
|
|
|
* 0x02 PARITY LINE OFF
|
|
|
|
* 0x04 IDENTIFY MSG OFF ( = single lun)
|
|
|
|
* 0x08 SYNC TRANSFER OFF
|
|
|
|
*/
|
|
|
|
/* #define STG_SYNC_SUPPORT */ /* NOT YET but easy */
|
|
|
|
|
|
|
|
/* For the 512 fifo type: change below */
|
|
|
|
#define TMC18C30_FIFOSZ 0x800
|
2001-07-14 00:38:51 +00:00
|
|
|
#define TMC18C30_FCBSZ 0x200
|
2000-10-23 12:55:51 +00:00
|
|
|
#define TMC18C50_FIFOSZ 0x2000
|
2001-07-14 00:38:51 +00:00
|
|
|
#define TMC18C50_FCBSZ 0x400
|
|
|
|
|
|
|
|
#define STG_MAX_DATA_SIZE (64 * 1024)
|
|
|
|
#define STG_DELAY_MAX (2 * 1000 * 1000)
|
|
|
|
#define STG_DELAY_INTERVAL (1)
|
|
|
|
#define STG_DELAY_SELECT_POLLING_MAX (5 * 1000 * 1000)
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* PARAMS
|
|
|
|
***************************************************/
|
|
|
|
#define STG_NTARGETS 8
|
|
|
|
#define STG_NLUNS 8
|
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* DEBUG
|
|
|
|
***************************************************/
|
|
|
|
#ifdef STG_DEBUG
|
2002-01-08 19:37:12 +00:00
|
|
|
static int stg_debug;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* STG_DEBUG */
|
|
|
|
|
|
|
|
#ifdef STG_STATICS
|
2002-01-08 19:37:12 +00:00
|
|
|
static struct stg_statics {
|
2001-07-14 00:38:51 +00:00
|
|
|
int arbit_fail_0;
|
|
|
|
int arbit_fail_1;
|
2000-10-23 12:55:51 +00:00
|
|
|
int disconnect;
|
|
|
|
int reselect;
|
2001-07-14 00:38:51 +00:00
|
|
|
} stg_statics;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* STG_STATICS */
|
|
|
|
|
|
|
|
/***************************************************
|
2001-07-14 00:38:51 +00:00
|
|
|
* IO control flags
|
|
|
|
***************************************************/
|
|
|
|
#define STG_FIFO_INTERRUPTS 0x0001
|
|
|
|
#define STG_WAIT_FOR_SELECT 0x0100
|
|
|
|
|
|
|
|
int stg_io_control = STG_IO_CONTROL_FLAGS;
|
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* DEVICE STRUCTURE
|
2000-10-23 12:55:51 +00:00
|
|
|
***************************************************/
|
|
|
|
extern struct cfdriver stg_cd;
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* DECLARE
|
|
|
|
**************************************************************/
|
|
|
|
/* static */
|
2002-03-20 02:08:01 +00:00
|
|
|
static void stg_pio_read(struct stg_softc *, struct targ_info *, u_int);
|
|
|
|
static void stg_pio_write(struct stg_softc *, struct targ_info *, u_int);
|
|
|
|
static int stg_xfer(struct stg_softc *, u_int8_t *, int, int, int);
|
|
|
|
static int stg_msg(struct stg_softc *, struct targ_info *, u_int);
|
|
|
|
static int stg_reselected(struct stg_softc *);
|
|
|
|
static int stg_disconnected(struct stg_softc *, struct targ_info *);
|
|
|
|
static __inline void stg_pdma_end(struct stg_softc *, struct targ_info *);
|
|
|
|
static int stghw_select_targ_wait(struct stg_softc *, int);
|
|
|
|
static int stghw_check(struct stg_softc *);
|
|
|
|
static void stghw_init(struct stg_softc *);
|
|
|
|
static int stg_negate_signal(struct stg_softc *, u_int8_t, u_char *);
|
|
|
|
static int stg_expect_signal(struct stg_softc *, u_int8_t, u_int8_t);
|
|
|
|
static int stg_world_start(struct stg_softc *, int);
|
|
|
|
static int stghw_start_selection(struct stg_softc *sc, struct slccb *);
|
|
|
|
static void stghw_bus_reset(struct stg_softc *);
|
|
|
|
static void stghw_attention(struct stg_softc *);
|
|
|
|
static int stg_target_nexus_establish(struct stg_softc *);
|
|
|
|
static int stg_lun_nexus_establish(struct stg_softc *);
|
|
|
|
static int stg_ccb_nexus_establish(struct stg_softc *);
|
|
|
|
static int stg_targ_init(struct stg_softc *, struct targ_info *, int);
|
|
|
|
static __inline void stghw_bcr_write_1(struct stg_softc *, u_int8_t);
|
|
|
|
static int stg_timeout(struct stg_softc *);
|
|
|
|
static void stg_selection_done_and_expect_msgout(struct stg_softc *);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
struct scsi_low_funcs stgfuncs = {
|
|
|
|
SC_LOW_INIT_T stg_world_start,
|
|
|
|
SC_LOW_BUSRST_T stghw_bus_reset,
|
2001-02-25 12:40:30 +00:00
|
|
|
SC_LOW_TARG_INIT_T stg_targ_init,
|
2001-07-14 00:38:51 +00:00
|
|
|
SC_LOW_LUN_INIT_T NULL,
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
SC_LOW_SELECT_T stghw_start_selection,
|
2001-07-14 00:38:51 +00:00
|
|
|
SC_LOW_NEXUS_T stg_lun_nexus_establish,
|
|
|
|
SC_LOW_NEXUS_T stg_ccb_nexus_establish,
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
SC_LOW_ATTEN_T stghw_attention,
|
|
|
|
SC_LOW_MSG_T stg_msg,
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
SC_LOW_TIMEOUT_T stg_timeout,
|
2000-10-23 12:55:51 +00:00
|
|
|
SC_LOW_POLL_T stgintr,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************
|
2001-07-14 00:38:51 +00:00
|
|
|
* hwfuncs
|
2000-10-23 12:55:51 +00:00
|
|
|
****************************************************/
|
|
|
|
static __inline void
|
|
|
|
stghw_bcr_write_1(sc, bcv)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
u_int8_t bcv;
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, tmc_bctl, bcv);
|
|
|
|
sc->sc_busimg = bcv;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static int
|
|
|
|
stghw_check(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
u_int fcbsize, fcb;
|
|
|
|
u_int16_t lsb, msb;
|
|
|
|
|
|
|
|
lsb = bus_space_read_1(iot, ioh, tmc_idlsb);
|
|
|
|
msb = bus_space_read_1(iot, ioh, tmc_idmsb);
|
|
|
|
switch (msb << 8 | lsb)
|
|
|
|
{
|
|
|
|
case 0x6127:
|
|
|
|
/* TMCCHIP_1800 not supported. (it's my policy) */
|
|
|
|
sc->sc_chip = TMCCHIP_1800;
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
case 0x60e9:
|
|
|
|
if (bus_space_read_1(iot, ioh, tmc_cfg2) & 0x02)
|
|
|
|
{
|
|
|
|
sc->sc_chip = TMCCHIP_18C30;
|
|
|
|
sc->sc_fsz = TMC18C30_FIFOSZ;
|
|
|
|
fcbsize = TMC18C30_FCBSZ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->sc_chip = TMCCHIP_18C50;
|
|
|
|
sc->sc_fsz = TMC18C50_FIFOSZ;
|
|
|
|
fcbsize = TMC18C50_FCBSZ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sc->sc_chip = TMCCHIP_UNK;
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_fcRinit = FCTL_INTEN;
|
|
|
|
sc->sc_fcWinit = FCTL_PARENB | FCTL_INTEN;
|
|
|
|
|
|
|
|
if (slp->sl_cfgflags & CFG_NOATTEN)
|
|
|
|
sc->sc_imsg = 0;
|
|
|
|
else
|
|
|
|
sc->sc_imsg = BCTL_ATN;
|
|
|
|
sc->sc_busc = BCTL_BUSEN;
|
|
|
|
|
|
|
|
sc->sc_wthold = fcbsize + 256;
|
|
|
|
sc->sc_rthold = fcbsize - 256;
|
|
|
|
sc->sc_maxwsize = sc->sc_fsz;
|
|
|
|
|
|
|
|
fcb = fcbsize / (sc->sc_fsz / 16);
|
|
|
|
sc->sc_icinit = ICTL_CD | ICTL_SEL | ICTL_ARBIT | fcb;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stghw_init(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, 0);
|
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl,
|
|
|
|
sc->sc_fcRinit | FCTL_CLRFIFO | FCTL_CLRINT);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit);
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ssctl, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_targ_init(sc, ti, action)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
|
|
|
int action;
|
|
|
|
{
|
|
|
|
struct stg_targ_info *sti = (void *) ti;
|
|
|
|
|
|
|
|
if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE)
|
|
|
|
{
|
|
|
|
ti->ti_width = SCSI_LOW_BUS_WIDTH_8;
|
|
|
|
ti->ti_maxsynch.period = 0;
|
|
|
|
ti->ti_maxsynch.offset = 0;
|
|
|
|
sti->sti_reg_synch = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************
|
|
|
|
* scsi low interface
|
|
|
|
****************************************************/
|
2000-10-23 12:55:51 +00:00
|
|
|
static void
|
|
|
|
stghw_attention(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
sc->sc_busc |= BCTL_ATN;
|
|
|
|
sc->sc_busimg |= BCTL_ATN;
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, tmc_bctl, sc->sc_busimg);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(10);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stghw_bus_reset(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, 0);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, 0);
|
|
|
|
stghw_bcr_write_1(sc, BCTL_RST);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(100000);
|
2000-10-23 12:55:51 +00:00
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stghw_start_selection(sc, cb)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
struct slccb *cb;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
struct targ_info *ti = cb->ti;
|
|
|
|
register u_int8_t stat;
|
|
|
|
int s;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000;
|
|
|
|
sc->sc_dataout_timeout = 0;
|
|
|
|
sc->sc_ubf_timeout = 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
s = splhigh();
|
2001-07-14 00:38:51 +00:00
|
|
|
stat = bus_space_read_1(iot, ioh, tmc_astat);
|
|
|
|
if ((stat & ASTAT_INT) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
splx(s);
|
|
|
|
return SCSI_LOW_START_FAIL;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_scsiid, sc->sc_idbit);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_ARBIT);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_ARBSTART);
|
|
|
|
return SCSI_LOW_START_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_world_start(sc, fdone)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
int fdone;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
int error;
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
if ((slp->sl_cfgflags & CFG_NOPARITY) == 0)
|
|
|
|
sc->sc_fcRinit |= FCTL_PARENB;
|
|
|
|
else
|
|
|
|
sc->sc_fcRinit &= ~FCTL_PARENB;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if ((error = stghw_check(sc)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
stghw_init(sc);
|
|
|
|
scsi_low_bus_reset(slp);
|
|
|
|
stghw_init(sc);
|
|
|
|
|
|
|
|
SOFT_INTR_REQUIRED(slp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_msg(sc, ti, msg)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
|
|
|
u_int msg;
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-02-25 12:40:30 +00:00
|
|
|
struct stg_targ_info *sti = (void *) ti;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int period, offset;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((msg & SCSI_LOW_MSG_WIDE) != 0)
|
|
|
|
{
|
|
|
|
if (ti->ti_width != SCSI_LOW_BUS_WIDTH_8)
|
|
|
|
{
|
|
|
|
ti->ti_width = SCSI_LOW_BUS_WIDTH_8;
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((msg & SCSI_LOW_MSG_SYNCH) == 0)
|
|
|
|
return 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-02-25 12:40:30 +00:00
|
|
|
period = ti->ti_maxsynch.period;
|
|
|
|
offset = ti->ti_maxsynch.offset;
|
2000-10-23 12:55:51 +00:00
|
|
|
period = period << 2;
|
|
|
|
if (period >= 200)
|
|
|
|
{
|
2001-02-25 12:40:30 +00:00
|
|
|
sti->sti_reg_synch = (period - 200) / 50;
|
2000-10-23 12:55:51 +00:00
|
|
|
if (period % 50)
|
2001-02-25 12:40:30 +00:00
|
|
|
sti->sti_reg_synch ++;
|
|
|
|
sti->sti_reg_synch |= SSCTL_SYNCHEN;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
else if (period >= 100)
|
|
|
|
{
|
2001-02-25 12:40:30 +00:00
|
|
|
sti->sti_reg_synch = (period - 100) / 50;
|
2000-10-23 12:55:51 +00:00
|
|
|
if (period % 50)
|
2001-02-25 12:40:30 +00:00
|
|
|
sti->sti_reg_synch ++;
|
|
|
|
sti->sti_reg_synch |= SSCTL_SYNCHEN | SSCTL_FSYNCHEN;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_ssctl, sti->sti_reg_synch);
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* General probe attach
|
|
|
|
**************************************************************/
|
|
|
|
int
|
|
|
|
stgprobesubr(iot, ioh, dvcfg)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
u_int dvcfg;
|
|
|
|
{
|
|
|
|
u_int16_t lsb, msb;
|
|
|
|
|
|
|
|
lsb = bus_space_read_1(iot, ioh, tmc_idlsb);
|
|
|
|
msb = bus_space_read_1(iot, ioh, tmc_idmsb);
|
|
|
|
switch (msb << 8 | lsb)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case 0x6127:
|
|
|
|
/* not support! */
|
|
|
|
return 0;
|
|
|
|
case 0x60e9:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
stgprint(aux, name)
|
|
|
|
void *aux;
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
printf("%s: scsibus ", name);
|
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
stgattachsubr(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
sc->sc_idbit = (1 << slp->sl_hostid);
|
|
|
|
slp->sl_funcs = &stgfuncs;
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
slp->sl_flags |= HW_READ_PADDING;
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_cfgflags |= CFG_ASYNC; /* XXX */
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
(void) scsi_low_attach(slp, 0, STG_NTARGETS, STG_NLUNS,
|
|
|
|
sizeof(struct stg_targ_info), 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* PDMA functions
|
|
|
|
**************************************************************/
|
|
|
|
static __inline void
|
|
|
|
stg_pdma_end(sc, ti)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
struct slccb *cb = slp->sl_Qnexus;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int len, tres;
|
|
|
|
|
|
|
|
slp->sl_flags &= ~HW_PDMASTART;
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_icinit &= ~ICTL_FIFO;
|
|
|
|
sc->sc_dataout_timeout = 0;
|
|
|
|
|
|
|
|
if (cb == NULL)
|
|
|
|
{
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
goto out;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (ti->ti_phase == PH_DATA)
|
|
|
|
{
|
|
|
|
len = bus_space_read_2(iot, ioh, tmc_fdcnt);
|
|
|
|
if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE)
|
|
|
|
{
|
|
|
|
if (len != 0)
|
|
|
|
{
|
|
|
|
tres = len + slp->sl_scp.scp_datalen;
|
|
|
|
if (tres <= (u_int) cb->ccb_scp.scp_datalen)
|
|
|
|
{
|
|
|
|
slp->sl_scp.scp_data -= len;
|
|
|
|
slp->sl_scp.scp_datalen = tres;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
printf("%s len %x >= datalen %x\n",
|
|
|
|
slp->sl_xname,
|
|
|
|
len, slp->sl_scp.scp_datalen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (slp->sl_scp.scp_direction == SCSI_LOW_READ)
|
|
|
|
{
|
|
|
|
if (len != 0)
|
|
|
|
{
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
printf("%s: len %x left in fifo\n",
|
|
|
|
slp->sl_xname, len);
|
|
|
|
}
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
scsi_low_data_finish(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s data phase miss\n", slp->sl_xname);
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
out:
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_pio_read(sc, ti, thold)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
2001-07-14 00:38:51 +00:00
|
|
|
u_int thold;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
struct sc_p *sp = &slp->sl_scp;
|
2001-07-14 00:38:51 +00:00
|
|
|
int s, tout;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int res;
|
|
|
|
u_int8_t stat;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_flags & HW_PDMASTART) == 0)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl,
|
|
|
|
sc->sc_fcRinit | FCTL_FIFOEN);
|
|
|
|
slp->sl_flags |= HW_PDMASTART;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
tout = sc->sc_tmaxcnt;
|
|
|
|
while (tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
if (thold > 0)
|
|
|
|
{
|
|
|
|
s = splhigh();
|
|
|
|
res = bus_space_read_2(iot, ioh, tmc_fdcnt);
|
|
|
|
if (res < thold)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl,
|
|
|
|
sc->sc_icinit);
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
else
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
stat = bus_space_read_1(iot, ioh, tmc_bstat);
|
2001-07-14 00:38:51 +00:00
|
|
|
res = bus_space_read_2(iot, ioh, tmc_fdcnt);
|
|
|
|
if (res == 0)
|
|
|
|
{
|
|
|
|
if ((stat & PHASE_MASK) != DATA_IN_PHASE)
|
|
|
|
break;
|
|
|
|
if (sp->scp_datalen <= 0)
|
|
|
|
break;
|
|
|
|
SCSI_LOW_DELAY(1);
|
2000-10-23 12:55:51 +00:00
|
|
|
continue;
|
2001-07-14 00:38:51 +00:00
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
/* The assumtion res != 0 is valid here */
|
2000-10-23 12:55:51 +00:00
|
|
|
if (res > sp->scp_datalen)
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
if (res == (u_int) -1)
|
|
|
|
break;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_error |= PDMAERR;
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_flags & HW_READ_PADDING) == 0)
|
|
|
|
{
|
|
|
|
printf("%s: read padding required\n",
|
|
|
|
slp->sl_xname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp->scp_datalen = 0;
|
|
|
|
if (res > STG_MAX_DATA_SIZE)
|
|
|
|
res = STG_MAX_DATA_SIZE;
|
|
|
|
while (res -- > 0)
|
|
|
|
{
|
|
|
|
(void) bus_space_read_1(iot, ioh, tmc_rfifo);
|
|
|
|
}
|
|
|
|
continue;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp->scp_datalen -= res;
|
|
|
|
if (res & 1)
|
|
|
|
{
|
|
|
|
*sp->scp_data = bus_space_read_1(iot, ioh, tmc_rfifo);
|
|
|
|
sp->scp_data ++;
|
|
|
|
res --;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_read_multi_2(iot, ioh, tmc_rfifo,
|
|
|
|
(u_int16_t *) sp->scp_data, res >> 1);
|
|
|
|
sp->scp_data += res;
|
|
|
|
}
|
|
|
|
|
2001-02-25 12:40:30 +00:00
|
|
|
if (tout <= 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: pio read timeout\n", slp->sl_xname);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_pio_write(sc, ti, thold)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
2001-07-14 00:38:51 +00:00
|
|
|
u_int thold;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
struct sc_p *sp = &slp->sl_scp;
|
|
|
|
u_int res;
|
2001-07-14 00:38:51 +00:00
|
|
|
int s, tout;
|
2000-10-23 12:55:51 +00:00
|
|
|
register u_int8_t stat;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_flags & HW_PDMASTART) == 0)
|
|
|
|
{
|
|
|
|
stat = sc->sc_fcWinit | FCTL_FIFOEN | FCTL_FIFOW;
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, stat | FCTL_CLRFIFO);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, stat);
|
|
|
|
slp->sl_flags |= HW_PDMASTART;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
tout = sc->sc_tmaxcnt;
|
|
|
|
while (tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
stat = bus_space_read_1(iot, ioh, tmc_bstat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((stat & PHASE_MASK) != DATA_OUT_PHASE)
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if (sp->scp_datalen <= 0)
|
|
|
|
{
|
|
|
|
if (sc->sc_dataout_timeout == 0)
|
|
|
|
sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thold > 0)
|
|
|
|
{
|
|
|
|
s = splhigh();
|
|
|
|
res = bus_space_read_2(iot, ioh, tmc_fdcnt);
|
|
|
|
if (res > thold)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl,
|
|
|
|
sc->sc_icinit);
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = bus_space_read_2(iot, ioh, tmc_fdcnt);
|
|
|
|
if (res > sc->sc_maxwsize / 2)
|
|
|
|
{
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res == (u_int) -1)
|
|
|
|
break;
|
|
|
|
res = sc->sc_maxwsize - res;
|
|
|
|
if (res > sp->scp_datalen)
|
|
|
|
res = sp->scp_datalen;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
sp->scp_datalen -= res;
|
|
|
|
if ((res & 0x1) != 0)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_wfifo, *sp->scp_data);
|
|
|
|
sp->scp_data ++;
|
|
|
|
res --;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_multi_2(iot, ioh, tmc_wfifo,
|
|
|
|
(u_int16_t *) sp->scp_data, res >> 1);
|
|
|
|
sp->scp_data += res;
|
|
|
|
}
|
|
|
|
|
2001-02-25 12:40:30 +00:00
|
|
|
if (tout <= 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: pio write timeout\n", slp->sl_xname);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_negate_signal(sc, mask, s)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
u_int8_t mask;
|
|
|
|
u_char *s;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t bst = sc->sc_iot;
|
|
|
|
bus_space_handle_t bsh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
int wc;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int8_t regv;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
for (wc = 0; wc < STG_DELAY_MAX / STG_DELAY_INTERVAL; wc ++)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
regv = bus_space_read_1(bst, bsh, tmc_bstat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if (regv == (u_int8_t) -1)
|
|
|
|
return -1;
|
|
|
|
if ((regv & mask) == 0)
|
|
|
|
return 1;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(STG_DELAY_INTERVAL);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
printf("%s: %s stg_negate_signal timeout\n", slp->sl_xname, s);
|
|
|
|
return -1;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_expect_signal(sc, phase, mask)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
u_int8_t phase, mask;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t bst = sc->sc_iot;
|
|
|
|
bus_space_handle_t bsh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
int wc;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int8_t ph;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
phase &= PHASE_MASK;
|
|
|
|
for (wc = 0; wc < STG_DELAY_MAX / STG_DELAY_INTERVAL; wc ++)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
ph = bus_space_read_1(bst, bsh, tmc_bstat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if (ph == (u_int8_t) -1)
|
|
|
|
return -1;
|
|
|
|
if ((ph & PHASE_MASK) != phase)
|
|
|
|
return 0;
|
|
|
|
if ((ph & mask) != 0)
|
|
|
|
return 1;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(STG_DELAY_INTERVAL);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
printf("%s: stg_expect_signal timeout\n", slp->sl_xname);
|
|
|
|
return -1;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_xfer(sc, buf, len, phase, clear_atn)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct stg_softc *sc;
|
|
|
|
u_int8_t *buf;
|
|
|
|
int len;
|
|
|
|
int phase;
|
2001-07-14 00:38:51 +00:00
|
|
|
int clear_atn;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
int rv, ptr;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (phase & BSTAT_IO)
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
else
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcWinit);
|
|
|
|
|
|
|
|
for (ptr = 0; len > 0; len --)
|
|
|
|
{
|
|
|
|
rv = stg_expect_signal(sc, phase, BSTAT_REQ);
|
|
|
|
if (rv <= 0)
|
|
|
|
goto bad;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if (len == 1 && clear_atn != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
sc->sc_busc &= ~BCTL_ATN;
|
|
|
|
stghw_bcr_write_1(sc, sc->sc_busc);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DEASSERT_ATN(&sc->sc_sclow);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (phase & BSTAT_IO)
|
|
|
|
{
|
|
|
|
buf[ptr ++] = bus_space_read_1(iot, ioh, tmc_rdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_wdata, buf[ptr ++]);
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
stg_negate_signal(sc, BSTAT_ACK, "xfer<ACK>");
|
|
|
|
}
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* disconnect & reselect (HW low)
|
|
|
|
**************************************************************/
|
|
|
|
static int
|
|
|
|
stg_reselected(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
int tout;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int sid;
|
2001-07-14 00:38:51 +00:00
|
|
|
u_int8_t regv;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (slp->sl_selid != NULL)
|
|
|
|
{
|
|
|
|
/* XXX:
|
|
|
|
* Selection vs Reselection conflicts.
|
|
|
|
*/
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
else if (slp->sl_Tnexus != NULL)
|
|
|
|
{
|
|
|
|
printf("%s: unexpected termination\n", slp->sl_xname);
|
|
|
|
stg_disconnected(sc, slp->sl_Tnexus);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/* XXX:
|
|
|
|
* We should ack the reselection as soon as possible,
|
2003-12-17 16:12:01 +00:00
|
|
|
* because the target would abort the current reselection seq
|
2000-10-23 12:55:51 +00:00
|
|
|
* due to reselection timeout.
|
|
|
|
*/
|
2001-07-14 00:38:51 +00:00
|
|
|
tout = STG_DELAY_SELECT_POLLING_MAX;
|
|
|
|
while (tout -- > 0)
|
|
|
|
{
|
|
|
|
regv = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((regv & (BSTAT_IO | BSTAT_SEL | BSTAT_BSY)) ==
|
|
|
|
(BSTAT_IO | BSTAT_SEL))
|
|
|
|
{
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
regv = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((regv & (BSTAT_IO | BSTAT_SEL | BSTAT_BSY)) ==
|
|
|
|
(BSTAT_IO | BSTAT_SEL))
|
|
|
|
goto reselect_start;
|
|
|
|
}
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
}
|
|
|
|
printf("%s: reselction timeout I\n", slp->sl_xname);
|
|
|
|
return EJUSTRETURN;
|
|
|
|
|
|
|
|
reselect_start:
|
2000-10-23 12:55:51 +00:00
|
|
|
sid = (u_int) bus_space_read_1(iot, ioh, tmc_scsiid);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((sid & sc->sc_idbit) == 0)
|
|
|
|
{
|
|
|
|
/* not us */
|
|
|
|
return EJUSTRETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl,
|
|
|
|
sc->sc_fcRinit | FCTL_CLRFIFO | FCTL_CLRINT);
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
stghw_bcr_write_1(sc, sc->sc_busc | BCTL_BSY);
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
while (tout -- > 0)
|
|
|
|
{
|
|
|
|
regv = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((regv & (BSTAT_SEL | BSTAT_BSY)) == BSTAT_BSY)
|
|
|
|
goto reselected;
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
}
|
|
|
|
printf("%s: reselction timeout II\n", slp->sl_xname);
|
|
|
|
return EJUSTRETURN;
|
|
|
|
|
|
|
|
reselected:
|
2000-10-23 12:55:51 +00:00
|
|
|
sid &= ~sc->sc_idbit;
|
|
|
|
sid = ffs(sid) - 1;
|
2001-07-14 00:38:51 +00:00
|
|
|
if (scsi_low_reselected(slp, sid) == NULL)
|
2000-10-23 12:55:51 +00:00
|
|
|
return EJUSTRETURN;
|
|
|
|
|
|
|
|
#ifdef STG_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_statics.reselect ++;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* STG_STATICS */
|
|
|
|
return EJUSTRETURN;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static int
|
2000-10-23 12:55:51 +00:00
|
|
|
stg_disconnected(sc, ti)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
struct targ_info *ti;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
/* clear bus status & fifo */
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_icinit &= ~ICTL_FIFO;
|
2000-10-23 12:55:51 +00:00
|
|
|
sc->sc_busc &= ~BCTL_ATN;
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_dataout_timeout = 0;
|
|
|
|
sc->sc_ubf_timeout = 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
#ifdef STG_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_statics.disconnect ++;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* STG_STATICS */
|
|
|
|
scsi_low_disconnected(slp, ti);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* SEQUENCER
|
|
|
|
**************************************************************/
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_target_nexus_establish(sc)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-07-14 00:38:51 +00:00
|
|
|
struct targ_info *ti = slp->sl_Tnexus;
|
2001-02-25 12:40:30 +00:00
|
|
|
struct stg_targ_info *sti = (void *) ti;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-02-25 12:40:30 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_ssctl, sti->sti_reg_synch);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((stg_io_control & STG_FIFO_INTERRUPTS) != 0)
|
|
|
|
{
|
|
|
|
sc->sc_icinit |= ICTL_FIFO;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_lun_nexus_establish(sc)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct stg_softc *sc;
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stg_ccb_nexus_establish(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
struct slccb *cb = slp->sl_Qnexus;
|
|
|
|
|
|
|
|
sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STGHW_SELECT_INTERVAL 10
|
|
|
|
|
|
|
|
static int
|
|
|
|
stghw_select_targ_wait(sc, mu)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
int mu;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
mu = mu / STGHW_SELECT_INTERVAL;
|
|
|
|
while (mu -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((bus_space_read_1(iot, ioh, tmc_bstat) & BSTAT_BSY) == 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(STGHW_SELECT_INTERVAL);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
if ((bus_space_read_1(iot, ioh, tmc_bstat) & BSTAT_BSY) != 0)
|
|
|
|
{
|
|
|
|
return 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stg_selection_done_and_expect_msgout(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
2001-07-14 00:38:51 +00:00
|
|
|
stghw_bcr_write_1(sc, sc->sc_imsg | sc->sc_busc);
|
|
|
|
SCSI_LOW_ASSERT_ATN(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
stgintr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct stg_softc *sc = arg;
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
struct targ_info *ti;
|
|
|
|
struct physio_proc *pp;
|
|
|
|
struct buf *bp;
|
2001-07-14 00:38:51 +00:00
|
|
|
u_int derror, flags;
|
|
|
|
int len, s;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int8_t status, astatus, regv;
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* interrupt check
|
|
|
|
*******************************************/
|
|
|
|
if (slp->sl_flags & HW_INACTIVE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
astatus = bus_space_read_1(iot, ioh, tmc_astat);
|
|
|
|
status = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((astatus & ASTAT_STATMASK) == 0 || astatus == (u_int8_t) -1)
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
if (astatus & ASTAT_SCSIRST)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl,
|
|
|
|
sc->sc_fcRinit | FCTL_CLRFIFO);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT,
|
|
|
|
"bus reset (power off?)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* debug section
|
|
|
|
*******************************************/
|
|
|
|
#ifdef STG_DEBUG
|
|
|
|
if (stg_debug)
|
|
|
|
{
|
|
|
|
scsi_low_print(slp, NULL);
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: st %x ist %x\n\n", slp->sl_xname,
|
2000-10-23 12:55:51 +00:00
|
|
|
status, astatus);
|
2004-07-10 21:14:20 +00:00
|
|
|
#ifdef KDB
|
2000-10-23 12:55:51 +00:00
|
|
|
if (stg_debug > 1)
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DEBUGGER("stg");
|
2004-07-10 21:14:20 +00:00
|
|
|
#endif /* KDB */
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
#endif /* STG_DEBUG */
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* reselection & nexus
|
|
|
|
*******************************************/
|
|
|
|
if ((status & RESEL_PHASE_MASK)== PHASE_RESELECTED)
|
|
|
|
{
|
|
|
|
if (stg_reselected(sc) == EJUSTRETURN)
|
2001-07-14 00:38:51 +00:00
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ti = slp->sl_Tnexus) == NULL)
|
|
|
|
return 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
derror = 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
if ((astatus & ASTAT_PARERR) != 0 && ti->ti_phase != PH_ARBSTART &&
|
|
|
|
(sc->sc_fcRinit & FCTL_PARENB) != 0)
|
|
|
|
{
|
|
|
|
slp->sl_error |= PARITYERR;
|
2001-07-14 00:38:51 +00:00
|
|
|
derror = SCSI_LOW_DATA_PE;
|
|
|
|
if ((status & PHASE_MASK) == MESSAGE_IN_PHASE)
|
|
|
|
scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_PARITY, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
else
|
|
|
|
scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ERROR, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* aribitration & selection
|
|
|
|
*******************************************/
|
|
|
|
switch (ti->ti_phase)
|
|
|
|
{
|
|
|
|
case PH_ARBSTART:
|
|
|
|
if ((astatus & ASTAT_ARBIT) == 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
#ifdef STG_STATICS
|
|
|
|
stg_statics.arbit_fail_0 ++;
|
|
|
|
#endif /* STG_STATICS */
|
2000-10-23 12:55:51 +00:00
|
|
|
goto arb_fail;
|
2001-07-14 00:38:51 +00:00
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
status = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((status & BSTAT_IO) != 0)
|
|
|
|
{
|
|
|
|
/* XXX:
|
|
|
|
* Selection vs Reselection conflicts.
|
|
|
|
*/
|
|
|
|
#ifdef STG_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_statics.arbit_fail_1 ++;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* STG_STATICS */
|
|
|
|
arb_fail:
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
stghw_bcr_write_1(sc, BCTL_BUSFREE);
|
2001-07-14 00:38:51 +00:00
|
|
|
scsi_low_arbit_fail(slp, slp->sl_Qnexus);
|
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* selection assert start.
|
|
|
|
*/
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART);
|
2001-07-14 00:38:51 +00:00
|
|
|
scsi_low_arbit_win(slp);
|
|
|
|
|
|
|
|
s = splhigh();
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, tmc_scsiid,
|
|
|
|
sc->sc_idbit | (1 << ti->ti_id));
|
|
|
|
stghw_bcr_write_1(sc, sc->sc_imsg | sc->sc_busc | BCTL_SEL);
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcWinit);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((stg_io_control & STG_WAIT_FOR_SELECT) != 0)
|
|
|
|
{
|
|
|
|
/* selection abort delay 200 + 100 micro sec */
|
|
|
|
if (stghw_select_targ_wait(sc, 300) == 0)
|
|
|
|
{
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED);
|
|
|
|
stg_selection_done_and_expect_msgout(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
case PH_SELSTART:
|
|
|
|
if ((status & BSTAT_BSY) == 0)
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
/* selection timeout delay 250 ms */
|
|
|
|
if (stghw_select_targ_wait(sc, 250 * 1000) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_disconnected(sc, ti);
|
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED);
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_selection_done_and_expect_msgout(sc);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case PH_SELECTED:
|
|
|
|
if ((status & BSTAT_REQ) == 0)
|
|
|
|
goto out;
|
|
|
|
stg_target_nexus_establish(sc);
|
|
|
|
break;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
case PH_RESEL:
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((status & BSTAT_REQ) == 0)
|
|
|
|
goto out;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
/* clear a busy line */
|
|
|
|
bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit);
|
|
|
|
stghw_bcr_write_1(sc, sc->sc_busc);
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_target_nexus_establish(sc);
|
2000-10-23 12:55:51 +00:00
|
|
|
if ((status & PHASE_MASK) != MESSAGE_IN_PHASE)
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: unexpected phase after reselect\n",
|
|
|
|
slp->sl_xname);
|
|
|
|
slp->sl_error |= FATALIO;
|
2000-10-23 12:55:51 +00:00
|
|
|
scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1);
|
2001-07-14 00:38:51 +00:00
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************
|
2001-07-14 00:38:51 +00:00
|
|
|
* data phase
|
2000-10-23 12:55:51 +00:00
|
|
|
*******************************************/
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_flags & HW_PDMASTART) && STG_IS_PHASE_DATA(status) == 0)
|
|
|
|
{
|
|
|
|
if (slp->sl_scp.scp_direction == SCSI_LOW_READ)
|
|
|
|
stg_pio_read(sc, ti, 0);
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
stg_pdma_end(sc, ti);
|
2001-07-14 00:38:51 +00:00
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
/*******************************************
|
|
|
|
* scsi seq
|
|
|
|
*******************************************/
|
2000-10-23 12:55:51 +00:00
|
|
|
switch (status & PHASE_MASK)
|
|
|
|
{
|
|
|
|
case COMMAND_PHASE:
|
2001-07-14 00:38:51 +00:00
|
|
|
if (stg_expect_signal(sc, COMMAND_PHASE, BSTAT_REQ) <= 0)
|
|
|
|
break;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_CMD);
|
|
|
|
if (scsi_low_cmd(slp, ti) != 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if (stg_xfer(sc, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen,
|
|
|
|
COMMAND_PHASE, 0) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: CMDOUT short\n", slp->sl_xname);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_OUT_PHASE:
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_DATA);
|
|
|
|
if (scsi_low_data(slp, ti, &bp, SCSI_LOW_WRITE) != 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
pp = physio_proc_enter(bp);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((sc->sc_icinit & ICTL_FIFO) != 0)
|
|
|
|
stg_pio_write(sc, ti, sc->sc_wthold);
|
|
|
|
else
|
|
|
|
stg_pio_write(sc, ti, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
physio_proc_leave(pp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_IN_PHASE:
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_DATA);
|
|
|
|
if (scsi_low_data(slp, ti, &bp, SCSI_LOW_READ) != 0)
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
pp = physio_proc_enter(bp);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((sc->sc_icinit & ICTL_FIFO) != 0)
|
|
|
|
stg_pio_read(sc, ti, sc->sc_rthold);
|
|
|
|
else
|
|
|
|
stg_pio_read(sc, ti, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
physio_proc_leave(pp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_PHASE:
|
2001-07-14 00:38:51 +00:00
|
|
|
regv = stg_expect_signal(sc, STATUS_PHASE, BSTAT_REQ);
|
|
|
|
if (regv <= 0)
|
|
|
|
break;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_STAT);
|
2001-07-14 00:38:51 +00:00
|
|
|
regv = bus_space_read_1(iot, ioh, tmc_sdna);
|
|
|
|
if (scsi_low_statusin(slp, ti, regv | derror) != 0)
|
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
|
|
|
if (regv != bus_space_read_1(iot, ioh, tmc_rdata))
|
|
|
|
{
|
|
|
|
printf("%s: STATIN: data mismatch\n", slp->sl_xname);
|
|
|
|
}
|
|
|
|
stg_negate_signal(sc, BSTAT_ACK, "statin<ACK>");
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESSAGE_OUT_PHASE:
|
2001-07-14 00:38:51 +00:00
|
|
|
if (stg_expect_signal(sc, MESSAGE_OUT_PHASE, BSTAT_REQ) <= 0)
|
|
|
|
break;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT);
|
2001-07-14 00:38:51 +00:00
|
|
|
flags = (ti->ti_ophase != ti->ti_phase) ?
|
|
|
|
SCSI_LOW_MSGOUT_INIT : 0;
|
|
|
|
len = scsi_low_msgout(slp, ti, flags);
|
|
|
|
|
|
|
|
if (len > 1 && slp->sl_atten == 0)
|
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stg_xfer(sc, ti->ti_msgoutstr, len, MESSAGE_OUT_PHASE,
|
|
|
|
slp->sl_clear_atten) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
printf("%s: MSGOUT short\n", slp->sl_xname);
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (slp->sl_msgphase >= MSGPH_ABORT)
|
|
|
|
{
|
|
|
|
stg_disconnected(sc, ti);
|
|
|
|
}
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESSAGE_IN_PHASE:
|
2001-07-14 00:38:51 +00:00
|
|
|
/* confirm phase and req signal */
|
|
|
|
if (stg_expect_signal(sc, MESSAGE_IN_PHASE, BSTAT_REQ) <= 0)
|
|
|
|
break;
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN);
|
|
|
|
|
|
|
|
/* read data with NOACK */
|
2001-07-14 00:38:51 +00:00
|
|
|
regv = bus_space_read_1(iot, ioh, tmc_sdna);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if (scsi_low_msgin(slp, ti, derror | regv) == 0)
|
|
|
|
{
|
|
|
|
if (scsi_low_is_msgout_continue(ti, 0) != 0)
|
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/* read data with ACK */
|
2001-07-14 00:38:51 +00:00
|
|
|
if (regv != bus_space_read_1(iot, ioh, tmc_rdata))
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
printf("%s: MSGIN: data mismatch\n", slp->sl_xname);
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
/* wait for the ack negated */
|
|
|
|
stg_negate_signal(sc, BSTAT_ACK, "msgin<ACK>");
|
|
|
|
|
|
|
|
if (slp->sl_msgphase != 0 && slp->sl_msgphase < MSGPH_ABORT)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
stg_disconnected(sc, ti);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUSFREE_PHASE:
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: unexpected disconnect\n", slp->sl_xname);
|
|
|
|
stg_disconnected(sc, ti);
|
|
|
|
break;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
default:
|
2001-07-14 00:38:51 +00:00
|
|
|
slp->sl_error |= FATALIO;
|
|
|
|
printf("%s: unknown phase bus %x intr %x\n",
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_xname, status, astatus);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
out:
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit);
|
2000-10-23 12:55:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
stg_timeout(sc)
|
|
|
|
struct stg_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int tout, count;
|
|
|
|
u_int8_t status;
|
|
|
|
|
|
|
|
if (slp->sl_Tnexus == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
status = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((status & PHASE_MASK) == 0)
|
|
|
|
{
|
|
|
|
if (sc->sc_ubf_timeout ++ == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
printf("%s: unexpected bus free detected\n", slp->sl_xname);
|
|
|
|
slp->sl_error |= FATALIO;
|
|
|
|
scsi_low_print(slp, slp->sl_Tnexus);
|
|
|
|
stg_disconnected(sc, slp->sl_Tnexus);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (status & PHASE_MASK)
|
|
|
|
{
|
|
|
|
case DATA_OUT_PHASE:
|
|
|
|
if (sc->sc_dataout_timeout == 0)
|
|
|
|
break;
|
|
|
|
if ((status & BSTAT_REQ) == 0)
|
|
|
|
break;
|
|
|
|
if (bus_space_read_2(iot, ioh, tmc_fdcnt) != 0)
|
|
|
|
break;
|
|
|
|
if ((-- sc->sc_dataout_timeout) > 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
if ((slp->sl_flags & HW_WRITE_PADDING) == 0)
|
|
|
|
{
|
|
|
|
printf("%s: write padding required\n",
|
|
|
|
slp->sl_xname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, 0);
|
|
|
|
|
|
|
|
tout = STG_DELAY_MAX;
|
|
|
|
while (tout --)
|
|
|
|
{
|
|
|
|
status = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((status & PHASE_MASK) != DATA_OUT_PHASE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (bus_space_read_2(iot, ioh, tmc_fdcnt) != 0)
|
|
|
|
{
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = sc->sc_maxwsize; count > 0; count --)
|
|
|
|
bus_space_write_1(iot, ioh, tmc_wfifo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
status = bus_space_read_1(iot, ioh, tmc_bstat);
|
|
|
|
if ((status & PHASE_MASK) == DATA_OUT_PHASE)
|
|
|
|
sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ;
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|