2000-10-23 12:55:51 +00:00
|
|
|
/* $FreeBSD$ */
|
2001-07-14 00:38:51 +00:00
|
|
|
/* $NecBSD: ncr53c500.c,v 1.30.12.3 2001/06/26 07:31:41 honda Exp $ */
|
2000-10-23 12:55:51 +00:00
|
|
|
/* $NetBSD$ */
|
|
|
|
|
|
|
|
#define NCV_DEBUG
|
|
|
|
#define NCV_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
#define NCV_IO_CONTROL_FLAGS (0)
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* [NetBSD for NEC PC-98 series]
|
2001-07-14 00:38:51 +00:00
|
|
|
* Copyright (c) 1995, 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) 1995, 1996, 1997, 1998, 1999, 2000, 2001
|
2000-10-23 12:55:51 +00:00
|
|
|
* Naofumi HONDA. 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.
|
|
|
|
*/
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
|
|
|
#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/ncr53c500reg.h>
|
|
|
|
#include <i386/Cbus/dev/ncr53c500hw.h>
|
|
|
|
#include <i386/Cbus/dev/ncr53c500var.h>
|
|
|
|
|
|
|
|
#include <i386/Cbus/dev/ncr53c500hwtab.h>
|
|
|
|
#endif /* __NetBSD__ */
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <machine/dvcfg.h>
|
|
|
|
#include <machine/physio_proc.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_low.h>
|
|
|
|
|
|
|
|
#include <dev/ncv/ncr53c500reg.h>
|
|
|
|
#include <dev/ncv/ncr53c500hw.h>
|
|
|
|
#include <dev/ncv/ncr53c500var.h>
|
|
|
|
|
|
|
|
#include <dev/ncv/ncr53c500hwtab.h>
|
|
|
|
#endif /* __FreeBSD__ */
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
#define NCV_MAX_DATA_SIZE (64 * 1024)
|
|
|
|
#define NCV_DELAY_MAX (2 * 1000 * 1000)
|
|
|
|
#define NCV_DELAY_INTERVAL (1)
|
|
|
|
#define NCV_PADDING_SIZE (32)
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
/***************************************************
|
2001-07-14 00:38:51 +00:00
|
|
|
* IO control
|
2000-10-23 12:55:51 +00:00
|
|
|
***************************************************/
|
2001-07-14 00:38:51 +00:00
|
|
|
#define NCV_READ_INTERRUPTS_DRIVEN 0x0001
|
|
|
|
#define NCV_WRITE_INTERRUPTS_DRIVEN 0x0002
|
|
|
|
#define NCV_ENABLE_FAST_SCSI 0x0010
|
|
|
|
#define NCV_FAST_INTERRUPTS 0x0100
|
|
|
|
|
|
|
|
u_int ncv_io_control = NCV_IO_CONTROL_FLAGS;
|
|
|
|
int ncv_data_read_bytes = 4096;
|
|
|
|
int ncv_data_write_bytes = 4096;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
/***************************************************
|
|
|
|
* DEBUG
|
|
|
|
***************************************************/
|
2000-10-23 12:55:51 +00:00
|
|
|
#ifdef NCV_DEBUG
|
2002-01-08 19:37:12 +00:00
|
|
|
static int ncv_debug;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* NCV_DEBUG */
|
|
|
|
|
|
|
|
#ifdef NCV_STATICS
|
2002-01-08 19:37:12 +00:00
|
|
|
static struct ncv_statics {
|
2000-10-23 12:55:51 +00:00
|
|
|
int disconnect;
|
|
|
|
int reselect;
|
2001-07-14 00:38:51 +00:00
|
|
|
} ncv_statics;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* NCV_STATICS */
|
|
|
|
|
|
|
|
/***************************************************
|
2001-07-14 00:38:51 +00:00
|
|
|
* DEVICE STRUCTURE
|
2000-10-23 12:55:51 +00:00
|
|
|
***************************************************/
|
|
|
|
extern struct cfdriver ncv_cd;
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* DECLARE
|
|
|
|
**************************************************************/
|
|
|
|
/* static */
|
2002-03-20 02:08:01 +00:00
|
|
|
static void ncv_pio_read(struct ncv_softc *, u_int8_t *, u_int);
|
|
|
|
static void ncv_pio_write(struct ncv_softc *, u_int8_t *, u_int);
|
|
|
|
static int ncv_msg(struct ncv_softc *, struct targ_info *, u_int);
|
|
|
|
static int ncv_reselected(struct ncv_softc *);
|
|
|
|
static int ncv_disconnected(struct ncv_softc *, struct targ_info *);
|
|
|
|
|
|
|
|
static __inline void ncvhw_set_count(bus_space_tag_t, bus_space_handle_t, int);
|
|
|
|
static __inline u_int ncvhw_get_count(bus_space_tag_t, bus_space_handle_t);
|
|
|
|
static __inline void ncvhw_select_register_0(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *);
|
|
|
|
static __inline void ncvhw_select_register_1(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *);
|
|
|
|
static __inline void ncvhw_fpush(bus_space_tag_t, bus_space_handle_t, u_int8_t *, int);
|
|
|
|
|
|
|
|
static void ncv_pdma_end(struct ncv_softc *sc, struct targ_info *);
|
|
|
|
static int ncv_world_start(struct ncv_softc *, int);
|
|
|
|
static void ncvhw_bus_reset(struct ncv_softc *);
|
|
|
|
static void ncvhw_reset(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *);
|
|
|
|
static int ncvhw_check(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *);
|
|
|
|
static void ncvhw_init(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *);
|
|
|
|
static int ncvhw_start_selection(struct ncv_softc *sc, struct slccb *);
|
|
|
|
static void ncvhw_attention(struct ncv_softc *);
|
|
|
|
static int ncv_ccb_nexus_establish(struct ncv_softc *);
|
|
|
|
static int ncv_lun_nexus_establish(struct ncv_softc *);
|
|
|
|
static int ncv_target_nexus_establish(struct ncv_softc *);
|
|
|
|
static int ncv_targ_init(struct ncv_softc *, struct targ_info *, int);
|
|
|
|
static int ncv_catch_intr(struct ncv_softc *);
|
2000-10-23 12:55:51 +00:00
|
|
|
#ifdef NCV_POWER_CONTROL
|
2002-03-20 02:08:01 +00:00
|
|
|
static int ncvhw_power(struct ncv_softc *, u_int);
|
2001-07-14 00:38:51 +00:00
|
|
|
#endif /* NCV_POWER_CONTROL */
|
2002-03-20 02:08:01 +00:00
|
|
|
static __inline void ncv_setup_and_start_pio(struct ncv_softc *, u_int);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
struct scsi_low_funcs ncv_funcs = {
|
|
|
|
SC_LOW_INIT_T ncv_world_start,
|
|
|
|
SC_LOW_BUSRST_T ncvhw_bus_reset,
|
2001-02-25 12:40:30 +00:00
|
|
|
SC_LOW_TARG_INIT_T ncv_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 ncvhw_start_selection,
|
2001-07-14 00:38:51 +00:00
|
|
|
SC_LOW_NEXUS_T ncv_lun_nexus_establish,
|
|
|
|
SC_LOW_NEXUS_T ncv_ccb_nexus_establish,
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
SC_LOW_ATTEN_T ncvhw_attention,
|
|
|
|
SC_LOW_MSG_T ncv_msg,
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
SC_LOW_TIMEOUT_T NULL,
|
2000-10-23 12:55:51 +00:00
|
|
|
SC_LOW_POLL_T ncvintr,
|
|
|
|
|
|
|
|
NULL, /* SC_LOW_POWER_T ncvhw_power, */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* hwfuncs
|
|
|
|
**************************************************************/
|
|
|
|
static __inline void
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct ncv_hw *hw;
|
|
|
|
{
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg4, hw->hw_cfg4);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
ncvhw_select_register_1(iot, ioh, hw)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct ncv_hw *hw;
|
|
|
|
{
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr1_cfg5, hw->hw_cfg5);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
ncvhw_fpush(iot, ioh, buf, len)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
u_int8_t *buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
int ptr;
|
|
|
|
|
|
|
|
for (ptr = 0; ptr < len; ptr ++)
|
|
|
|
bus_space_write_1(iot, ioh, cr0_sfifo, buf[ptr]);
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static __inline void
|
|
|
|
ncvhw_set_count(iot, ioh, count)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int count;
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_tclsb, (u_int8_t) count);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_tcmsb, (u_int8_t) (count >> NBBY));
|
|
|
|
bus_space_write_1(iot, ioh, cr0_tchsb, (u_int8_t) (count >> (NBBY * 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline u_int
|
|
|
|
ncvhw_get_count(iot, ioh)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
{
|
|
|
|
u_int count;
|
|
|
|
|
|
|
|
count = (u_int) bus_space_read_1(iot, ioh, cr0_tclsb);
|
|
|
|
count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tcmsb)) << NBBY;
|
|
|
|
count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tchsb)) << (NBBY * 2);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
static int
|
|
|
|
ncvhw_check(iot, ioh, hw)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct ncv_hw *hw;
|
|
|
|
{
|
|
|
|
u_int8_t stat;
|
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA);
|
|
|
|
if (bus_space_read_1(iot, ioh, cr0_cmd) != (CMD_NOP | CMD_DMA))
|
|
|
|
{
|
|
|
|
#ifdef NCV_DEBUG
|
|
|
|
printf("ncv: cr0_cmd CMD_NOP|CMD_DMA failed\n");
|
|
|
|
#endif /* NCV_DEBUG */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP);
|
|
|
|
if (bus_space_read_1(iot, ioh, cr0_cmd) != CMD_NOP)
|
|
|
|
{
|
|
|
|
#ifdef NCV_DEBUG
|
|
|
|
printf("ncv: cr0_cmd CMD_NOP failed\n");
|
|
|
|
#endif /* NCV_DEBUG */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hardware reset */
|
|
|
|
ncvhw_reset(iot, ioh, hw);
|
|
|
|
ncvhw_init(iot, ioh, hw);
|
|
|
|
|
|
|
|
/* bus reset */
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(100 * 1000);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/* check response */
|
|
|
|
bus_space_read_1(iot, ioh, cr0_stat);
|
|
|
|
stat = bus_space_read_1(iot, ioh, cr0_istat);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(1000);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (((stat & INTR_SBR) == 0) ||
|
|
|
|
(bus_space_read_1(iot, ioh, cr0_istat) & INTR_SBR))
|
|
|
|
{
|
|
|
|
#ifdef NCV_DEBUG
|
|
|
|
printf("ncv: cr0_istat SCSI BUS RESET failed\n");
|
|
|
|
#endif /* NCV_DEBUG */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncvhw_reset(iot, ioh, hw)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct ncv_hw *hw;
|
|
|
|
{
|
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw);
|
|
|
|
|
|
|
|
/* dummy cmd twice */
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP);
|
|
|
|
|
|
|
|
/* chip reset */
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTCHIP);
|
|
|
|
|
|
|
|
/* again dummy cmd twice */
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncvhw_init(iot, ioh, hw)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct ncv_hw *hw;
|
|
|
|
{
|
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw);
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_clk, hw->hw_clk);
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_srtout, SEL_TOUT);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_period, 0);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_offs, 0);
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg1, hw->hw_cfg1);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg2, hw->hw_cfg2);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg3, hw->hw_cfg3);
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_tchsb, 0);
|
|
|
|
|
|
|
|
ncvhw_select_register_1(iot, ioh, hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_fstat, 0x0);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_pflag, 0x0);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE);
|
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NCV_POWER_CONTROL
|
|
|
|
static int
|
|
|
|
ncvhw_power(sc, flags)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
u_int flags;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
if (flags == SCSI_LOW_POWDOWN)
|
|
|
|
{
|
|
|
|
printf("%s power down\n", slp->sl_xname);
|
|
|
|
ncvhw_select_register_1(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_POWDOWN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (sc->sc_rstep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
printf("%s resume step O\n", slp->sl_xname);
|
|
|
|
ncvhw_select_register_1(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
printf("%s resume step I\n", slp->sl_xname);
|
|
|
|
ncvhw_reset(iot, ioh, &sc->sc_hw);
|
|
|
|
ncvhw_init(iot, ioh, &sc->sc_hw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* NCV_POWER_CONTROL */
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* scsi low interface
|
|
|
|
**************************************************************/
|
|
|
|
static void
|
|
|
|
ncvhw_attention(sc)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, CMD_SETATN);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(10);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncvhw_bus_reset(sc)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncvhw_start_selection(sc, cb)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
struct slccb *cb;
|
|
|
|
{
|
|
|
|
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 = cb->ti;
|
2001-07-14 00:38:51 +00:00
|
|
|
int s, len;
|
|
|
|
u_int flags;
|
|
|
|
u_int8_t cmd;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000;
|
2000-10-23 12:55:51 +00:00
|
|
|
sc->sc_compseq = 0;
|
2001-07-14 00:38:51 +00:00
|
|
|
if (scsi_low_is_msgout_continue(ti, SCSI_LOW_MSG_IDENTIFY) == 0)
|
|
|
|
{
|
|
|
|
cmd = CMD_SELATN;
|
|
|
|
sc->sc_selstop = 0;
|
|
|
|
flags = SCSI_LOW_MSGOUT_UNIFY | SCSI_LOW_MSGOUT_INIT;
|
|
|
|
}
|
|
|
|
else if (scsi_low_is_msgout_continue(ti,
|
|
|
|
SCSI_LOW_MSG_IDENTIFY | SCSI_LOW_MSG_SIMPLE_QTAG) == 0)
|
|
|
|
{
|
|
|
|
cmd = CMD_SELATN3;
|
|
|
|
sc->sc_selstop = 0;
|
|
|
|
flags = SCSI_LOW_MSGOUT_UNIFY | SCSI_LOW_MSGOUT_INIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmd = CMD_SELATNS;
|
|
|
|
sc->sc_selstop = 1;
|
|
|
|
flags = SCSI_LOW_MSGOUT_INIT;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0)
|
|
|
|
return SCSI_LOW_START_FAIL;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_target_nexus_establish(sc);
|
|
|
|
|
|
|
|
len = scsi_low_msgout(slp, ti, flags);
|
|
|
|
if (sc->sc_selstop == 0)
|
|
|
|
scsi_low_cmd(slp, ti);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
s = splhigh();
|
|
|
|
if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
splx(s);
|
|
|
|
return SCSI_LOW_START_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_dstid, ti->ti_id);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
2001-07-14 00:38:51 +00:00
|
|
|
ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len);
|
|
|
|
if (sc->sc_selstop == 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
ncvhw_fpush(iot, ioh,
|
|
|
|
slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen);
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, cmd);
|
2000-10-23 12:55:51 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART);
|
|
|
|
return SCSI_LOW_START_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncv_world_start(sc, fdone)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
int fdone;
|
|
|
|
{
|
|
|
|
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_int8_t stat;
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
if ((slp->sl_cfgflags & CFG_NOPARITY) == 0)
|
|
|
|
sc->sc_hw.hw_cfg1 |= C1_PARENB;
|
|
|
|
else
|
|
|
|
sc->sc_hw.hw_cfg1 &= ~C1_PARENB;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
ncvhw_reset(iot, ioh, &sc->sc_hw);
|
|
|
|
ncvhw_init(iot, ioh, &sc->sc_hw);
|
|
|
|
|
2001-01-23 22:05:07 +00:00
|
|
|
scsi_low_bus_reset(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_stat);
|
|
|
|
stat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(1000);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (((stat & INTR_SBR) == 0) ||
|
|
|
|
(bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat) & INTR_SBR))
|
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
SOFT_INTR_REQUIRED(slp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncv_msg(sc, ti, msg)
|
|
|
|
struct ncv_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 ncv_targ_info *nti = (void *) ti;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int hwcycle, period;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
if ((msg & SCSI_LOW_MSG_SYNCH) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2001-02-25 12:40:30 +00:00
|
|
|
period = ti->ti_maxsynch.period;
|
2001-07-14 00:38:51 +00:00
|
|
|
hwcycle = (sc->sc_hw.hw_clk == 0) ? 40 : (5 * sc->sc_hw.hw_clk);
|
|
|
|
hwcycle = 1000 / hwcycle;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (period < 200 / 4 && period >= 100 / 4)
|
2001-07-14 00:38:51 +00:00
|
|
|
nti->nti_reg_cfg3 |= sc->sc_hw.hw_cfg3_fscsi;
|
2000-10-23 12:55:51 +00:00
|
|
|
else
|
2001-07-14 00:38:51 +00:00
|
|
|
nti->nti_reg_cfg3 &= ~sc->sc_hw.hw_cfg3_fscsi;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
period = ((period * 40 / hwcycle) + 5) / 10;
|
2001-02-25 12:40:30 +00:00
|
|
|
nti->nti_reg_period = period & 0x1f;
|
|
|
|
nti->nti_reg_offset = ti->ti_maxsynch.offset;
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_period, nti->nti_reg_period);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_offs, nti->nti_reg_offset);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg3, nti->nti_reg_cfg3);
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_targ_init(sc, ti, action)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct ncv_softc *sc;
|
|
|
|
struct targ_info *ti;
|
2001-07-14 00:38:51 +00:00
|
|
|
int action;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-02-25 12:40:30 +00:00
|
|
|
struct ncv_targ_info *nti = (void *) ti;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE)
|
|
|
|
{
|
|
|
|
ti->ti_width = SCSI_LOW_BUS_WIDTH_8;
|
|
|
|
ti->ti_maxsynch.period = sc->sc_hw.hw_mperiod;
|
|
|
|
ti->ti_maxsynch.offset = sc->sc_hw.hw_moffset;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
nti->nti_reg_cfg3 = sc->sc_hw.hw_cfg3;
|
|
|
|
nti->nti_reg_period = 0;
|
|
|
|
nti->nti_reg_offset = 0;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* General probe attach
|
|
|
|
**************************************************************/
|
2002-03-20 02:08:01 +00:00
|
|
|
static int ncv_setup_img(struct ncv_hw *, u_int, int);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_setup_img(hw, dvcfg, hostid)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct ncv_hw *hw;
|
|
|
|
u_int dvcfg;
|
2001-07-14 00:38:51 +00:00
|
|
|
int hostid;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (NCV_CLKFACTOR(dvcfg) > CLK_35M_F)
|
|
|
|
{
|
|
|
|
printf("ncv: invalid dvcfg flags\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NCV_C5IMG(dvcfg) != 0)
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
hw->hw_cfg5 = NCV_C5IMG(dvcfg);
|
|
|
|
hw->hw_clk = NCV_CLKFACTOR(dvcfg);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ncv_io_control & NCV_ENABLE_FAST_SCSI) != 0 &&
|
|
|
|
(NCV_SPECIAL(dvcfg) & NCVHWCFG_MAX10M) != 0)
|
|
|
|
hw->hw_mperiod = 100 / 4;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (NCV_SPECIAL(dvcfg) & NCVHWCFG_FIFOBUG)
|
2001-07-14 00:38:51 +00:00
|
|
|
hw->hw_cfg3_fclk = 0x04;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (NCV_SPECIAL(dvcfg) & NCVHWCFG_SCSI1)
|
2001-07-14 00:38:51 +00:00
|
|
|
hw->hw_cfg2 &= ~C2_SCSI2;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
if (NCV_SPECIAL(dvcfg) & NCVHWCFG_SLOW)
|
2001-07-14 00:38:51 +00:00
|
|
|
hw->hw_cfg1 |= C1_SLOW;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* setup configuration image 3 */
|
2001-07-14 00:38:51 +00:00
|
|
|
if (hw->hw_clk != CLK_40M_F && hw->hw_clk <= CLK_25M_F)
|
|
|
|
hw->hw_cfg3 &= ~hw->hw_cfg3_fclk;
|
|
|
|
else
|
|
|
|
hw->hw_cfg3 |= hw->hw_cfg3_fclk;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
/* setup configuration image 1 */
|
2001-07-14 00:38:51 +00:00
|
|
|
hw->hw_cfg1 = (hw->hw_cfg1 & 0xf0) | hostid;
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncvprobesubr(iot, ioh, dvcfg, hsid)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
u_int dvcfg;
|
|
|
|
int hsid;
|
|
|
|
{
|
|
|
|
struct ncv_hw hwtab;
|
|
|
|
|
|
|
|
hwtab = ncv_template;
|
|
|
|
if (ncv_setup_img(&hwtab, dvcfg, hsid))
|
|
|
|
return 0;
|
|
|
|
if (ncvhw_check(iot, ioh, &hwtab) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncvprint(aux, name)
|
|
|
|
void *aux;
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
printf("%s: scsibus ", name);
|
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncvattachsubr(sc)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
sc->sc_hw = ncv_template;
|
|
|
|
ncv_setup_img(&sc->sc_hw, slp->sl_cfgflags, slp->sl_hostid);
|
|
|
|
slp->sl_funcs = &ncv_funcs;
|
2001-07-14 00:38:51 +00:00
|
|
|
slp->sl_flags |= HW_READ_PADDING;
|
|
|
|
sc->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */
|
|
|
|
|
|
|
|
(void) scsi_low_attach(slp, 0, NCV_NTARGETS, NCV_NLUNS,
|
|
|
|
sizeof(struct ncv_targ_info), 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* PDMA
|
|
|
|
**************************************************************/
|
|
|
|
static __inline void
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_setup_and_start_pio(sc, reqlen)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
u_int reqlen;
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
ncvhw_set_count(iot, ioh, reqlen);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS | CMD_DMA);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
ncvhw_select_register_1(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_fstat, FIFO_EN);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static void
|
2000-10-23 12:55:51 +00:00
|
|
|
ncv_pdma_end(sc, ti)
|
|
|
|
struct ncv_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;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
slp->sl_flags &= ~HW_PDMASTART;
|
2001-07-14 00:38:51 +00:00
|
|
|
if (slp->sl_Qnexus == NULL)
|
|
|
|
{
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
if (ti->ti_phase == PH_DATA)
|
|
|
|
{
|
|
|
|
len = ncvhw_get_count(sc->sc_iot, sc->sc_ioh);
|
|
|
|
if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE)
|
|
|
|
len += (bus_space_read_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
cr0_sffl) & CR0_SFFLR_BMASK);
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((u_int) len <= (u_int) sc->sc_sdatalen)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
if ((slp->sl_scp.scp_direction == SCSI_LOW_READ) &&
|
|
|
|
sc->sc_tdatalen != len)
|
|
|
|
goto bad;
|
2001-07-14 00:38:51 +00:00
|
|
|
|
|
|
|
len = sc->sc_sdatalen - len;
|
|
|
|
if ((u_int) len > (u_int) slp->sl_scp.scp_datalen)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
slp->sl_scp.scp_data += len;
|
|
|
|
slp->sl_scp.scp_datalen -= len;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bad:
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_error & PDMAERR) == 0)
|
|
|
|
{
|
|
|
|
printf("%s: stragne cnt hw 0x%x soft 0x%x\n",
|
|
|
|
slp->sl_xname, len,
|
|
|
|
slp->sl_scp.scp_datalen);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
scsi_low_data_finish(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
printf("%s: data phase miss\n", slp->sl_xname);
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
out:
|
2000-10-23 12:55:51 +00:00
|
|
|
ncvhw_select_register_1(iot, ioh, &sc->sc_hw);
|
|
|
|
bus_space_write_1(iot, ioh, cr1_fstat, 0);
|
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncv_pio_read(sc, buf, reqlen)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
u_int8_t *buf;
|
|
|
|
u_int reqlen;
|
|
|
|
{
|
|
|
|
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
|
|
|
register u_int8_t fstat;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_setup_and_start_pio(sc, reqlen);
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_flags |= HW_PDMASTART;
|
2001-07-14 00:38:51 +00:00
|
|
|
sc->sc_sdatalen = reqlen;
|
|
|
|
tout = sc->sc_tmaxcnt;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
while (reqlen >= FIFO_F_SZ && tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
fstat = bus_space_read_1(iot, ioh, cr1_fstat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if (fstat == (u_int8_t) -1)
|
|
|
|
goto out;
|
2000-10-23 12:55:51 +00:00
|
|
|
if (fstat & FIFO_F)
|
|
|
|
{
|
|
|
|
#define NCV_FAST32_ACCESS
|
|
|
|
#ifdef NCV_FAST32_ACCESS
|
|
|
|
bus_space_read_multi_4(iot, ioh, cr1_fdata,
|
|
|
|
(u_int32_t *) buf, FIFO_F_SZ / 4);
|
|
|
|
#else /* !NCV_FAST32_ACCESS */
|
|
|
|
bus_space_read_multi_2(iot, ioh, cr1_fdata,
|
|
|
|
(u_int16_t *) buf, FIFO_F_SZ / 2);
|
|
|
|
#endif /* !NCV_FAST32_ACCESS */
|
|
|
|
buf += FIFO_F_SZ;
|
|
|
|
reqlen -= FIFO_F_SZ;
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
else
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
if (fstat & FIFO_BRK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
SCSI_LOW_DELAY(1);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
while (reqlen > 0 && tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
fstat = bus_space_read_1(iot, ioh, cr1_fstat);
|
|
|
|
if ((fstat & FIFO_E) == 0)
|
|
|
|
{
|
|
|
|
*buf++ = bus_space_read_1(iot, ioh, cr1_fdata);
|
|
|
|
reqlen --;
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fstat & FIFO_BRK)
|
|
|
|
break;
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
out:
|
2000-10-23 12:55:51 +00:00
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
sc->sc_tdatalen = reqlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ncv_pio_write(sc, buf, reqlen)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
u_int8_t *buf;
|
|
|
|
u_int reqlen;
|
|
|
|
{
|
|
|
|
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
|
|
|
register u_int8_t fstat;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_setup_and_start_pio(sc, reqlen);
|
|
|
|
sc->sc_sdatalen = reqlen;
|
|
|
|
tout = sc->sc_tmaxcnt;
|
2000-10-23 12:55:51 +00:00
|
|
|
slp->sl_flags |= HW_PDMASTART;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
while (reqlen >= FIFO_F_SZ && tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
fstat = bus_space_read_1(iot, ioh, cr1_fstat);
|
|
|
|
if (fstat & FIFO_BRK)
|
|
|
|
goto done;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((fstat & FIFO_E) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
#ifdef NCV_FAST32_ACCESS
|
|
|
|
bus_space_write_multi_4(iot, ioh, cr1_fdata,
|
|
|
|
(u_int32_t *) buf, FIFO_F_SZ / 4);
|
|
|
|
#else /* !NCV_FAST32_ACCESS */
|
|
|
|
bus_space_write_multi_2(iot, ioh, cr1_fdata,
|
|
|
|
(u_int16_t *) buf, FIFO_F_SZ / 2);
|
|
|
|
#endif /* !NCV_FAST32_ACCESS */
|
|
|
|
buf += FIFO_F_SZ;
|
|
|
|
reqlen -= FIFO_F_SZ;
|
|
|
|
}
|
2001-02-25 12:40:30 +00:00
|
|
|
else
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
while (reqlen > 0 && tout -- > 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
fstat = bus_space_read_1(iot, ioh, cr1_fstat);
|
|
|
|
if (fstat & FIFO_BRK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((fstat & FIFO_F) == 0) /* fifo not full */
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, cr1_fdata, *buf++);
|
|
|
|
reqlen --;
|
|
|
|
}
|
2001-02-25 12:40:30 +00:00
|
|
|
else
|
2001-07-14 00:38:51 +00:00
|
|
|
{
|
|
|
|
SCSI_LOW_DELAY(1);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* disconnect & reselect (HW low)
|
|
|
|
**************************************************************/
|
2001-07-14 00:38:51 +00:00
|
|
|
static int
|
2000-10-23 12:55:51 +00:00
|
|
|
ncv_reselected(sc)
|
|
|
|
struct ncv_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;
|
|
|
|
struct targ_info *ti;
|
|
|
|
u_int sid;
|
|
|
|
|
|
|
|
if ((bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK) != 2)
|
|
|
|
{
|
|
|
|
printf("%s illegal fifo bytes\n", slp->sl_xname);
|
|
|
|
scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "chip confused");
|
|
|
|
return EJUSTRETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
sid = (u_int) bus_space_read_1(iot, ioh, cr0_sfifo);
|
2001-07-14 00:38:51 +00:00
|
|
|
sid &= ~(1 << slp->sl_hostid);
|
2000-10-23 12:55:51 +00:00
|
|
|
sid = ffs(sid) - 1;
|
|
|
|
ti = scsi_low_reselected((struct scsi_low_softc *) sc, sid);
|
|
|
|
if (ti == NULL)
|
|
|
|
return EJUSTRETURN;
|
|
|
|
|
|
|
|
#ifdef NCV_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_statics.reselect ++;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* NCV_STATICS */
|
|
|
|
bus_space_write_1(iot, ioh, cr0_dstid, sid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static int
|
2000-10-23 12:55:51 +00:00
|
|
|
ncv_disconnected(sc, ti)
|
|
|
|
struct ncv_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;
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_ENSEL);
|
|
|
|
|
|
|
|
#ifdef NCV_STATICS
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_statics.disconnect ++;
|
2000-10-23 12:55:51 +00:00
|
|
|
#endif /* NCV_STATICS */
|
|
|
|
|
|
|
|
scsi_low_disconnected(slp, ti);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
* SEQUENCER
|
|
|
|
**************************************************************/
|
|
|
|
static int
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_target_nexus_establish(sc)
|
2000-10-23 12:55:51 +00:00
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
struct scsi_low_softc *slp = &sc->sc_sclow;
|
|
|
|
struct targ_info *ti = slp->sl_Tnexus;
|
|
|
|
struct ncv_targ_info *nti = (void *) ti;
|
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-02-25 12:40:30 +00:00
|
|
|
bus_space_write_1(iot, ioh, cr0_period, nti->nti_reg_period);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_offs, nti->nti_reg_offset);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg3, nti->nti_reg_cfg3);
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
static int
|
|
|
|
ncv_lun_nexus_establish(sc)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncv_ccb_nexus_establish(sc)
|
|
|
|
struct ncv_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncv_catch_intr(sc)
|
|
|
|
struct ncv_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int wc;
|
|
|
|
register u_int8_t status;
|
|
|
|
|
|
|
|
for (wc = 0; wc < NCV_DELAY_MAX / NCV_DELAY_INTERVAL; wc ++)
|
|
|
|
{
|
|
|
|
status = bus_space_read_1(iot, ioh, cr0_stat);
|
|
|
|
if ((status & STAT_INT) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCSI_LOW_DELAY(NCV_DELAY_INTERVAL);
|
|
|
|
}
|
|
|
|
return EJUSTRETURN;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
int
|
|
|
|
ncvintr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ncv_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;
|
2000-10-23 12:55:51 +00:00
|
|
|
u_int8_t regv, status, ireason;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
again:
|
2000-10-23 12:55:51 +00:00
|
|
|
if (slp->sl_flags & HW_INACTIVE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Status
|
|
|
|
********************************************/
|
|
|
|
ncvhw_select_register_0(iot, ioh, &sc->sc_hw);
|
|
|
|
status = bus_space_read_1(iot, ioh, cr0_stat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((status & STAT_INT) == 0 || status == (u_int8_t) -1)
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
ireason = bus_space_read_1(iot, ioh, cr0_istat);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ireason & INTR_SBR) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
u_int8_t val;
|
|
|
|
|
|
|
|
/* avoid power off hangup */
|
|
|
|
val = bus_space_read_1(iot, ioh, cr0_cfg1);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cfg1, val | C1_SRR);
|
|
|
|
|
|
|
|
/* status init */
|
|
|
|
scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT,
|
|
|
|
"bus reset (power off?)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Debug section
|
|
|
|
********************************************/
|
|
|
|
#ifdef NCV_DEBUG
|
|
|
|
if (ncv_debug)
|
|
|
|
{
|
|
|
|
scsi_low_print(slp, NULL);
|
|
|
|
printf("%s st %x ist %x\n\n", slp->sl_xname,
|
|
|
|
status, ireason);
|
2001-07-14 00:38:51 +00:00
|
|
|
#ifdef DDB
|
2000-10-23 12:55:51 +00:00
|
|
|
if (ncv_debug > 1)
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DEBUGGER("ncv");
|
|
|
|
#endif /* DDB */
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
#endif /* NCV_DEBUG */
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Reselect or Disconnect or Nexus check
|
|
|
|
********************************************/
|
|
|
|
/* (I) reselect */
|
|
|
|
if (ireason == INTR_RESELECT)
|
|
|
|
{
|
|
|
|
if (ncv_reselected(sc) == EJUSTRETURN)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (II) nexus */
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ti = slp->sl_Tnexus) == NULL)
|
2000-10-23 12:55:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
derror = 0;
|
2000-10-23 12:55:51 +00:00
|
|
|
if ((status & (STAT_PE | STAT_GE)) != 0)
|
|
|
|
{
|
|
|
|
slp->sl_error |= PARITYERR;
|
2001-07-14 00:38:51 +00:00
|
|
|
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);
|
2001-07-14 00:38:51 +00:00
|
|
|
derror = SCSI_LOW_DATA_PE;
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ireason & (INTR_DIS | INTR_ILL)) != 0)
|
|
|
|
{
|
|
|
|
if ((ireason & INTR_ILL) == 0)
|
|
|
|
return ncv_disconnected(sc, ti);
|
|
|
|
|
|
|
|
slp->sl_error |= FATALIO;
|
|
|
|
scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "illegal cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Internal scsi phase
|
|
|
|
********************************************/
|
|
|
|
switch (ti->ti_phase)
|
|
|
|
{
|
|
|
|
case PH_SELSTART:
|
2001-07-14 00:38:51 +00:00
|
|
|
scsi_low_arbit_win(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED);
|
|
|
|
|
|
|
|
if (sc->sc_selstop == 0)
|
|
|
|
{
|
|
|
|
/* XXX:
|
|
|
|
* Here scsi phases expected are
|
|
|
|
* DATA PHASE:
|
|
|
|
* MSGIN : target wants to disconnect the host.
|
|
|
|
* STATUSIN : immediate command completed.
|
2001-07-14 00:38:51 +00:00
|
|
|
* CMD PHASE : command out failed
|
2000-10-23 12:55:51 +00:00
|
|
|
* MSGOUT : identify command failed.
|
|
|
|
*/
|
|
|
|
if ((status & PHASE_MASK) != MESSAGE_OUT_PHASE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((status & PHASE_MASK) != MESSAGE_OUT_PHASE)
|
2001-07-14 00:38:51 +00:00
|
|
|
break;
|
|
|
|
if ((ireason & INTR_FC) != 0)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_ASSERT_ATN(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT);
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PH_RESEL:
|
2001-07-14 00:38:51 +00:00
|
|
|
ncv_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);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((slp->sl_flags & HW_PDMASTART) != 0)
|
|
|
|
{
|
2000-10-23 12:55:51 +00:00
|
|
|
ncv_pdma_end(sc, ti);
|
2001-07-14 00:38:51 +00:00
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Scsi phase sequencer
|
|
|
|
********************************************/
|
|
|
|
switch (status & PHASE_MASK)
|
|
|
|
{
|
|
|
|
case DATA_OUT_PHASE: /* data out */
|
|
|
|
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 (slp->sl_scp.scp_datalen <= 0)
|
|
|
|
{
|
|
|
|
if ((ireason & INTR_BS) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((slp->sl_error & PDMAERR) == 0)
|
|
|
|
printf("%s: data underrun\n", slp->sl_xname);
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
|
|
|
|
if ((slp->sl_flags & HW_WRITE_PADDING) != 0)
|
|
|
|
{
|
|
|
|
u_int8_t padding[NCV_PADDING_SIZE];
|
|
|
|
|
|
|
|
SCSI_LOW_BZERO(padding, sizeof(padding));
|
|
|
|
ncv_pio_write(sc, padding, sizeof(padding));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s: write padding required\n",
|
|
|
|
slp->sl_xname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = slp->sl_scp.scp_datalen;
|
|
|
|
if ((ncv_io_control & NCV_WRITE_INTERRUPTS_DRIVEN) != 0)
|
|
|
|
{
|
|
|
|
if (len > ncv_data_write_bytes)
|
|
|
|
len = ncv_data_write_bytes;
|
|
|
|
}
|
|
|
|
ncv_pio_write(sc, slp->sl_scp.scp_data, len);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
physio_proc_leave(pp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_IN_PHASE: /* data in */
|
|
|
|
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 (slp->sl_scp.scp_datalen <= 0)
|
|
|
|
{
|
|
|
|
if ((ireason & INTR_BS) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((slp->sl_error & PDMAERR) == 0)
|
|
|
|
printf("%s: data overrun\n", slp->sl_xname);
|
|
|
|
slp->sl_error |= PDMAERR;
|
|
|
|
|
|
|
|
if ((slp->sl_flags & HW_READ_PADDING) != 0)
|
|
|
|
{
|
|
|
|
u_int8_t padding[NCV_PADDING_SIZE];
|
|
|
|
|
|
|
|
ncv_pio_read(sc, padding, sizeof(padding));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s: read padding required\n",
|
|
|
|
slp->sl_xname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = slp->sl_scp.scp_datalen;
|
|
|
|
if ((ncv_io_control & NCV_READ_INTERRUPTS_DRIVEN) != 0)
|
|
|
|
{
|
|
|
|
if (len > ncv_data_read_bytes)
|
|
|
|
len = ncv_data_read_bytes;
|
|
|
|
}
|
|
|
|
ncv_pio_read(sc, slp->sl_scp.scp_data, len);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
physio_proc_leave(pp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMAND_PHASE: /* cmd out */
|
|
|
|
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
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
ncvhw_fpush(iot, ioh,
|
|
|
|
slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_PHASE: /* status in */
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_STAT);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_ICCS);
|
|
|
|
sc->sc_compseq = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MESSAGE_OUT_PHASE: /* msg out */
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
|
2001-07-14 00:38:51 +00:00
|
|
|
flags = SCSI_LOW_MSGOUT_UNIFY;
|
|
|
|
if (ti->ti_ophase != ti->ti_phase)
|
|
|
|
flags |= SCSI_LOW_MSGOUT_INIT;
|
|
|
|
len = scsi_low_msgout(slp, ti, flags);
|
|
|
|
|
|
|
|
if (len > 1 && slp->sl_atten == 0)
|
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS);
|
2001-07-14 00:38:51 +00:00
|
|
|
SCSI_LOW_DEASSERT_ATN(slp);
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESSAGE_IN_PHASE: /* msg in */
|
|
|
|
SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN);
|
|
|
|
|
|
|
|
len = bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK;
|
|
|
|
if (sc->sc_compseq != 0)
|
|
|
|
{
|
|
|
|
sc->sc_compseq = 0;
|
|
|
|
if ((ireason & INTR_FC) && len == 2)
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
regv = bus_space_read_1(iot, ioh, cr0_sfifo);
|
|
|
|
scsi_low_statusin(slp, ti, regv | derror);
|
2000-10-23 12:55:51 +00:00
|
|
|
len --;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
slp->sl_error |= FATALIO;
|
|
|
|
scsi_low_assert_msg(slp, ti,
|
|
|
|
SCSI_LOW_MSG_ABORT, 1);
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
cr0_cmd, CMD_MSGOK);
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ireason & INTR_BS)
|
|
|
|
{
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH);
|
|
|
|
bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0)
|
|
|
|
{
|
|
|
|
if (ncv_catch_intr(sc) == 0)
|
|
|
|
goto again;
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ireason & INTR_FC) && len == 1)
|
|
|
|
{
|
|
|
|
regv = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
cr0_sfifo);
|
2001-07-14 00:38:51 +00:00
|
|
|
if (scsi_low_msgin(slp, ti, regv | derror) == 0)
|
|
|
|
{
|
|
|
|
if (scsi_low_is_msgout_continue(ti, 0) != 0)
|
|
|
|
{
|
|
|
|
scsi_low_attention(slp);
|
|
|
|
}
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd,
|
|
|
|
CMD_MSGOK);
|
2001-07-14 00:38:51 +00:00
|
|
|
if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0)
|
|
|
|
{
|
|
|
|
/* XXX:
|
|
|
|
* clear a pending interrupt and sync with
|
|
|
|
* a next interrupt!
|
|
|
|
*/
|
|
|
|
ncv_catch_intr(sc);
|
|
|
|
}
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-14 00:38:51 +00:00
|
|
|
slp->sl_error |= FATALIO;
|
|
|
|
scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1);
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd,
|
|
|
|
CMD_MSGOK);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|