2001-04-25 21:53:04 +04:00
|
|
|
/* $NetBSD: sbic.c,v 1.43 2001/04/25 17:53:08 bouyer Exp $ */
|
1994-10-26 05:01:24 +03:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Christian E. Hopps
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Van Jacobson of Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)scsi.c 7.5 (Berkeley) 5/4/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AMIGA AMD 33C93 scsi adaptor driver
|
|
|
|
*/
|
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
1995-08-18 19:27:29 +04:00
|
|
|
#include <sys/kernel.h> /* For hz */
|
1995-02-12 22:18:33 +03:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/dkstat.h>
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <sys/buf.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
2000-06-26 18:20:25 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <amiga/amiga/device.h>
|
|
|
|
#include <amiga/amiga/custom.h>
|
1995-02-12 22:18:33 +03:00
|
|
|
#include <amiga/amiga/isr.h>
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <amiga/dev/dmavar.h>
|
|
|
|
#include <amiga/dev/sbicreg.h>
|
|
|
|
#include <amiga/dev/sbicvar.h>
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* These are for bounce buffers */
|
|
|
|
#include <amiga/amiga/cc.h>
|
|
|
|
#include <amiga/dev/zbusvar.h>
|
|
|
|
|
|
|
|
/* Since I can't find this in any other header files */
|
|
|
|
#define SCSI_PHASE(reg) (reg&0x07)
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* SCSI delays
|
|
|
|
* In u-seconds, primarily for state changes on the SPC.
|
|
|
|
*/
|
|
|
|
#define SBIC_CMD_WAIT 50000 /* wait per step of 'immediate' cmds */
|
|
|
|
#define SBIC_DATA_WAIT 50000 /* wait per data in/out step */
|
|
|
|
#define SBIC_INIT_WAIT 50000 /* wait per step (both) during init */
|
|
|
|
|
|
|
|
#define SBIC_WAIT(regs, until, timeo) sbicwait(regs, until, timeo, __LINE__)
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
int sbicicmd __P((struct sbic_softc *, int, int, void *, int, void *, int));
|
1997-08-27 15:22:52 +04:00
|
|
|
int sbicgo __P((struct sbic_softc *, struct scsipi_xfer *));
|
|
|
|
int sbicdmaok __P((struct sbic_softc *, struct scsipi_xfer *));
|
1998-08-21 23:13:27 +04:00
|
|
|
int sbicwait __P((sbic_regmap_t, char, int , int));
|
1995-08-13 00:30:45 +04:00
|
|
|
int sbiccheckdmap __P((void *, u_long, u_long));
|
1998-08-21 23:13:27 +04:00
|
|
|
int sbicselectbus __P((struct sbic_softc *, sbic_regmap_t, u_char, u_char, u_char));
|
|
|
|
int sbicxfstart __P((sbic_regmap_t, int, u_char, int));
|
|
|
|
int sbicxfout __P((sbic_regmap_t regs, int, void *, int));
|
|
|
|
int sbicfromscsiperiod __P((struct sbic_softc *, sbic_regmap_t, int));
|
|
|
|
int sbictoscsiperiod __P((struct sbic_softc *, sbic_regmap_t, int));
|
1995-08-18 19:27:29 +04:00
|
|
|
int sbicpoll __P((struct sbic_softc *));
|
|
|
|
int sbicnextstate __P((struct sbic_softc *, u_char, u_char));
|
|
|
|
int sbicmsgin __P((struct sbic_softc *));
|
1998-08-21 23:13:27 +04:00
|
|
|
int sbicxfin __P((sbic_regmap_t regs, int, void *));
|
|
|
|
int sbicabort __P((struct sbic_softc *, sbic_regmap_t, char *));
|
|
|
|
void sbicxfdone __P((struct sbic_softc *, sbic_regmap_t, int));
|
|
|
|
void sbicerror __P((struct sbic_softc *, sbic_regmap_t, u_char));
|
1994-05-08 09:52:54 +04:00
|
|
|
void sbicstart __P((struct sbic_softc *));
|
|
|
|
void sbicreset __P((struct sbic_softc *));
|
1995-08-18 19:27:29 +04:00
|
|
|
void sbic_scsidone __P((struct sbic_acb *, int));
|
|
|
|
void sbic_sched __P((struct sbic_softc *));
|
1998-08-21 23:13:27 +04:00
|
|
|
void sbic_save_ptrs __P((struct sbic_softc *, sbic_regmap_t,int,int));
|
|
|
|
void sbic_load_ptrs __P((struct sbic_softc *, sbic_regmap_t,int,int));
|
1996-04-22 01:10:48 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void sbicdumpstate __P((void));
|
|
|
|
void sbic_dump_acb __P((struct sbic_acb *));
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Synch xfer parameters, and timing conversions
|
|
|
|
*/
|
|
|
|
int sbic_min_period = SBIC_SYN_MIN_PERIOD; /* in cycles = f(ICLK,FSn) */
|
|
|
|
int sbic_max_offset = SBIC_SYN_MAX_OFFSET; /* pure number */
|
|
|
|
|
|
|
|
int sbic_cmd_wait = SBIC_CMD_WAIT;
|
|
|
|
int sbic_data_wait = SBIC_DATA_WAIT;
|
|
|
|
int sbic_init_wait = SBIC_INIT_WAIT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* was broken before.. now if you want this you get it for all drives
|
|
|
|
* on sbic controllers.
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
u_char sbic_inhibit_sync[8];
|
1995-08-18 19:27:29 +04:00
|
|
|
int sbic_enable_reselect = 1;
|
1994-05-08 09:52:54 +04:00
|
|
|
int sbic_clock_override = 0;
|
|
|
|
int sbic_no_dma = 0;
|
1995-08-18 19:27:29 +04:00
|
|
|
int sbic_parallel_operations = 1;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t debug_sbic_regs;
|
1995-02-12 22:18:33 +03:00
|
|
|
int sbicdma_ops = 0; /* total DMA operations */
|
|
|
|
int sbicdma_bounces = 0; /* number operations using bounce buffer */
|
|
|
|
int sbicdma_hits = 0; /* number of DMA chains that were contiguous */
|
|
|
|
int sbicdma_misses = 0; /* number of DMA chains that were not contiguous */
|
1995-08-18 19:27:29 +04:00
|
|
|
int sbicdma_saves = 0;
|
1996-10-13 07:05:43 +04:00
|
|
|
#define QPRINTF(a) if (sbic_debug > 1) printf a
|
1994-05-08 09:52:54 +04:00
|
|
|
int sbic_debug = 0;
|
|
|
|
int sync_debug = 0;
|
|
|
|
int sbic_dma_debug = 0;
|
1995-08-18 19:27:29 +04:00
|
|
|
int reselect_debug = 0;
|
|
|
|
int data_pointer_debug = 0;
|
1995-09-04 17:04:40 +04:00
|
|
|
u_char debug_asr, debug_csr, routine;
|
1995-08-18 19:27:29 +04:00
|
|
|
void sbictimeout __P((struct sbic_softc *dev));
|
1995-09-04 17:04:40 +04:00
|
|
|
|
1995-09-16 20:11:03 +04:00
|
|
|
#define CSR_TRACE_SIZE 32
|
1995-09-04 17:04:40 +04:00
|
|
|
#if CSR_TRACE_SIZE
|
|
|
|
#define CSR_TRACE(w,c,a,x) do { \
|
|
|
|
int s = splbio(); \
|
|
|
|
csr_trace[csr_traceptr].whr = (w); csr_trace[csr_traceptr].csr = (c); \
|
|
|
|
csr_trace[csr_traceptr].asr = (a); csr_trace[csr_traceptr].xtn = (x); \
|
1996-04-22 01:10:48 +04:00
|
|
|
dma_cachectl((caddr_t)&csr_trace[csr_traceptr], sizeof(csr_trace[0])); \
|
1995-09-04 17:04:40 +04:00
|
|
|
csr_traceptr = (csr_traceptr + 1) & (CSR_TRACE_SIZE - 1); \
|
1996-04-22 01:10:48 +04:00
|
|
|
/* dma_cachectl((caddr_t)&csr_traceptr, sizeof(csr_traceptr));*/ \
|
1995-09-04 17:04:40 +04:00
|
|
|
splx(s); \
|
|
|
|
} while (0)
|
|
|
|
int csr_traceptr;
|
|
|
|
int csr_tracesize = CSR_TRACE_SIZE;
|
|
|
|
struct {
|
|
|
|
u_char whr;
|
|
|
|
u_char csr;
|
|
|
|
u_char asr;
|
|
|
|
u_char xtn;
|
|
|
|
} csr_trace[CSR_TRACE_SIZE];
|
|
|
|
#else
|
1996-04-22 01:10:48 +04:00
|
|
|
#define CSR_TRACE(w,c,a,x)
|
1995-09-04 17:04:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SBIC_TRACE_SIZE 0
|
|
|
|
#if SBIC_TRACE_SIZE
|
|
|
|
#define SBIC_TRACE(dev) do { \
|
|
|
|
int s = splbio(); \
|
|
|
|
sbic_trace[sbic_traceptr].sp = &s; \
|
|
|
|
sbic_trace[sbic_traceptr].line = __LINE__; \
|
|
|
|
sbic_trace[sbic_traceptr].sr = s; \
|
|
|
|
sbic_trace[sbic_traceptr].csr = csr_traceptr; \
|
|
|
|
dma_cachectl(&sbic_trace[sbic_traceptr], sizeof(sbic_trace[0])); \
|
|
|
|
sbic_traceptr = (sbic_traceptr + 1) & (SBIC_TRACE_SIZE - 1); \
|
|
|
|
dma_cachectl(&sbic_traceptr, sizeof(sbic_traceptr)); \
|
|
|
|
if (dev) dma_cachectl(dev, sizeof(*dev)); \
|
|
|
|
splx(s); \
|
|
|
|
} while (0)
|
|
|
|
int sbic_traceptr;
|
|
|
|
int sbic_tracesize = SBIC_TRACE_SIZE;
|
|
|
|
struct {
|
|
|
|
void *sp;
|
|
|
|
u_short line;
|
|
|
|
u_short sr;
|
|
|
|
int csr;
|
|
|
|
} sbic_trace[SBIC_TRACE_SIZE];
|
|
|
|
#else
|
1996-04-22 01:10:48 +04:00
|
|
|
#define SBIC_TRACE(dev)
|
1995-09-04 17:04:40 +04:00
|
|
|
#endif
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
#else /* DEBUG */
|
|
|
|
#define QPRINTF(a)
|
|
|
|
#define CSR_TRACE(w,c,a,x)
|
|
|
|
#define SBIC_TRACE(dev)
|
|
|
|
#endif /* DEBUG */
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* default minphys routine for sbic based controllers
|
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
void
|
1994-05-08 09:52:54 +04:00
|
|
|
sbic_minphys(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* No max transfer at this level.
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
minphys(bp);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/*
|
|
|
|
* Save DMA pointers. Take into account partial transfer. Shut down DMA.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbic_save_ptrs(dev, regs, target, lun)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
int target, lun;
|
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
int count, asr, s;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb* acb;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
if( !dev->sc_cur ) return;
|
|
|
|
if( !(dev->sc_flags & SBICF_INDMA) ) return; /* DMA not active */
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
acb = dev->sc_nexus;
|
|
|
|
count = -1;
|
|
|
|
do {
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & SBIC_ASR_DBR ) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbic_save_ptrs: asr %02x canceled!\n", asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
splx(s);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while( asr & (SBIC_ASR_BSY|SBIC_ASR_CIP) );
|
|
|
|
|
|
|
|
/* Save important state */
|
|
|
|
/* must be done before dmastop */
|
|
|
|
acb->sc_dmacmd = dev->sc_dmacmd;
|
|
|
|
SBIC_TC_GET(regs, count);
|
|
|
|
|
|
|
|
/* Shut down DMA ====CAREFUL==== */
|
|
|
|
dev->sc_dmastop(dev);
|
|
|
|
dev->sc_flags &= ~SBICF_INDMA;
|
|
|
|
SBIC_TC_PUT(regs, 0);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
if(!count && sbic_debug) printf("%dcount0",target);
|
1995-08-18 19:27:29 +04:00
|
|
|
if(data_pointer_debug == -1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("SBIC saving target %d data pointers from (%p,%x)%xASR:%02x",
|
1995-08-18 19:27:29 +04:00
|
|
|
target, dev->sc_cur->dc_addr, dev->sc_cur->dc_count,
|
|
|
|
acb->sc_dmacmd, asr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Fixup partial xfers */
|
|
|
|
acb->sc_kv.dc_addr += (dev->sc_tcnt - count);
|
|
|
|
acb->sc_kv.dc_count -= (dev->sc_tcnt - count);
|
|
|
|
acb->sc_pa.dc_addr += (dev->sc_tcnt - count);
|
|
|
|
acb->sc_pa.dc_count -= ((dev->sc_tcnt - count)>>1);
|
|
|
|
|
|
|
|
acb->sc_tcnt = dev->sc_tcnt = count;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" at (%p,%x):%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_cur->dc_addr, dev->sc_cur->dc_count,count);
|
|
|
|
sbicdma_saves++;
|
|
|
|
#endif
|
|
|
|
splx(s);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DOES NOT RESTART DMA!!!
|
|
|
|
*/
|
|
|
|
void sbic_load_ptrs(dev, regs, target, lun)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
int target, lun;
|
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
int s, count;
|
1995-08-18 19:27:29 +04:00
|
|
|
char* vaddr, * paddr;
|
|
|
|
struct sbic_acb *acb;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
acb = dev->sc_nexus;
|
1995-09-04 17:04:40 +04:00
|
|
|
if( !acb->sc_kv.dc_count ) {
|
1995-08-18 19:27:29 +04:00
|
|
|
/* No data to xfer */
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return;
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
dev->sc_last = dev->sc_cur = &acb->sc_pa;
|
|
|
|
dev->sc_tcnt = acb->sc_tcnt;
|
|
|
|
dev->sc_dmacmd = acb->sc_dmacmd;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
sbicdma_ops++;
|
|
|
|
#endif
|
|
|
|
if( !dev->sc_tcnt ) {
|
|
|
|
/* sc_tcnt == 0 implies end of segment */
|
|
|
|
|
|
|
|
/* do kvm to pa mappings */
|
|
|
|
paddr = acb->sc_pa.dc_addr =
|
|
|
|
(char *) kvtop(acb->sc_kv.dc_addr);
|
|
|
|
|
|
|
|
vaddr = acb->sc_kv.dc_addr;
|
|
|
|
count = acb->sc_kv.dc_count;
|
|
|
|
for(count = (NBPG - ((int)vaddr & PGOFSET));
|
|
|
|
count < acb->sc_kv.dc_count
|
|
|
|
&& (char*)kvtop(vaddr + count + 4) == paddr + count + 4;
|
|
|
|
count += NBPG);
|
|
|
|
/* If it's all contiguous... */
|
|
|
|
if(count > acb->sc_kv.dc_count ) {
|
|
|
|
count = acb->sc_kv.dc_count;
|
|
|
|
#ifdef DEBUG
|
|
|
|
sbicdma_hits++;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
sbicdma_misses++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
acb->sc_tcnt = count;
|
|
|
|
acb->sc_pa.dc_count = count >> 1;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DMA recalc:kv(%p,%x)pa(%p,%lx)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_kv.dc_addr,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
acb->sc_pa.dc_addr,
|
|
|
|
acb->sc_tcnt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("SBIC restoring target %d data pointers at (%p,%x)%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
target, dev->sc_cur->dc_addr, dev->sc_cur->dc_count,
|
|
|
|
dev->sc_dmacmd);
|
|
|
|
#endif
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* used by specific sbic controller
|
|
|
|
*
|
|
|
|
* it appears that the higher level code does nothing with LUN's
|
|
|
|
* so I will too. I could plug it in, however so could they
|
1997-08-27 15:22:52 +04:00
|
|
|
* in scsi_scsipi_cmd().
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
void
|
|
|
|
sbic_scsipi_request(chan, req, arg)
|
|
|
|
struct scsipi_channel *chan;
|
|
|
|
scsipi_adapter_req_t req;
|
|
|
|
void *arg;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_xfer *xs;
|
|
|
|
struct scsipi_periph *periph;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct sbic_softc *dev = (void *)chan->chan_adapter->adapt_dev;
|
1995-08-18 19:27:29 +04:00
|
|
|
int flags, s, stat;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch (req) {
|
|
|
|
case ADAPTER_REQ_RUN_XFER:
|
|
|
|
xs = arg;
|
|
|
|
periph = xs->xs_periph;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SBIC_TRACE(dev);
|
|
|
|
flags = xs->xs_control;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (flags & XS_CTL_DATA_UIO)
|
|
|
|
panic("sbic: scsi data uio requested");
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (dev->sc_nexus && flags & XS_CTL_POLL)
|
|
|
|
panic("sbic_scsipi_request: busy");
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
s = splbio();
|
|
|
|
acb = dev->free_list.tqh_first;
|
|
|
|
if (acb)
|
|
|
|
TAILQ_REMOVE(&dev->free_list, acb, chain);
|
|
|
|
splx(s);
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (acb == NULL) {
|
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("unable to allocate acb\n");
|
|
|
|
panic("sbic_scsipi_request");
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
acb->flags = ACB_ACTIVE;
|
|
|
|
if (flags & XS_CTL_DATA_IN)
|
|
|
|
acb->flags |= ACB_DATAIN;
|
|
|
|
acb->xs = xs;
|
|
|
|
bcopy(xs->cmd, &acb->cmd, xs->cmdlen);
|
|
|
|
acb->clen = xs->cmdlen;
|
|
|
|
acb->sc_kv.dc_addr = xs->data;
|
|
|
|
acb->sc_kv.dc_count = xs->datalen;
|
|
|
|
acb->pa_addr = xs->data ? (char *)kvtop(xs->data) : 0; /* XXXX check */
|
|
|
|
|
|
|
|
if (flags & XS_CTL_POLL) {
|
|
|
|
s = splbio();
|
|
|
|
/*
|
|
|
|
* This has major side effects - it locks up the machine
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->sc_flags |= SBICF_ICMD;
|
|
|
|
do {
|
|
|
|
while(dev->sc_nexus)
|
|
|
|
sbicpoll(dev);
|
|
|
|
dev->sc_nexus = acb;
|
|
|
|
dev->sc_stat[0] = -1;
|
|
|
|
dev->sc_xs = xs;
|
|
|
|
dev->target = periph->periph_target;
|
|
|
|
dev->lun = periph->periph_lun;
|
|
|
|
stat = sbicicmd(dev, dev->target, dev->lun,
|
1995-08-18 19:27:29 +04:00
|
|
|
&acb->cmd, acb->clen,
|
|
|
|
acb->sc_kv.dc_addr, acb->sc_kv.dc_count);
|
2001-04-25 21:53:04 +04:00
|
|
|
} while (dev->sc_nexus != acb);
|
|
|
|
sbic_scsidone(acb, stat);
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
splx(s);
|
|
|
|
SBIC_TRACE(dev);
|
|
|
|
return;
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
s = splbio();
|
|
|
|
TAILQ_INSERT_TAIL(&dev->ready_list, acb, chain);
|
1995-08-18 19:27:29 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (dev->sc_nexus) {
|
|
|
|
splx(s);
|
|
|
|
SBIC_TRACE(dev);
|
|
|
|
return;
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/*
|
|
|
|
* nothing is active, try to start it now.
|
|
|
|
*/
|
|
|
|
sbic_sched(dev);
|
|
|
|
splx(s);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SBIC_TRACE(dev);
|
1999-10-01 02:59:52 +04:00
|
|
|
/* TODO: add sbic_poll to do XS_CTL_POLL operations */
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
2001-04-25 21:53:04 +04:00
|
|
|
if (flags & XS_CTL_POLL)
|
|
|
|
return(COMPLETE);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_GROW_RESOURCES:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_SET_XFER_MODE:
|
|
|
|
return;
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* attempt to start the next available command
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
|
|
|
void
|
1995-08-18 19:27:29 +04:00
|
|
|
sbic_sched(dev)
|
1994-05-08 09:52:54 +04:00
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
|
|
|
int flags, /*phase,*/ stat, i;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
if (dev->sc_nexus)
|
|
|
|
return; /* a command is current active */
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
for (acb = dev->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
|
2001-04-25 21:53:04 +04:00
|
|
|
periph = acb->xs->xs_periph;
|
|
|
|
i = periph->periph_target;
|
|
|
|
if (!(dev->sc_tinfo[i].lubusy & (1 << periph->periph_lun))) {
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_tinfo *ti = &dev->sc_tinfo[i];
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&dev->ready_list, acb, chain);
|
|
|
|
dev->sc_nexus = acb;
|
2001-04-25 21:53:04 +04:00
|
|
|
ti = &dev->sc_tinfo[periph->periph_target];
|
|
|
|
ti->lubusy |= (1 << periph->periph_lun);
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_pa.dc_addr = acb->pa_addr; /* XXXX check */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
if (acb == NULL)
|
|
|
|
return; /* did not find an available command */
|
|
|
|
|
|
|
|
dev->sc_xs = xs = acb->xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
periph = xs->xs_periph;
|
1999-10-01 02:59:52 +04:00
|
|
|
flags = xs->xs_control;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1999-10-01 02:59:52 +04:00
|
|
|
if (flags & XS_CTL_RESET)
|
1994-05-08 09:52:54 +04:00
|
|
|
sbicreset(dev);
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("sbic_sched(%d,%d)\n", periph->periph_target,
|
|
|
|
periph->periph_lun);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_stat[0] = -1;
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->target = periph->periph_target;
|
|
|
|
dev->lun = periph->periph_lun;
|
1999-10-01 02:59:52 +04:00
|
|
|
if ( flags & XS_CTL_POLL || ( !sbic_parallel_operations
|
1999-11-02 01:22:33 +03:00
|
|
|
&& (sbicdmaok(dev, xs) == 0)))
|
2001-04-25 21:53:04 +04:00
|
|
|
stat = sbicicmd(dev, periph->periph_target,
|
|
|
|
periph->periph_lun, &acb->cmd,
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->clen, acb->sc_kv.dc_addr, acb->sc_kv.dc_count);
|
1999-11-02 01:22:33 +03:00
|
|
|
else if (sbicgo(dev, xs) == 0 && xs->error != XS_SELTIMEOUT) {
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
return;
|
1995-09-04 17:04:40 +04:00
|
|
|
} else
|
1994-05-08 09:52:54 +04:00
|
|
|
stat = dev->sc_stat[0];
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
sbic_scsidone(acb, stat);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1995-08-18 19:27:29 +04:00
|
|
|
sbic_scsidone(acb, stat)
|
|
|
|
struct sbic_acb *acb;
|
1994-05-08 09:52:54 +04:00
|
|
|
int stat;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_softc *dev;
|
1996-04-22 01:10:48 +04:00
|
|
|
int dosched = 0;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
xs = acb->xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
periph = xs->xs_periph;
|
|
|
|
dev = (void *)periph->periph_channel->chan_adapter->adapt_dev;
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1995-08-18 19:27:29 +04:00
|
|
|
if (acb == NULL || xs == NULL) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbic_scsidone -- (%d,%d) no scsi_xfer\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target, dev->lun);
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->status = stat;
|
|
|
|
xs->resid = 0; /* XXXX */
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("scsidone: (%d,%d)->(%d,%d)%02x\n",
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_target, periph->periph_lun,
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target, dev->lun, stat);
|
2001-04-25 21:53:04 +04:00
|
|
|
if( periph->periph_target ==
|
|
|
|
periph->periph_channel->chan_id)
|
1995-08-18 19:27:29 +04:00
|
|
|
panic("target == hostid");
|
|
|
|
#endif
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->error == XS_NOERROR) {
|
|
|
|
if (stat == SCSI_CHECK || stat == SCSI_BUSY)
|
1994-05-08 09:52:54 +04:00
|
|
|
xs->error = XS_BUSY;
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Remove the ACB from whatever queue it's on. We have to do a bit of
|
|
|
|
* a hack to figure out which queue it's on. Note that it is *not*
|
|
|
|
* necessary to cdr down the ready queue, but we must cdr down the
|
|
|
|
* nexus queue and see if it's there, so we can mark the unit as no
|
|
|
|
* longer busy. This code is sickening, but it works.
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
if (acb == dev->sc_nexus) {
|
|
|
|
dev->sc_nexus = NULL;
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_xs = NULL;
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->sc_tinfo[periph->periph_target].lubusy &=
|
|
|
|
~(1<<periph->periph_lun);
|
1995-08-18 19:27:29 +04:00
|
|
|
if (dev->ready_list.tqh_first)
|
|
|
|
dosched = 1; /* start next command */
|
|
|
|
} else if (dev->ready_list.tqh_last == &acb->chain.tqe_next) {
|
|
|
|
TAILQ_REMOVE(&dev->ready_list, acb, chain);
|
1994-05-08 09:52:54 +04:00
|
|
|
} else {
|
1995-08-18 19:27:29 +04:00
|
|
|
register struct sbic_acb *acb2;
|
|
|
|
for (acb2 = dev->nexus_list.tqh_first; acb2;
|
1995-09-04 17:04:40 +04:00
|
|
|
acb2 = acb2->chain.tqe_next) {
|
1995-08-18 19:27:29 +04:00
|
|
|
if (acb2 == acb) {
|
|
|
|
TAILQ_REMOVE(&dev->nexus_list, acb, chain);
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->sc_tinfo[periph->periph_target].lubusy
|
|
|
|
&= ~(1<<periph->periph_lun);
|
1995-08-18 19:27:29 +04:00
|
|
|
break;
|
|
|
|
}
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
if (acb2)
|
|
|
|
;
|
|
|
|
else if (acb->chain.tqe_next) {
|
|
|
|
TAILQ_REMOVE(&dev->ready_list, acb, chain);
|
|
|
|
} else {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: can't find matching acb\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dev.dv_xname);
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Put it on the free list. */
|
|
|
|
acb->flags = ACB_FREE;
|
|
|
|
TAILQ_INSERT_HEAD(&dev->free_list, acb, chain);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->sc_tinfo[periph->periph_target].cmds++;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
scsipi_done(xs);
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
if (dosched)
|
|
|
|
sbic_sched(dev);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicdmaok(dev, xs)
|
|
|
|
struct sbic_softc *dev;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
1999-11-02 01:22:33 +03:00
|
|
|
if (sbic_no_dma || !xs->datalen || xs->datalen & 0x1 ||
|
|
|
|
(u_int)xs->data & 0x3)
|
1994-05-08 09:52:54 +04:00
|
|
|
return(0);
|
|
|
|
/*
|
|
|
|
* controller supports dma to any addresses?
|
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
else if ((dev->sc_flags & SBICF_BADDMA) == 0)
|
1994-05-08 09:52:54 +04:00
|
|
|
return(1);
|
|
|
|
/*
|
|
|
|
* this address is ok for dma?
|
|
|
|
*/
|
|
|
|
else if (sbiccheckdmap(xs->data, xs->datalen, dev->sc_dmamask) == 0)
|
|
|
|
return(1);
|
|
|
|
/*
|
|
|
|
* we have a bounce buffer?
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
else if (dev->sc_tinfo[xs->xs_periph->periph_target].bounce)
|
1995-08-18 19:27:29 +04:00
|
|
|
return(1);
|
|
|
|
/*
|
|
|
|
* try to get one
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
else if ((dev->sc_tinfo[xs->xs_periph->periph_target].bounce
|
1996-04-22 01:10:48 +04:00
|
|
|
= (char *)alloc_z2mem(MAXPHYS))) {
|
2001-04-25 21:53:04 +04:00
|
|
|
if (isztwomem(dev->sc_tinfo[xs->xs_periph->periph_target].bounce))
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("alloc ZII target %d bounce pa 0x%x\n",
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
|
|
|
kvtop(dev->sc_tinfo[xs->xs_periph->periph_target].bounce));
|
|
|
|
else if (dev->sc_tinfo[xs->xs_periph->periph_target].bounce)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("alloc CHIP target %d bounce pa 0x%p\n",
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
|
|
|
PREP_DMA_MEM(dev->sc_tinfo[xs->xs_periph->periph_target].bounce));
|
1994-05-08 09:52:54 +04:00
|
|
|
return(1);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicwait(regs, until, timeo, line)
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
char until;
|
|
|
|
int timeo;
|
|
|
|
int line;
|
|
|
|
{
|
|
|
|
u_char val;
|
|
|
|
int csr;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE((struct sbic_softc *)0);
|
1994-05-08 09:52:54 +04:00
|
|
|
if (timeo == 0)
|
|
|
|
timeo = 1000000; /* some large value.. */
|
|
|
|
|
|
|
|
GET_SBIC_asr(regs,val);
|
|
|
|
while ((val & until) == 0) {
|
|
|
|
if (timeo-- == 0) {
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicwait TIMEO @%d with asr=x%x csr=x%x\n",
|
1994-05-08 09:52:54 +04:00
|
|
|
line, val, csr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#if defined(DDB) && defined(DEBUG)
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
return(val); /* Maybe I should abort */
|
1994-05-08 09:52:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(1);
|
|
|
|
GET_SBIC_asr(regs,val);
|
|
|
|
}
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE((struct sbic_softc *)0);
|
1994-05-08 09:52:54 +04:00
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
int
|
1994-05-08 09:52:54 +04:00
|
|
|
sbicabort(dev, regs, where)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
char *where;
|
|
|
|
{
|
|
|
|
u_char csr, asr;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_asr(regs, asr);
|
1995-09-04 17:04:40 +04:00
|
|
|
GET_SBIC_csr(regs, csr);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("%s: abort %s: csr = 0x%02x, asr = 0x%02x\n",
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_dev.dv_xname, where, csr, asr);
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Clean up running command */
|
|
|
|
if (dev->sc_nexus != NULL) {
|
|
|
|
dev->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
sbic_scsidone(dev->sc_nexus, dev->sc_stat[0]);
|
|
|
|
}
|
|
|
|
while (acb = dev->nexus_list.tqh_first) {
|
|
|
|
acb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
sbic_scsidone(acb, -1 /*acb->stat[0]*/);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Clean up chip itself */
|
1994-05-08 09:52:54 +04:00
|
|
|
if (dev->sc_flags & SBICF_SELECTED) {
|
1995-08-18 19:27:29 +04:00
|
|
|
while( asr & SBIC_ASR_DBR ) {
|
|
|
|
/* sbic is jammed w/data. need to clear it */
|
|
|
|
/* But we don't know what direction it needs to go */
|
|
|
|
GET_SBIC_data(regs, asr);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: abort %s: clearing data buffer 0x%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dev.dv_xname, where, asr);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & SBIC_ASR_DBR ) /* Not the read direction, then */
|
|
|
|
SET_SBIC_data(regs, asr);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
}
|
|
|
|
WAIT_CIP(regs);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: sbicabort - sending ABORT command\n", dev->sc_dev.dv_xname);
|
1994-05-08 09:52:54 +04:00
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI)) {
|
|
|
|
/* ok, get more drastic.. */
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: sbicabort - asr %x, trying to reset\n", dev->sc_dev.dv_xname, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicreset(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
1995-08-18 19:27:29 +04:00
|
|
|
return -1;
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: sbicabort - sending DISC command\n", dev->sc_dev.dv_xname);
|
1995-08-18 19:27:29 +04:00
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_DISC);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
do {
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_csr (regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('a',csr,asr,0);
|
1994-05-08 09:52:54 +04:00
|
|
|
} while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
|
|
|
|
&& (csr != SBIC_CSR_CMD_INVALID));
|
|
|
|
|
|
|
|
/* lets just hope it worked.. */
|
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
return -1;
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Initialize driver-private structures
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
void
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicinit(dev)
|
|
|
|
struct sbic_softc *dev;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1996-04-22 01:10:48 +04:00
|
|
|
u_int i;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
1995-11-30 03:56:23 +03:00
|
|
|
u_int inhibit_sync;
|
|
|
|
|
|
|
|
extern u_long scsi_nosync;
|
|
|
|
extern int shift_nosync;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
if ((dev->sc_flags & SBICF_ALIVE) == 0) {
|
|
|
|
TAILQ_INIT(&dev->ready_list);
|
|
|
|
TAILQ_INIT(&dev->nexus_list);
|
|
|
|
TAILQ_INIT(&dev->free_list);
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_init(&dev->sc_timo_ch);
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_nexus = NULL;
|
|
|
|
dev->sc_xs = NULL;
|
|
|
|
acb = dev->sc_acb;
|
|
|
|
bzero(acb, sizeof(dev->sc_acb));
|
|
|
|
for (i = 0; i < sizeof(dev->sc_acb) / sizeof(*acb); i++) {
|
|
|
|
TAILQ_INSERT_TAIL(&dev->free_list, acb, chain);
|
|
|
|
acb++;
|
|
|
|
}
|
|
|
|
bzero(dev->sc_tinfo, sizeof(dev->sc_tinfo));
|
1995-09-04 17:04:40 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* make sure timeout is really not needed */
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_reset(&dev->sc_timo_ch, 30 * hz,
|
|
|
|
(void *)sbictimeout, dev);
|
1995-09-04 17:04:40 +04:00
|
|
|
#endif
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
} else panic("sbic: reinitializing driver!");
|
|
|
|
|
|
|
|
dev->sc_flags |= SBICF_ALIVE;
|
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* initialize inhibit array */
|
|
|
|
if (scsi_nosync) {
|
|
|
|
inhibit_sync = (scsi_nosync >> shift_nosync) & 0xff;
|
|
|
|
shift_nosync += 8;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (inhibit_sync)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: Inhibiting synchronous transfer %02x\n",
|
1995-11-30 03:56:23 +03:00
|
|
|
dev->sc_dev.dv_xname, inhibit_sync);
|
|
|
|
#endif
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
if (inhibit_sync & (1 << i))
|
|
|
|
sbic_inhibit_sync[i] = 1;
|
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicreset(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sbicreset(dev)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1996-04-22 01:10:48 +04:00
|
|
|
u_int my_id, s;
|
1995-08-18 19:27:29 +04:00
|
|
|
u_char csr;
|
1996-04-22 01:10:48 +04:00
|
|
|
#if 0
|
|
|
|
u_int i;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
1996-04-22 01:10:48 +04:00
|
|
|
#endif
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
|
|
|
if (dev->sc_flags & SBICF_ALIVE) {
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
s = splbio();
|
2001-04-25 21:53:04 +04:00
|
|
|
my_id = dev->sc_channel.chan_id & SBIC_ID_MASK;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Enable advanced mode */
|
1994-05-08 09:52:54 +04:00
|
|
|
my_id |= SBIC_ID_EAF /*| SBIC_ID_EHP*/ ;
|
|
|
|
SET_SBIC_myid(regs, my_id);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable interrupts (in dmainit) then reset the chip
|
|
|
|
*/
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_RESET);
|
|
|
|
DELAY(25);
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
GET_SBIC_csr(regs, csr); /* clears interrupt also */
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
if (dev->sc_clkfreq < 110)
|
|
|
|
my_id |= SBIC_ID_FS_8_10;
|
|
|
|
else if (dev->sc_clkfreq < 160)
|
|
|
|
my_id |= SBIC_ID_FS_12_15;
|
|
|
|
else if (dev->sc_clkfreq < 210)
|
|
|
|
my_id |= SBIC_ID_FS_16_20;
|
|
|
|
|
|
|
|
SET_SBIC_myid(regs, my_id);
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* Set up various chip parameters
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI /* | SBIC_CTL_HSP */
|
1994-05-08 09:52:54 +04:00
|
|
|
| SBIC_MACHINE_DMA_MODE);
|
|
|
|
/*
|
|
|
|
* don't allow (re)selection (SBIC_RID_ES)
|
|
|
|
* until we can handle target mode!!
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
SET_SBIC_rselid(regs, SBIC_RID_ER);
|
1994-05-08 09:52:54 +04:00
|
|
|
SET_SBIC_syn(regs, 0); /* asynch for now */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anything else was zeroed by reset
|
|
|
|
*/
|
|
|
|
splx(s);
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
|
|
|
if ((dev->sc_flags & SBICF_ALIVE) == 0) {
|
|
|
|
TAILQ_INIT(&dev->ready_list);
|
|
|
|
TAILQ_INIT(&dev->nexus_list);
|
|
|
|
TAILQ_INIT(&dev->free_list);
|
|
|
|
dev->sc_nexus = NULL;
|
|
|
|
dev->sc_xs = NULL;
|
|
|
|
acb = dev->sc_acb;
|
|
|
|
bzero(acb, sizeof(dev->sc_acb));
|
|
|
|
for (i = 0; i < sizeof(dev->sc_acb) / sizeof(*acb); i++) {
|
|
|
|
TAILQ_INSERT_TAIL(&dev->free_list, acb, chain);
|
|
|
|
acb++;
|
|
|
|
}
|
|
|
|
bzero(dev->sc_tinfo, sizeof(dev->sc_tinfo));
|
|
|
|
} else {
|
|
|
|
if (dev->sc_nexus != NULL) {
|
|
|
|
dev->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
sbic_scsidone(dev->sc_nexus, dev->sc_stat[0]);
|
|
|
|
}
|
|
|
|
while (acb = dev->nexus_list.tqh_first) {
|
|
|
|
acb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
sbic_scsidone(acb, -1 /*acb->stat[0]*/);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_flags |= SBICF_ALIVE;
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sbicerror(dev, regs, csr)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
u_char csr;
|
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
xs = dev->sc_xs;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (xs == NULL)
|
|
|
|
panic("sbicerror");
|
|
|
|
#endif
|
1999-10-01 02:59:52 +04:00
|
|
|
if (xs->xs_control & XS_CTL_SILENT)
|
1994-05-08 09:52:54 +04:00
|
|
|
return;
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: ", dev->sc_dev.dv_xname);
|
|
|
|
printf("csr == 0x%02x\n", csr); /* XXX */
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* select the bus, return when selected or error.
|
|
|
|
*/
|
|
|
|
int
|
1994-12-28 12:24:55 +03:00
|
|
|
sbicselectbus(dev, regs, target, lun, our_addr)
|
1994-05-08 09:52:54 +04:00
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-12-28 12:24:55 +03:00
|
|
|
u_char target, lun, our_addr;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
|
|
|
u_char asr, csr, id;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("sbicselectbus %d\n", target));
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-08 09:52:54 +04:00
|
|
|
* if we're already selected, return (XXXX panic maybe?)
|
|
|
|
*/
|
1995-09-04 17:04:40 +04:00
|
|
|
if (dev->sc_flags & SBICF_SELECTED) {
|
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
return(1);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
1995-09-04 17:04:40 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* issue select
|
|
|
|
*/
|
|
|
|
SBIC_TC_PUT(regs, 0);
|
|
|
|
SET_SBIC_selid(regs, target);
|
|
|
|
SET_SBIC_timeo(regs, SBIC_TIMEOUT(250,dev->sc_clkfreq));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set sync or async
|
|
|
|
*/
|
|
|
|
if (dev->sc_sync[target].state == SYNC_DONE)
|
1995-08-13 00:30:45 +04:00
|
|
|
SET_SBIC_syn(regs, SBIC_SYN (dev->sc_sync[target].offset,
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_sync[target].period));
|
|
|
|
else
|
|
|
|
SET_SBIC_syn(regs, SBIC_SYN (0, sbic_min_period));
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & (SBIC_ASR_INT|SBIC_ASR_BSY) ) {
|
|
|
|
/* This means we got ourselves reselected upon */
|
1996-10-13 07:05:43 +04:00
|
|
|
/* printf("sbicselectbus: INT/BSY asr %02x\n", asr);*/
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DDB
|
|
|
|
/* Debugger();*/
|
|
|
|
#endif
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wait for select (merged from seperate function may need
|
|
|
|
* cleanup)
|
|
|
|
*/
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
do {
|
1995-08-18 19:27:29 +04:00
|
|
|
asr = SBIC_WAIT(regs, SBIC_ASR_INT | SBIC_ASR_LCI, 0);
|
|
|
|
if (asr & SBIC_ASR_LCI) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (reselect_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicselectbus: late LCI asr %02x\n", asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_csr (regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('s',csr,asr,target);
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("%02x ", csr));
|
1995-08-18 19:27:29 +04:00
|
|
|
if( csr == SBIC_CSR_RSLT_NI || csr == SBIC_CSR_RSLT_IFY) {
|
|
|
|
#ifdef DEBUG
|
1995-09-04 17:04:40 +04:00
|
|
|
if(reselect_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicselectbus: reselected asr %02x\n", asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1995-08-24 19:46:19 +04:00
|
|
|
/* We need to handle this now so we don't lock up later */
|
|
|
|
sbicnextstate(dev, csr, asr);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if( csr == SBIC_CSR_SLT || csr == SBIC_CSR_SLT_ATN) {
|
|
|
|
panic("sbicselectbus: target issued select!");
|
|
|
|
return 1;
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
} while (csr != (SBIC_CSR_MIS_2|MESG_OUT_PHASE)
|
|
|
|
&& csr != (SBIC_CSR_MIS_2|CMD_PHASE) && csr != SBIC_CSR_SEL_TIMEO);
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Enable (or not) reselection */
|
1995-09-04 17:04:40 +04:00
|
|
|
if(!sbic_enable_reselect && dev->nexus_list.tqh_first == NULL)
|
1995-08-18 19:27:29 +04:00
|
|
|
SET_SBIC_rselid (regs, 0);
|
|
|
|
else
|
|
|
|
SET_SBIC_rselid (regs, SBIC_RID_ER);
|
|
|
|
|
|
|
|
if (csr == (SBIC_CSR_MIS_2|CMD_PHASE)) {
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_flags |= SBICF_SELECTED; /* device ignored ATN */
|
1995-08-18 19:27:29 +04:00
|
|
|
GET_SBIC_selid(regs, id);
|
|
|
|
dev->target = id;
|
|
|
|
GET_SBIC_tlun(regs,dev->lun);
|
|
|
|
if( dev->lun & SBIC_TLUN_VALID )
|
|
|
|
dev->lun &= SBIC_TLUN_MASK;
|
|
|
|
else
|
|
|
|
dev->lun = lun;
|
|
|
|
} else if (csr == (SBIC_CSR_MIS_2|MESG_OUT_PHASE)) {
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* Send identify message
|
|
|
|
* (SCSI-2 requires an identify msg (?))
|
|
|
|
*/
|
|
|
|
GET_SBIC_selid(regs, id);
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target = id;
|
|
|
|
GET_SBIC_tlun(regs,dev->lun);
|
|
|
|
if( dev->lun & SBIC_TLUN_VALID )
|
|
|
|
dev->lun &= SBIC_TLUN_MASK;
|
|
|
|
else
|
|
|
|
dev->lun = lun;
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
|
|
|
* handle drives that don't want to be asked
|
1994-05-08 09:52:54 +04:00
|
|
|
* whether to go sync at all.
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
if (sbic_inhibit_sync[id]
|
|
|
|
&& dev->sc_sync[id].state == SYNC_START) {
|
1994-05-08 09:52:54 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Forcing target %d asynchronous.\n", id);
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
|
|
|
dev->sc_sync[id].offset = 0;
|
|
|
|
dev->sc_sync[id].period = sbic_min_period;
|
|
|
|
dev->sc_sync[id].state = SYNC_DONE;
|
|
|
|
}
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
if (dev->sc_sync[id].state != SYNC_START){
|
1999-10-01 02:59:52 +04:00
|
|
|
if( dev->sc_xs->xs_control & XS_CTL_POLL
|
1995-08-18 19:27:29 +04:00
|
|
|
|| (dev->sc_flags & SBICF_ICMD)
|
|
|
|
|| !sbic_enable_reselect )
|
|
|
|
SEND_BYTE (regs, MSG_IDENTIFY | lun);
|
|
|
|
else
|
|
|
|
SEND_BYTE (regs, MSG_IDENTIFY_DR | lun);
|
|
|
|
} else {
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* try to initiate a sync transfer.
|
1995-08-13 00:30:45 +04:00
|
|
|
* So compose the sync message we're going
|
1994-05-08 09:52:54 +04:00
|
|
|
* to send to the target
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Sending sync request to target %d ... ",
|
1994-05-08 09:52:54 +04:00
|
|
|
id);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* setup scsi message sync message request
|
|
|
|
*/
|
1994-12-28 12:24:55 +03:00
|
|
|
dev->sc_msg[0] = MSG_IDENTIFY | lun;
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_msg[1] = MSG_EXT_MESSAGE;
|
|
|
|
dev->sc_msg[2] = 3;
|
|
|
|
dev->sc_msg[3] = MSG_SYNC_REQ;
|
|
|
|
dev->sc_msg[4] = sbictoscsiperiod(dev, regs,
|
|
|
|
sbic_min_period);
|
|
|
|
dev->sc_msg[5] = sbic_max_offset;
|
|
|
|
|
|
|
|
if (sbicxfstart(regs, 6, MESG_OUT_PHASE, sbic_cmd_wait))
|
|
|
|
sbicxfout(regs, 6, dev->sc_msg, MESG_OUT_PHASE);
|
|
|
|
|
|
|
|
dev->sc_sync[id].state = SYNC_SENT;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("sent\n");
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_csr (regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('y',csr,asr,target);
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("[%02x]", csr));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug && dev->sc_sync[id].state == SYNC_SENT)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("csr-result of last msgout: 0x%x\n", csr);
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (csr != SBIC_CSR_SEL_TIMEO)
|
|
|
|
dev->sc_flags |= SBICF_SELECTED;
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
if (csr == SBIC_CSR_SEL_TIMEO)
|
|
|
|
dev->sc_xs->error = XS_SELTIMEOUT;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("\n"));
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
return(csr == SBIC_CSR_SEL_TIMEO);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicxfstart(regs, len, phase, wait)
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int len, wait;
|
|
|
|
u_char phase;
|
|
|
|
{
|
|
|
|
u_char id;
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
switch (phase) {
|
|
|
|
case DATA_IN_PHASE:
|
|
|
|
case MESG_IN_PHASE:
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_selid (regs, id);
|
|
|
|
id |= SBIC_SID_FROM_SCSI;
|
|
|
|
SET_SBIC_selid (regs, id);
|
|
|
|
SBIC_TC_PUT (regs, (unsigned)len);
|
1995-08-18 19:27:29 +04:00
|
|
|
break;
|
|
|
|
case DATA_OUT_PHASE:
|
|
|
|
case MESG_OUT_PHASE:
|
|
|
|
case CMD_PHASE:
|
|
|
|
GET_SBIC_selid (regs, id);
|
|
|
|
id &= ~SBIC_SID_FROM_SCSI;
|
|
|
|
SET_SBIC_selid (regs, id);
|
|
|
|
SBIC_TC_PUT (regs, (unsigned)len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SBIC_TC_PUT (regs, 0);
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("sbicxfstart %d, %d, %d\n", len, phase, wait));
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicxfout(regs, len, bp, phase)
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int len;
|
|
|
|
void *bp;
|
|
|
|
int phase;
|
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
u_char orig_csr, asr, *buf;
|
1994-05-08 09:52:54 +04:00
|
|
|
int wait;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
buf = bp;
|
|
|
|
wait = sbic_data_wait;
|
|
|
|
|
|
|
|
QPRINTF(("sbicxfout {%d} %02x %02x %02x %02x %02x "
|
1995-08-13 00:30:45 +04:00
|
|
|
"%02x %02x %02x %02x %02x\n", len, buf[0], buf[1], buf[2],
|
1994-05-08 09:52:54 +04:00
|
|
|
buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]));
|
|
|
|
|
|
|
|
GET_SBIC_csr (regs, orig_csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('>',orig_csr,0,0);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-08 09:52:54 +04:00
|
|
|
* sigh.. WD-PROTO strikes again.. sending the command in one go
|
|
|
|
* causes the chip to lock up if talking to certain (misbehaving?)
|
|
|
|
* targets. Anyway, this procedure should work for all targets, but
|
|
|
|
* it's slightly slower due to the overhead
|
|
|
|
*/
|
|
|
|
WAIT_CIP (regs);
|
|
|
|
SET_SBIC_cmd (regs, SBIC_CMD_XFER_INFO);
|
|
|
|
for (;len > 0; len--) {
|
|
|
|
GET_SBIC_asr (regs, asr);
|
|
|
|
while ((asr & SBIC_ASR_DBR) == 0) {
|
|
|
|
if ((asr & SBIC_ASR_INT) || --wait < 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sbic_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicxfout fail: l%d i%x w%d\n",
|
1994-05-08 09:52:54 +04:00
|
|
|
len, asr, wait);
|
|
|
|
#endif
|
|
|
|
return (len);
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
/* DELAY(1);*/
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_asr (regs, asr);
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_SBIC_data (regs, *buf);
|
|
|
|
buf++;
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
SBIC_TC_GET(regs, len);
|
|
|
|
QPRINTF(("sbicxfout done %d bytes\n", len));
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* this leaves with one csr to be read
|
|
|
|
*/
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* returns # bytes left to read */
|
|
|
|
int
|
1994-05-08 09:52:54 +04:00
|
|
|
sbicxfin(regs, len, bp)
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int len;
|
|
|
|
void *bp;
|
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
int wait;
|
1994-05-08 09:52:54 +04:00
|
|
|
u_char *obp, *buf;
|
|
|
|
u_char orig_csr, csr, asr;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
wait = sbic_data_wait;
|
|
|
|
obp = bp;
|
|
|
|
buf = bp;
|
|
|
|
|
|
|
|
GET_SBIC_csr (regs, orig_csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('<',orig_csr,0,0);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
QPRINTF(("sbicxfin %d, csr=%02x\n", len, orig_csr));
|
|
|
|
|
|
|
|
WAIT_CIP (regs);
|
|
|
|
SET_SBIC_cmd (regs, SBIC_CMD_XFER_INFO);
|
|
|
|
for (;len > 0; len--) {
|
|
|
|
GET_SBIC_asr (regs, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
if((asr & SBIC_ASR_PE)) {
|
|
|
|
#ifdef DEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicxfin parity error: l%d i%x w%d\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
len, asr, wait);
|
|
|
|
/* return ((unsigned long)buf - (unsigned long)bp); */
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
while ((asr & SBIC_ASR_DBR) == 0) {
|
|
|
|
if ((asr & SBIC_ASR_INT) || --wait < 0) {
|
|
|
|
#ifdef DEBUG
|
1995-08-18 19:27:29 +04:00
|
|
|
if (sbic_debug) {
|
|
|
|
QPRINTF(("sbicxfin fail:{%d} %02x %02x %02x %02x %02x %02x "
|
|
|
|
"%02x %02x %02x %02x\n", len, obp[0], obp[1], obp[2],
|
|
|
|
obp[3], obp[4], obp[5], obp[6], obp[7], obp[8], obp[9]));
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicxfin fail: l%d i%x w%d\n",
|
1994-05-08 09:52:54 +04:00
|
|
|
len, asr, wait);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! asr & SBIC_ASR_BSY ) {
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('<',csr,asr,len);
|
1995-08-18 19:27:29 +04:00
|
|
|
QPRINTF(("[CSR%02xASR%02x]", csr, asr));
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* DELAY(1);*/
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_asr (regs, asr);
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_SBIC_data (regs, *buf);
|
1995-08-18 19:27:29 +04:00
|
|
|
/* QPRINTF(("asr=%02x, csr=%02x, data=%02x\n", asr, csr, *buf));*/
|
1994-05-08 09:52:54 +04:00
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPRINTF(("sbicxfin {%d} %02x %02x %02x %02x %02x %02x "
|
1995-08-13 00:30:45 +04:00
|
|
|
"%02x %02x %02x %02x\n", len, obp[0], obp[1], obp[2],
|
1994-05-08 09:52:54 +04:00
|
|
|
obp[3], obp[4], obp[5], obp[6], obp[7], obp[8], obp[9]));
|
|
|
|
|
|
|
|
/* this leaves with one csr to be read */
|
1995-08-18 19:27:29 +04:00
|
|
|
return len;
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SCSI 'immediate' command: issue a command to some SCSI device
|
|
|
|
* and get back an 'immediate' response (i.e., do programmed xfer
|
|
|
|
* to get the response data). 'cbuf' is a buffer containing a scsi
|
|
|
|
* command of length clen bytes. 'buf' is a buffer of length 'len'
|
|
|
|
* bytes for data. The transfer direction is determined by the device
|
|
|
|
* (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
|
1995-08-18 19:27:29 +04:00
|
|
|
* command must supply no data.
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
|
|
|
int
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicicmd(dev, target, lun, cbuf, clen, buf, len)
|
1994-05-08 09:52:54 +04:00
|
|
|
struct sbic_softc *dev;
|
|
|
|
void *cbuf, *buf;
|
|
|
|
int clen, len;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
u_char phase, csr, asr;
|
1996-04-22 01:10:48 +04:00
|
|
|
int wait, i;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
|
|
|
|
|
|
|
#define CSR_LOG_BUF_SIZE 0
|
|
|
|
#if CSR_LOG_BUF_SIZE
|
|
|
|
int bufptr;
|
|
|
|
int csrbuf[CSR_LOG_BUF_SIZE];
|
|
|
|
bufptr=0;
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
acb = dev->sc_nexus;
|
|
|
|
|
|
|
|
/* Make sure pointers are OK */
|
|
|
|
dev->sc_last = dev->sc_cur = &acb->sc_pa;
|
|
|
|
dev->sc_tcnt = acb->sc_tcnt = 0;
|
|
|
|
acb->sc_pa.dc_count = 0; /* No DMA */
|
|
|
|
acb->sc_kv.dc_addr = buf;
|
|
|
|
acb->sc_kv.dc_count = len;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
routine = 3;
|
|
|
|
debug_sbic_regs = regs; /* store this to allow debug calls */
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicicmd(%d,%d):%d\n", target, lun,
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_kv.dc_count);
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-08 09:52:54 +04:00
|
|
|
* set the sbic into non-DMA mode
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI /*| SBIC_CTL_HSP*/);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
dev->sc_stat[0] = 0xff;
|
|
|
|
dev->sc_msg[0] = 0xff;
|
1995-08-18 19:27:29 +04:00
|
|
|
i = 1; /* pre-load */
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* We're stealing the SCSI bus */
|
|
|
|
dev->sc_flags |= SBICF_ICMD;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* select the SCSI bus (it's an error if bus isn't free)
|
|
|
|
*/
|
|
|
|
if (!( dev->sc_flags & SBICF_SELECTED )
|
|
|
|
&& sbicselectbus(dev, regs, target, lun, dev->sc_scsiaddr)) {
|
1999-11-02 01:22:33 +03:00
|
|
|
/* printf("sbicicmd: trying to select busy bus!\n"); */
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_flags &= ~SBICF_ICMD;
|
1994-05-08 09:52:54 +04:00
|
|
|
return(-1);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Wait for a phase change (or error) then let the device sequence
|
|
|
|
* us through the various SCSI phases.
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
wait = sbic_cmd_wait;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = GET_SBIC_asr (regs, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
GET_SBIC_csr (regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('I',csr,asr,target);
|
1995-08-18 19:27:29 +04:00
|
|
|
QPRINTF((">ASR:%02xCSR:%02x<", asr, csr));
|
|
|
|
|
|
|
|
#if CSR_LOG_BUF_SIZE
|
|
|
|
csrbuf[bufptr++] = csr;
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
switch (csr) {
|
|
|
|
case SBIC_CSR_S_XFERRED:
|
|
|
|
case SBIC_CSR_DISC:
|
|
|
|
case SBIC_CSR_DISC_1:
|
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
|
|
|
GET_SBIC_cmd_phase (regs, phase);
|
|
|
|
if (phase == 0x60) {
|
|
|
|
GET_SBIC_tlun (regs, dev->sc_stat[0]);
|
|
|
|
i = 0; /* done */
|
1996-04-22 01:10:48 +04:00
|
|
|
/* break; */ /* Bypass all the state gobldygook */
|
1995-08-18 19:27:29 +04:00
|
|
|
} else {
|
1994-05-08 09:52:54 +04:00
|
|
|
#ifdef DEBUG
|
1995-08-18 19:27:29 +04:00
|
|
|
if(reselect_debug>1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicicmd: handling disconnect\n");
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
i = SBIC_STATE_DISCONNECT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SBIC_CSR_XFERRED|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|CMD_PHASE:
|
|
|
|
if (sbicxfstart(regs, clen, CMD_PHASE, sbic_cmd_wait))
|
|
|
|
if (sbicxfout(regs, clen,
|
|
|
|
cbuf, CMD_PHASE))
|
|
|
|
i = sbicabort(dev, regs,"icmd sending cmd");
|
|
|
|
#if 0
|
|
|
|
GET_SBIC_csr(regs, csr); /* Lets us reload tcount */
|
1994-05-08 09:52:54 +04:00
|
|
|
WAIT_CIP(regs);
|
1995-08-18 19:27:29 +04:00
|
|
|
GET_SBIC_asr(regs, asr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('I',csr,asr,target);
|
1995-08-18 19:27:29 +04:00
|
|
|
if( asr & (SBIC_ASR_BSY|SBIC_ASR_LCI|SBIC_ASR_CIP) )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next: cmd sent asr %02x, csr %02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
asr, csr);
|
|
|
|
#endif
|
|
|
|
break;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
|
|
|
case SBIC_CSR_XFERRED|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_XFERRED|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|DATA_IN_PHASE:
|
|
|
|
if (acb->sc_kv.dc_count <= 0)
|
|
|
|
i = sbicabort(dev, regs, "icmd out of data");
|
|
|
|
else {
|
|
|
|
wait = sbic_data_wait;
|
|
|
|
if (sbicxfstart(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
SBIC_PHASE(csr), wait))
|
|
|
|
if (csr & 0x01)
|
|
|
|
/* data in? */
|
|
|
|
i=sbicxfin(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
acb->sc_kv.dc_addr);
|
|
|
|
else
|
|
|
|
i=sbicxfout(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
acb->sc_kv.dc_addr,
|
|
|
|
SBIC_PHASE(csr));
|
|
|
|
acb->sc_kv.dc_addr +=
|
|
|
|
(acb->sc_kv.dc_count - i);
|
|
|
|
acb->sc_kv.dc_count = i;
|
|
|
|
i = 1;
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
break;
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
case SBIC_CSR_XFERRED|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|STATUS_PHASE:
|
|
|
|
/*
|
|
|
|
* the sbic does the status/cmd-complete reading ok,
|
|
|
|
* so do this with its hi-level commands.
|
|
|
|
*/
|
1994-05-08 09:52:54 +04:00
|
|
|
#ifdef DEBUG
|
1995-08-18 19:27:29 +04:00
|
|
|
if(sbic_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("SBICICMD status phase\n");
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
SBIC_TC_PUT(regs, 0);
|
|
|
|
SET_SBIC_cmd_phase(regs, 0x46);
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN_XFER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if THIS_IS_A_RESERVED_STATE
|
|
|
|
case BUS_FREE_PHASE: /* This is not legal */
|
|
|
|
if( dev->sc_stat[0] != 0xff )
|
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
i = sbicnextstate(dev, csr, asr);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/*
|
|
|
|
* make sure the last command was taken,
|
|
|
|
* ie. we're not hunting after an ignored command..
|
|
|
|
*/
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
|
|
|
|
/* tapes may take a loooong time.. */
|
|
|
|
while (asr & SBIC_ASR_BSY){
|
|
|
|
if(asr & SBIC_ASR_DBR) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicicmd: Waiting while sbic is jammed, CSR:%02x,ASR:%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
csr,asr);
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
1994-05-08 09:52:54 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
/* SBIC is jammed */
|
|
|
|
/* DUNNO which direction */
|
|
|
|
/* Try old direction */
|
|
|
|
GET_SBIC_data(regs,i);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & SBIC_ASR_DBR) /* Wants us to write */
|
|
|
|
SET_SBIC_data(regs,i);
|
|
|
|
}
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* wait for last command to complete
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
if (asr & SBIC_ASR_LCI) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicicmd: last command ignored\n");
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
|
|
|
else if( i == 1 ) /* Bsy */
|
|
|
|
SBIC_WAIT (regs, SBIC_ASR_INT, wait);
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* do it again
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
} while ( i > 0 && dev->sc_stat[0] == 0xff);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Sometimes we need to do an extra read of the CSR */
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('I',csr,asr,0xff);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#if CSR_LOG_BUF_SIZE
|
|
|
|
if(reselect_debug>1)
|
|
|
|
for(i=0; i<bufptr; i++)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("CSR:%02x", csrbuf[i]);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug > 1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicicmd done(%d,%d):%d =%d=\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target, lun,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
dev->sc_stat[0]);
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
QPRINTF(("=STS:%02x=", dev->sc_stat[0]));
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_flags &= ~SBICF_ICMD;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
return(dev->sc_stat[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish SCSI xfer command: After the completion interrupt from
|
|
|
|
* a read/write operation, sequence through the final phases in
|
|
|
|
* programmed i/o. This routine is a lot like sbicicmd except we
|
|
|
|
* skip (and don't allow) the select, cmd out and data in/out phases.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbicxfdone(dev, regs, target)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int target;
|
|
|
|
{
|
1995-09-04 17:04:40 +04:00
|
|
|
u_char phase, asr, csr;
|
1994-05-08 09:52:54 +04:00
|
|
|
int s;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("{"));
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* have the sbic complete on its own
|
|
|
|
*/
|
|
|
|
SBIC_TC_PUT(regs, 0);
|
|
|
|
SET_SBIC_cmd_phase(regs, 0x46);
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN_XFER);
|
|
|
|
|
|
|
|
do {
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_csr (regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('f',csr,asr,target);
|
1994-05-08 09:52:54 +04:00
|
|
|
QPRINTF(("%02x:", csr));
|
|
|
|
} while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
|
|
|
|
&& (csr != SBIC_CSR_S_XFERRED));
|
|
|
|
|
|
|
|
dev->sc_flags &= ~SBICF_SELECTED;
|
|
|
|
|
|
|
|
GET_SBIC_cmd_phase (regs, phase);
|
|
|
|
QPRINTF(("}%02x", phase));
|
|
|
|
if (phase == 0x60)
|
|
|
|
GET_SBIC_tlun(regs, dev->sc_stat[0]);
|
|
|
|
else
|
|
|
|
sbicerror(dev, regs, csr);
|
|
|
|
|
|
|
|
QPRINTF(("=STS:%02x=\n", dev->sc_stat[0]));
|
|
|
|
splx(s);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/*
|
|
|
|
* No DMA chains
|
|
|
|
*/
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
int
|
|
|
|
sbicgo(dev, xs)
|
|
|
|
struct sbic_softc *dev;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
int i, dmaflags, count, usedma;
|
|
|
|
u_char csr, asr, *addr;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->target = xs->xs_periph->periph_target;
|
|
|
|
dev->lun = xs->xs_periph->periph_lun;
|
1995-08-18 19:27:29 +04:00
|
|
|
acb = dev->sc_nexus;
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
usedma = sbicdmaok(dev, xs);
|
|
|
|
#ifdef DEBUG
|
|
|
|
routine = 1;
|
|
|
|
debug_sbic_regs = regs; /* store this to allow debug calls */
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicgo(%d,%d)\n", dev->target, dev->lun);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* set the sbic into DMA mode
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
if( usedma )
|
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI |
|
|
|
|
SBIC_MACHINE_DMA_MODE);
|
|
|
|
else
|
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* select the SCSI bus (it's an error if bus isn't free)
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
if (sbicselectbus(dev, regs, dev->target, dev->lun,
|
1994-12-28 12:24:55 +03:00
|
|
|
dev->sc_scsiaddr)) {
|
1999-11-02 01:22:33 +03:00
|
|
|
/* printf("sbicgo: Trying to select busy bus!\n"); */
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return(0); /* Not done: needs to be rescheduled */
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_stat[0] = 0xff;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Calculate DMA chains now
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
dmaflags = 0;
|
|
|
|
if (acb->flags & ACB_DATAIN)
|
|
|
|
dmaflags |= DMAGO_READ;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Deal w/bounce buffers.
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
addr = acb->sc_kv.dc_addr;
|
|
|
|
count = acb->sc_kv.dc_count;
|
|
|
|
if (count && (char *)kvtop(addr) != acb->sc_pa.dc_addr) { /* XXXX check */
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbic: DMA buffer mapping changed %p->%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_pa.dc_addr, kvtop(addr));
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
++sbicdma_ops; /* count total DMA operations */
|
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
if (count && usedma && dev->sc_flags & SBICF_BADDMA &&
|
1994-05-08 09:52:54 +04:00
|
|
|
sbiccheckdmap(addr, count, dev->sc_dmamask)) {
|
|
|
|
/*
|
|
|
|
* need to bounce the dma.
|
|
|
|
*/
|
|
|
|
if (dmaflags & DMAGO_READ) {
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->flags |= ACB_BBUF;
|
|
|
|
acb->sc_dmausrbuf = addr;
|
|
|
|
acb->sc_dmausrlen = count;
|
|
|
|
acb->sc_usrbufpa = (u_char *)kvtop(addr);
|
|
|
|
if(!dev->sc_tinfo[dev->target].bounce) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicgo: HELP! no bounce allocated for %d\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("xfer: (%p->%p,%lx)\n", acb->sc_dmausrbuf,
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_usrbufpa, acb->sc_dmausrlen);
|
2001-04-25 21:53:04 +04:00
|
|
|
dev->sc_tinfo[xs->xs_periph->periph_target].bounce
|
1995-08-18 19:27:29 +04:00
|
|
|
= (char *)alloc_z2mem(MAXPHYS);
|
2001-04-25 21:53:04 +04:00
|
|
|
if (isztwomem(dev->sc_tinfo[xs->xs_periph->periph_target].bounce))
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("alloc ZII target %d bounce pa 0x%x\n",
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
|
|
|
kvtop(dev->sc_tinfo[xs->xs_periph->periph_target].bounce));
|
|
|
|
else if (dev->sc_tinfo[xs->xs_periph->periph_target].bounce)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("alloc CHIP target %d bounce pa 0x%p\n",
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
|
|
|
PREP_DMA_MEM(dev->sc_tinfo[xs->xs_periph->periph_target].bounce));
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Allocating %d bounce at %x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target,
|
|
|
|
kvtop(dev->sc_tinfo[dev->target].bounce));
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
} else { /* write: copy to dma buffer */
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicgo: copying %x bytes to target %d bounce %x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
count, dev->target,
|
|
|
|
kvtop(dev->sc_tinfo[dev->target].bounce));
|
|
|
|
#endif
|
|
|
|
bcopy (addr, dev->sc_tinfo[dev->target].bounce, count);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
addr = dev->sc_tinfo[dev->target].bounce;/* and use dma buffer */
|
|
|
|
acb->sc_kv.dc_addr = addr;
|
1995-02-12 22:18:33 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
++sbicdma_bounces; /* count number of bounced */
|
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* Allocate the DMA chain
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Set start KVM addresses */
|
|
|
|
#if 0
|
|
|
|
acb->sc_kv.dc_addr = addr;
|
|
|
|
acb->sc_kv.dc_count = count;
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Mark end of segment */
|
|
|
|
acb->sc_tcnt = dev->sc_tcnt = 0;
|
|
|
|
acb->sc_pa.dc_count = 0;
|
|
|
|
|
|
|
|
sbic_load_ptrs(dev, regs, dev->target, dev->lun);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Enable interrupts but don't do any DMA */
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_enintr(dev);
|
|
|
|
if (usedma) {
|
|
|
|
dev->sc_tcnt = dev->sc_dmago(dev, acb->sc_pa.dc_addr,
|
|
|
|
acb->sc_pa.dc_count,
|
|
|
|
dmaflags);
|
|
|
|
#ifdef DEBUG
|
1995-10-05 15:36:07 +03:00
|
|
|
dev->sc_dmatimo = dev->sc_tcnt ? 1 : 0;
|
1995-09-04 17:04:40 +04:00
|
|
|
#endif
|
|
|
|
} else
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dmacmd = 0; /* Don't use DMA */
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_flags |= SBICF_INDMA;
|
1996-04-22 01:10:48 +04:00
|
|
|
/* SBIC_TC_PUT(regs, dev->sc_tcnt); */ /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
sbic_save_ptrs(dev, regs, dev->target, dev->lun);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* push the data cache ( I think this won't work (EH))
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1996-06-10 20:11:20 +04:00
|
|
|
#if defined(M68040) || defined(M68060)
|
1995-08-18 19:27:29 +04:00
|
|
|
if (mmutype == MMU_68040 && usedma && count) {
|
|
|
|
dma_cachectl(addr, count);
|
|
|
|
if (((u_int)addr & 0xF) || (((u_int)addr + count) & 0xF))
|
1994-06-20 06:23:12 +04:00
|
|
|
dev->sc_flags |= SBICF_DCFLUSH;
|
|
|
|
}
|
1994-06-14 04:58:05 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
1995-09-04 17:04:40 +04:00
|
|
|
* enintr() also enables interrupts for the sbic
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicgo dmago:%d(%p:%lx)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target,dev->sc_cur->dc_addr,dev->sc_tcnt);
|
1996-05-01 20:58:41 +04:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Hmm - this isn't right: asr and csr haven't been set yet.
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
debug_asr = asr;
|
|
|
|
debug_csr = csr;
|
1996-05-01 20:58:41 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/*
|
|
|
|
* Lets cycle a while then let the interrupt handler take over
|
|
|
|
*/
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = GET_SBIC_asr(regs, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
do {
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('g',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug_csr = csr;
|
|
|
|
routine = 1;
|
|
|
|
#endif
|
|
|
|
QPRINTF(("go[0x%x]", csr));
|
|
|
|
|
|
|
|
i = sbicnextstate(dev, csr, asr);
|
|
|
|
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_asr = asr;
|
|
|
|
#endif
|
1996-10-13 07:05:43 +04:00
|
|
|
if(asr & SBIC_ASR_LCI) printf("sbicgo: LCI asr:%02x csr:%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
asr,csr);
|
|
|
|
} while( i == SBIC_STATE_RUNNING
|
|
|
|
&& asr & (SBIC_ASR_INT|SBIC_ASR_LCI) );
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('g',csr,asr,i<<4);
|
|
|
|
SBIC_TRACE(dev);
|
1996-10-13 07:05:43 +04:00
|
|
|
if (i == SBIC_STATE_DONE && dev->sc_stat[0] == 0xff) printf("sbicgo: done & stat = 0xff\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
if (i == SBIC_STATE_DONE && dev->sc_stat[0] != 0xff) {
|
|
|
|
/* if( i == SBIC_STATE_DONE && dev->sc_stat[0] ) { */
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Did we really finish that fast? */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicintr(dev)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1996-04-22 01:10:48 +04:00
|
|
|
u_char asr, csr;
|
|
|
|
int i;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pending interrupt?
|
|
|
|
*/
|
|
|
|
GET_SBIC_asr (regs, asr);
|
|
|
|
if ((asr & SBIC_ASR_INT) == 0)
|
|
|
|
return(0);
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
do {
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('i',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug_csr = csr;
|
|
|
|
routine = 2;
|
|
|
|
#endif
|
|
|
|
QPRINTF(("intr[0x%x]", csr));
|
|
|
|
|
|
|
|
i = sbicnextstate(dev, csr, asr);
|
|
|
|
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_asr = asr;
|
|
|
|
#endif
|
|
|
|
#if 0
|
1996-10-13 07:05:43 +04:00
|
|
|
if(asr & SBIC_ASR_LCI) printf("sbicintr: LCI asr:%02x csr:%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
asr,csr);
|
|
|
|
#endif
|
|
|
|
} while(i == SBIC_STATE_RUNNING &&
|
|
|
|
asr & (SBIC_ASR_INT|SBIC_ASR_LCI));
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('i',csr,asr,i<<4);
|
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run commands and wait for disconnect
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbicpoll(dev)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
u_char asr, csr;
|
|
|
|
int i;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
GET_SBIC_asr (regs, asr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_asr = asr;
|
|
|
|
#endif
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('p',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug_csr = csr;
|
|
|
|
routine = 2;
|
|
|
|
#endif
|
|
|
|
QPRINTF(("poll[0x%x]", csr));
|
|
|
|
|
|
|
|
i = sbicnextstate(dev, csr, asr);
|
|
|
|
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
/* tapes may take a loooong time.. */
|
|
|
|
while (asr & SBIC_ASR_BSY){
|
|
|
|
if(asr & SBIC_ASR_DBR) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbipoll: Waiting while sbic is jammed, CSR:%02x,ASR:%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
csr,asr);
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
/* SBIC is jammed */
|
|
|
|
/* DUNNO which direction */
|
|
|
|
/* Try old direction */
|
|
|
|
GET_SBIC_data(regs,i);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & SBIC_ASR_DBR) /* Wants us to write */
|
|
|
|
SET_SBIC_data(regs,i);
|
|
|
|
}
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
}
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
if(asr & SBIC_ASR_LCI) printf("sbicpoll: LCI asr:%02x csr:%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
asr,csr);
|
|
|
|
else if( i == 1 ) /* BSY */
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, sbic_cmd_wait);
|
|
|
|
} while(i == SBIC_STATE_RUNNING);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('p',csr,asr,i<<4);
|
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a single msgin
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sbicmsgin(dev)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
int recvlen;
|
|
|
|
u_char asr, csr, *tmpaddr;
|
|
|
|
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
|
|
|
|
dev->sc_msg[0] = 0xff;
|
|
|
|
dev->sc_msg[1] = 0xff;
|
|
|
|
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(reselect_debug>1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicmsgin asr=%02x\n", asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sbic_save_ptrs(dev, regs, dev->target, dev->lun);
|
|
|
|
|
|
|
|
GET_SBIC_selid (regs, csr);
|
|
|
|
SET_SBIC_selid (regs, csr | SBIC_SID_FROM_SCSI);
|
|
|
|
|
|
|
|
SBIC_TC_PUT(regs, 0);
|
|
|
|
tmpaddr = dev->sc_msg;
|
|
|
|
recvlen = 1;
|
|
|
|
do {
|
|
|
|
while( recvlen-- ) {
|
1995-09-04 17:04:40 +04:00
|
|
|
asr = GET_SBIC_asr(regs, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
GET_SBIC_csr(regs, csr);
|
|
|
|
QPRINTF(("sbicmsgin ready to go (csr,asr)=(%02x,%02x)\n",
|
|
|
|
csr, asr));
|
|
|
|
|
|
|
|
RECV_BYTE(regs, *tmpaddr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('m',csr,asr,*tmpaddr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
* get the command completion interrupt, or we
|
|
|
|
* can't send a new command (LCI)
|
|
|
|
*/
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('X',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
#else
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
do {
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
csr = 0xff;
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('X',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
if( csr == 0xff )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicmsgin waiting: csr %02x asr %02x\n", csr, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
} while( csr == 0xff );
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(reselect_debug>1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicmsgin: got %02x csr %02x asr %02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
*tmpaddr, csr, asr);
|
|
|
|
#endif
|
|
|
|
#if do_parity_check
|
|
|
|
if( asr & SBIC_ASR_PE ) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("Parity error");
|
1995-08-18 19:27:29 +04:00
|
|
|
/* This code simply does not work. */
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
if( !(asr & SBIC_ASR_LCI) )
|
|
|
|
/* Target wants to send garbled msg*/
|
|
|
|
continue;
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("--fixing\n");
|
1995-08-18 19:27:29 +04:00
|
|
|
/* loop until a msgout phase occurs on target */
|
|
|
|
while(csr & 0x07 != MESG_OUT_PHASE) {
|
|
|
|
while( asr & SBIC_ASR_BSY &&
|
|
|
|
!(asr & SBIC_ASR_DBR|SBIC_ASR_INT) )
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if( asr & SBIC_ASR_DBR )
|
|
|
|
panic("msgin: jammed again!\n");
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('e',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
if( csr & 0x07 != MESG_OUT_PHASE ) {
|
|
|
|
sbicnextstate(dev, csr, asr);
|
|
|
|
sbic_save_ptrs(dev, regs,
|
|
|
|
dev->target,
|
|
|
|
dev->lun);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Should be msg out by now */
|
|
|
|
SEND_BYTE(regs, MSG_PARITY_ERROR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
tmpaddr++;
|
|
|
|
|
|
|
|
if(recvlen) {
|
|
|
|
/* Clear ACK */
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('X',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
QPRINTF(("sbicmsgin pre byte CLR_ACK (csr,asr)=(%02x,%02x)\n",
|
|
|
|
csr, asr));
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if(dev->sc_msg[0] == 0xff) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicmsgin: sbic swallowed our message\n");
|
1995-08-18 19:27:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("msgin done csr 0x%x asr 0x%x msg 0x%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
csr, asr, dev->sc_msg[0]);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* test whether this is a reply to our sync
|
|
|
|
* request
|
|
|
|
*/
|
|
|
|
if (MSG_ISIDENTIFY(dev->sc_msg[0])) {
|
|
|
|
QPRINTF(("IFFY"));
|
|
|
|
#if 0
|
|
|
|
/* There is an implied load-ptrs here */
|
|
|
|
sbic_load_ptrs(dev, regs, dev->target, dev->lun);
|
|
|
|
#endif
|
|
|
|
/* Got IFFY msg -- ack it */
|
|
|
|
} else if (dev->sc_msg[0] == MSG_REJECT
|
|
|
|
&& dev->sc_sync[dev->target].state == SYNC_SENT) {
|
|
|
|
QPRINTF(("REJECT of SYN"));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("target %d rejected sync, going async\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target);
|
|
|
|
#endif
|
|
|
|
dev->sc_sync[dev->target].period = sbic_min_period;
|
|
|
|
dev->sc_sync[dev->target].offset = 0;
|
|
|
|
dev->sc_sync[dev->target].state = SYNC_DONE;
|
|
|
|
SET_SBIC_syn(regs,
|
|
|
|
SBIC_SYN(dev->sc_sync[dev->target].offset,
|
|
|
|
dev->sc_sync[dev->target].period));
|
|
|
|
} else if ((dev->sc_msg[0] == MSG_REJECT)) {
|
|
|
|
QPRINTF(("REJECT"));
|
|
|
|
/*
|
|
|
|
* we'll never REJECt a REJECT message..
|
|
|
|
*/
|
|
|
|
} else if ((dev->sc_msg[0] == MSG_SAVE_DATA_PTR)) {
|
|
|
|
QPRINTF(("MSG_SAVE_DATA_PTR"));
|
|
|
|
/*
|
|
|
|
* don't reject this either.
|
|
|
|
*/
|
|
|
|
} else if ((dev->sc_msg[0] == MSG_DISCONNECT)) {
|
|
|
|
QPRINTF(("DISCONNECT"));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( reselect_debug>1 && dev->sc_msg[0] == MSG_DISCONNECT )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicmsgin: got disconnect msg %s\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
(dev->sc_flags & SBICF_ICMD)?"rejecting":"");
|
|
|
|
#endif
|
|
|
|
if( dev->sc_flags & SBICF_ICMD ) {
|
|
|
|
/* We're in immediate mode. Prevent disconnects. */
|
|
|
|
/* prepare to reject the message, NACK */
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
}
|
|
|
|
} else if (dev->sc_msg[0] == MSG_CMD_COMPLETE ) {
|
|
|
|
QPRINTF(("CMD_COMPLETE"));
|
|
|
|
/* !! KLUDGE ALERT !! quite a few drives don't seem to
|
|
|
|
* really like the current way of sending the
|
|
|
|
* sync-handshake together with the ident-message, and
|
|
|
|
* they react by sending command-complete and
|
|
|
|
* disconnecting right after returning the valid sync
|
|
|
|
* handshake. So, all I can do is reselect the drive,
|
|
|
|
* and hope it won't disconnect again. I don't think
|
|
|
|
* this is valid behavior, but I can't help fixing a
|
|
|
|
* problem that apparently exists.
|
|
|
|
*
|
|
|
|
* Note: we should not get here on `normal' command
|
|
|
|
* completion, as that condition is handled by the
|
|
|
|
* high-level sel&xfer resume command used to walk
|
|
|
|
* thru status/cc-phase.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("GOT MSG %d! target %d acting weird.."
|
1995-08-18 19:27:29 +04:00
|
|
|
" waiting for disconnect...\n",
|
|
|
|
dev->sc_msg[0], dev->target);
|
|
|
|
#endif
|
|
|
|
/* Check to see if sbic is handling this */
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if(asr & SBIC_ASR_BSY)
|
|
|
|
return SBIC_STATE_RUNNING;
|
|
|
|
|
|
|
|
/* Let's try this: Assume it works and set status to 00 */
|
|
|
|
dev->sc_stat[0] = 0;
|
|
|
|
} else if (dev->sc_msg[0] == MSG_EXT_MESSAGE
|
|
|
|
&& tmpaddr == &dev->sc_msg[1]) {
|
|
|
|
QPRINTF(("ExtMSG\n"));
|
|
|
|
/* Read in whole extended message */
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
GET_SBIC_csr(regs, csr);
|
|
|
|
QPRINTF(("CLR ACK asr %02x, csr %02x\n", asr, csr));
|
|
|
|
RECV_BYTE(regs, *tmpaddr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('x',csr,asr,*tmpaddr);
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Wait for command completion IRQ */
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
recvlen = *tmpaddr++;
|
|
|
|
QPRINTF(("Recving ext msg, asr %02x csr %02x len %02x\n",
|
|
|
|
asr, csr, recvlen));
|
|
|
|
} else if (dev->sc_msg[0] == MSG_EXT_MESSAGE && dev->sc_msg[1] == 3
|
|
|
|
&& dev->sc_msg[2] == MSG_SYNC_REQ) {
|
|
|
|
QPRINTF(("SYN"));
|
|
|
|
dev->sc_sync[dev->target].period =
|
|
|
|
sbicfromscsiperiod(dev,
|
|
|
|
regs, dev->sc_msg[3]);
|
|
|
|
dev->sc_sync[dev->target].offset = dev->sc_msg[4];
|
|
|
|
dev->sc_sync[dev->target].state = SYNC_DONE;
|
|
|
|
SET_SBIC_syn(regs,
|
|
|
|
SBIC_SYN(dev->sc_sync[dev->target].offset,
|
|
|
|
dev->sc_sync[dev->target].period));
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: target %d now synchronous,"
|
1995-08-18 19:27:29 +04:00
|
|
|
" period=%dns, offset=%d.\n",
|
|
|
|
dev->sc_dev.dv_xname, dev->target,
|
|
|
|
dev->sc_msg[3] * 4, dev->sc_msg[4]);
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sbic_debug || sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("sbicmsgin: Rejecting message 0x%02x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_msg[0]);
|
|
|
|
#endif
|
|
|
|
/* prepare to reject the message, NACK */
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
}
|
|
|
|
/* Clear ACK */
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
GET_SBIC_csr(regs, csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('X',csr,asr,dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
QPRINTF(("sbicmsgin pre CLR_ACK (csr,asr)=(%02x,%02x)%d\n",
|
|
|
|
csr, asr, recvlen));
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
|
|
|
|
SBIC_WAIT(regs, SBIC_ASR_INT, 0);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
while((csr == SBIC_CSR_MSGIN_W_ACK)
|
|
|
|
|| (SBIC_PHASE(csr) == MESG_IN_PHASE));
|
|
|
|
#else
|
|
|
|
while (recvlen>0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QPRINTF(("sbicmsgin finished: csr %02x, asr %02x\n",csr, asr));
|
|
|
|
|
|
|
|
/* Should still have one CSR to read */
|
|
|
|
return SBIC_STATE_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sbicnextstate()
|
|
|
|
* return:
|
|
|
|
* 0 == done
|
|
|
|
* 1 == working
|
|
|
|
* 2 == disconnected
|
|
|
|
* -1 == error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbicnextstate(dev, csr, asr)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
u_char csr, asr;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_acb *acb;
|
|
|
|
int i, newtarget, newlun, wait;
|
1996-04-22 01:10:48 +04:00
|
|
|
#if 0
|
1995-08-18 19:27:29 +04:00
|
|
|
unsigned tcnt;
|
1996-04-22 01:10:48 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
i = 0;
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-08-18 19:27:29 +04:00
|
|
|
acb = dev->sc_nexus;
|
|
|
|
|
|
|
|
QPRINTF(("next[%02x,%02x]",asr,csr));
|
|
|
|
|
|
|
|
switch (csr) {
|
|
|
|
case SBIC_CSR_XFERRED|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|CMD_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|CMD_PHASE:
|
|
|
|
sbic_save_ptrs(dev, regs, dev->target, dev->lun);
|
|
|
|
if (sbicxfstart(regs, acb->clen, CMD_PHASE, sbic_cmd_wait))
|
|
|
|
if (sbicxfout(regs, acb->clen,
|
|
|
|
&acb->cmd, CMD_PHASE))
|
|
|
|
goto abort;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SBIC_CSR_XFERRED|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|STATUS_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|STATUS_PHASE:
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* this should be the normal i/o completion case.
|
|
|
|
* get the status & cmd complete msg then let the
|
|
|
|
* device driver look at what happened.
|
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicxfdone(dev,regs,dev->target);
|
1994-06-14 04:58:05 +04:00
|
|
|
/*
|
|
|
|
* check for overlapping cache line, flush if so
|
|
|
|
*/
|
1996-06-10 20:11:20 +04:00
|
|
|
#if defined(M68040) || defined(M68060)
|
1994-06-14 04:58:05 +04:00
|
|
|
if (dev->sc_flags & SBICF_DCFLUSH) {
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbic: 68040/68060 DMA cache flush needs"
|
1996-06-10 20:11:20 +04:00
|
|
|
"fixing? %x:%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_xs->data, dev->sc_xs->datalen);
|
|
|
|
#endif
|
1994-06-14 04:58:05 +04:00
|
|
|
}
|
1994-06-15 23:05:55 +04:00
|
|
|
#endif
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next dmastop: %d(%p:%lx)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target,dev->sc_cur->dc_addr,dev->sc_tcnt);
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_dmatimo = 0;
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
dev->sc_dmastop(dev); /* was dmafree */
|
|
|
|
if (acb->flags & ACB_BBUF) {
|
|
|
|
if ((u_char *)kvtop(acb->sc_dmausrbuf) != acb->sc_usrbufpa)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: WARNING - buffer mapping changed %p->%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dev.dv_xname, acb->sc_usrbufpa,
|
|
|
|
kvtop(acb->sc_dmausrbuf));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(data_pointer_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicgo:copying %lx bytes from target %d bounce %x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_dmausrlen,
|
|
|
|
dev->target,
|
|
|
|
kvtop(dev->sc_tinfo[dev->target].bounce));
|
|
|
|
#endif
|
|
|
|
bcopy(dev->sc_tinfo[dev->target].bounce,
|
|
|
|
acb->sc_dmausrbuf,
|
|
|
|
acb->sc_dmausrlen);
|
|
|
|
}
|
|
|
|
dev->sc_flags &= ~(SBICF_INDMA | SBICF_DCFLUSH);
|
|
|
|
sbic_scsidone(acb, dev->sc_stat[0]);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return SBIC_STATE_DONE;
|
|
|
|
|
|
|
|
case SBIC_CSR_XFERRED|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_XFERRED|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|DATA_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|DATA_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|DATA_IN_PHASE:
|
1999-10-01 02:59:52 +04:00
|
|
|
if( dev->sc_xs->xs_control & XS_CTL_POLL || dev->sc_flags & SBICF_ICMD
|
1995-08-18 19:27:29 +04:00
|
|
|
|| acb->sc_dmacmd == 0 ) {
|
|
|
|
/* Do PIO */
|
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
|
|
|
|
if (acb->sc_kv.dc_count <= 0) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicnextstate:xfer count %d asr%x csr%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_kv.dc_count, asr, csr);
|
|
|
|
goto abort;
|
1995-03-02 05:23:50 +03:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
wait = sbic_data_wait;
|
|
|
|
if( sbicxfstart(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
1998-11-05 17:13:59 +03:00
|
|
|
SBIC_PHASE(csr), wait)) {
|
1995-08-18 19:27:29 +04:00
|
|
|
if( SBIC_PHASE(csr) == DATA_IN_PHASE )
|
|
|
|
/* data in? */
|
|
|
|
i=sbicxfin(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
acb->sc_kv.dc_addr);
|
|
|
|
else
|
|
|
|
i=sbicxfout(regs,
|
|
|
|
acb->sc_kv.dc_count,
|
|
|
|
acb->sc_kv.dc_addr,
|
|
|
|
SBIC_PHASE(csr));
|
1998-11-05 17:13:59 +03:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
acb->sc_kv.dc_addr +=
|
|
|
|
(acb->sc_kv.dc_count - i);
|
|
|
|
acb->sc_kv.dc_count = i;
|
|
|
|
} else {
|
1995-09-04 17:04:40 +04:00
|
|
|
if (acb->sc_kv.dc_count <= 0) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicnextstate:xfer count %d asr%x csr%x\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
acb->sc_kv.dc_count, asr, csr);
|
|
|
|
goto abort;
|
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
/*
|
|
|
|
* do scatter-gather dma
|
|
|
|
* hacking the controller chip, ouch..
|
|
|
|
*/
|
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI |
|
|
|
|
SBIC_MACHINE_DMA_MODE);
|
|
|
|
/*
|
|
|
|
* set next dma addr and dec count
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
SBIC_TC_GET(regs, tcnt);
|
|
|
|
dev->sc_cur->dc_count -= ((dev->sc_tcnt - tcnt) >> 1);
|
|
|
|
dev->sc_cur->dc_addr += (dev->sc_tcnt - tcnt);
|
|
|
|
dev->sc_tcnt = acb->sc_tcnt = tcnt;
|
|
|
|
#else
|
|
|
|
sbic_save_ptrs(dev, regs, dev->target, dev->lun);
|
|
|
|
sbic_load_ptrs(dev, regs, dev->target, dev->lun);
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next dmanext: %d(%p:%lx)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target,dev->sc_cur->dc_addr,
|
|
|
|
dev->sc_tcnt);
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_dmatimo = 1;
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
dev->sc_tcnt = dev->sc_dmanext(dev);
|
|
|
|
SBIC_TC_PUT(regs, (unsigned)dev->sc_tcnt);
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_XFER_INFO);
|
|
|
|
dev->sc_flags |= SBICF_INDMA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SBIC_CSR_XFERRED|MESG_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS|MESG_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|MESG_IN_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|MESG_IN_PHASE:
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return sbicmsgin(dev);
|
|
|
|
|
|
|
|
case SBIC_CSR_MSGIN_W_ACK:
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK); /* Dunno what I'm ACKing */
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Acking unknown msgin CSR:%02x",csr);
|
1995-08-18 19:27:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SBIC_CSR_XFERRED|MESG_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS|MESG_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_1|MESG_OUT_PHASE:
|
|
|
|
case SBIC_CSR_MIS_2|MESG_OUT_PHASE:
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (sync_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("sending REJECT msg to last msg.\n");
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sbic_save_ptrs(dev, regs, dev->target, dev->lun);
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
1995-08-18 19:27:29 +04:00
|
|
|
* should only get here on reject,
|
|
|
|
* since it's always US that
|
|
|
|
* initiate a sync transfer
|
1994-05-08 09:52:54 +04:00
|
|
|
*/
|
1995-08-18 19:27:29 +04:00
|
|
|
SEND_BYTE(regs, MSG_REJECT);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
if( asr & (SBIC_ASR_BSY|SBIC_ASR_LCI|SBIC_ASR_CIP) )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next: REJECT sent asr %02x\n", asr);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return SBIC_STATE_RUNNING;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
case SBIC_CSR_DISC:
|
|
|
|
case SBIC_CSR_DISC_1:
|
|
|
|
dev->sc_flags &= ~(SBICF_INDMA|SBICF_SELECTED);
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
/* Try to schedule another target */
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(reselect_debug>1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicnext target %d disconnected\n", dev->target);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
TAILQ_INSERT_HEAD(&dev->nexus_list, acb, chain);
|
|
|
|
++dev->sc_tinfo[dev->target].dconns;
|
|
|
|
dev->sc_nexus = NULL;
|
|
|
|
dev->sc_xs = NULL;
|
|
|
|
|
1999-10-01 02:59:52 +04:00
|
|
|
if( acb->xs->xs_control & XS_CTL_POLL
|
1995-08-18 19:27:29 +04:00
|
|
|
|| (dev->sc_flags & SBICF_ICMD)
|
1995-09-04 17:04:40 +04:00
|
|
|
|| !sbic_parallel_operations ) {
|
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return SBIC_STATE_DISCONNECT;
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
sbic_sched(dev);
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return SBIC_STATE_DISCONNECT;
|
|
|
|
|
|
|
|
case SBIC_CSR_RSLT_NI:
|
|
|
|
case SBIC_CSR_RSLT_IFY:
|
|
|
|
GET_SBIC_rselid(regs, newtarget);
|
|
|
|
/* check SBIC_RID_SIV? */
|
|
|
|
newtarget &= SBIC_RID_MASK;
|
|
|
|
if (csr == SBIC_CSR_RSLT_IFY) {
|
|
|
|
/* Read IFY msg to avoid lockup */
|
|
|
|
GET_SBIC_data(regs, newlun);
|
|
|
|
WAIT_CIP(regs);
|
|
|
|
newlun &= SBIC_TLUN_MASK;
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('r',csr,asr,newtarget);
|
1995-08-18 19:27:29 +04:00
|
|
|
} else {
|
|
|
|
/* Need to get IFY message */
|
|
|
|
for (newlun = 256; newlun; --newlun) {
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if (asr & SBIC_ASR_INT)
|
|
|
|
break;
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
newlun = 0; /* XXXX */
|
|
|
|
if ((asr & SBIC_ASR_INT) == 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (reselect_debug)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("RSLT_NI - no IFFY message? asr %x\n", asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
GET_SBIC_csr(regs,csr);
|
1995-09-04 17:04:40 +04:00
|
|
|
CSR_TRACE('n',csr,asr,newtarget);
|
1996-04-22 01:10:48 +04:00
|
|
|
if (csr == (SBIC_CSR_MIS | MESG_IN_PHASE) ||
|
|
|
|
csr == (SBIC_CSR_MIS_1 | MESG_IN_PHASE) ||
|
|
|
|
csr == (SBIC_CSR_MIS_2 | MESG_IN_PHASE)) {
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicmsgin(dev);
|
|
|
|
newlun = dev->sc_msg[0] & 7;
|
|
|
|
} else {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("RSLT_NI - not MESG_IN_PHASE %x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
csr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(reselect_debug>1 || (reselect_debug && csr==SBIC_CSR_RSLT_NI))
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicnext: reselect %s from targ %d lun %d\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY",
|
|
|
|
newtarget, newlun);
|
|
|
|
#endif
|
|
|
|
if (dev->sc_nexus) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (reselect_debug > 1)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: reselect %s with active command\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dev.dv_xname,
|
|
|
|
csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY");
|
|
|
|
#ifdef DDB
|
|
|
|
/* Debugger();*/
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
TAILQ_INSERT_HEAD(&dev->ready_list, dev->sc_nexus, chain);
|
|
|
|
dev->sc_tinfo[dev->target].lubusy &= ~(1 << dev->lun);
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_nexus = NULL;
|
|
|
|
dev->sc_xs = NULL;
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
1995-08-24 19:46:19 +04:00
|
|
|
/* Reload sync values for this target */
|
|
|
|
if (dev->sc_sync[newtarget].state == SYNC_DONE)
|
|
|
|
SET_SBIC_syn(regs, SBIC_SYN (dev->sc_sync[newtarget].offset,
|
|
|
|
dev->sc_sync[newtarget].period));
|
|
|
|
else
|
|
|
|
SET_SBIC_syn(regs, SBIC_SYN (0, sbic_min_period));
|
1995-08-18 19:27:29 +04:00
|
|
|
for (acb = dev->nexus_list.tqh_first; acb;
|
|
|
|
acb = acb->chain.tqe_next) {
|
2001-04-25 21:53:04 +04:00
|
|
|
if (acb->xs->xs_periph->periph_target != newtarget ||
|
|
|
|
acb->xs->xs_periph->periph_lun != newlun)
|
1995-08-18 19:27:29 +04:00
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&dev->nexus_list, acb, chain);
|
|
|
|
dev->sc_nexus = acb;
|
|
|
|
dev->sc_xs = acb->xs;
|
|
|
|
dev->sc_flags |= SBICF_SELECTED;
|
|
|
|
dev->target = newtarget;
|
|
|
|
dev->lun = newlun;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (acb == NULL) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: reselect %s targ %d not in nexus_list %p\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_dev.dv_xname,
|
|
|
|
csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY", newtarget,
|
|
|
|
&dev->nexus_list.tqh_first);
|
|
|
|
panic("bad reselect in sbic");
|
|
|
|
}
|
|
|
|
if (csr == SBIC_CSR_RSLT_IFY)
|
|
|
|
SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort:
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* Something unexpected happened -- deal with it.
|
|
|
|
*/
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbicnextstate: aborting csr %02x asr %02x\n", csr, asr);
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next dmastop: %d(%p:%lx)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->target,dev->sc_cur->dc_addr,dev->sc_tcnt);
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_dmatimo = 0;
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
dev->sc_dmastop(dev);
|
1995-09-04 17:04:40 +04:00
|
|
|
SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
|
1994-05-08 09:52:54 +04:00
|
|
|
sbicerror(dev, regs, csr);
|
1995-08-18 19:27:29 +04:00
|
|
|
sbicabort(dev, regs, "next");
|
1994-05-08 09:52:54 +04:00
|
|
|
if (dev->sc_flags & SBICF_INDMA) {
|
1994-06-14 04:58:05 +04:00
|
|
|
/*
|
|
|
|
* check for overlapping cache line, flush if so
|
|
|
|
*/
|
1996-06-10 20:11:20 +04:00
|
|
|
#if defined(M68040) || defined(M68060)
|
1994-06-14 04:58:05 +04:00
|
|
|
if (dev->sc_flags & SBICF_DCFLUSH) {
|
1995-08-18 19:27:29 +04:00
|
|
|
#if 0
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sbic: 68040/060 DMA cache flush needs"
|
1996-06-10 20:11:20 +04:00
|
|
|
"fixing? %x:%x\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
dev->sc_xs->data, dev->sc_xs->datalen);
|
|
|
|
#endif
|
1994-06-14 04:58:05 +04:00
|
|
|
}
|
1994-06-15 23:05:55 +04:00
|
|
|
#endif
|
1995-08-13 00:30:45 +04:00
|
|
|
dev->sc_flags &=
|
1995-08-18 19:27:29 +04:00
|
|
|
~(SBICF_INDMA | SBICF_DCFLUSH);
|
|
|
|
#ifdef DEBUG
|
1995-09-04 17:04:40 +04:00
|
|
|
if( data_pointer_debug > 1 )
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("next dmastop: %d(%p:%lx)\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->target,dev->sc_cur->dc_addr,dev->sc_tcnt);
|
|
|
|
dev->sc_dmatimo = 0;
|
1995-08-18 19:27:29 +04:00
|
|
|
#endif
|
|
|
|
dev->sc_dmastop(dev);
|
|
|
|
sbic_scsidone(acb, -1);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return SBIC_STATE_ERROR;
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
SBIC_TRACE(dev);
|
1995-08-18 19:27:29 +04:00
|
|
|
return(SBIC_STATE_RUNNING);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* Check if DMA can not be used with specified buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sbiccheckdmap(bp, len, mask)
|
|
|
|
void *bp;
|
|
|
|
u_long len, mask;
|
|
|
|
{
|
|
|
|
u_char *buffer;
|
|
|
|
u_long phy_buf;
|
|
|
|
u_long phy_len;
|
|
|
|
|
|
|
|
buffer = bp;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
phy_buf = kvtop(buffer);
|
|
|
|
if (len < (phy_len = NBPG - ((int) buffer & PGOFSET)))
|
|
|
|
phy_len = len;
|
|
|
|
if (phy_buf & mask)
|
|
|
|
return(1);
|
|
|
|
buffer += phy_len;
|
|
|
|
len -= phy_len;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
int
|
1994-05-08 09:52:54 +04:00
|
|
|
sbictoscsiperiod(dev, regs, a)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int a;
|
|
|
|
{
|
|
|
|
unsigned int fs;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*
|
|
|
|
* cycle = DIV / (2*CLK)
|
|
|
|
* DIV = FS+2
|
|
|
|
* best we can do is 200ns at 20Mhz, 2 cycles
|
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_myid(regs,fs);
|
|
|
|
fs = (fs >>6) + 2; /* DIV */
|
|
|
|
fs = (fs * 10000) / (dev->sc_clkfreq<<1); /* Cycle, in ns */
|
|
|
|
if (a < 2) a = 8; /* map to Cycles */
|
|
|
|
return ((fs*a)>>2); /* in 4 ns units */
|
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
int
|
1994-05-08 09:52:54 +04:00
|
|
|
sbicfromscsiperiod(dev, regs, p)
|
|
|
|
struct sbic_softc *dev;
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1994-05-08 09:52:54 +04:00
|
|
|
int p;
|
|
|
|
{
|
|
|
|
register unsigned int fs, ret;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/* Just the inverse of the above */
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
GET_SBIC_myid(regs,fs);
|
|
|
|
fs = (fs >>6) + 2; /* DIV */
|
|
|
|
fs = (fs * 10000) / (dev->sc_clkfreq<<1); /* Cycle, in ns */
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
ret = p << 2; /* in ns units */
|
|
|
|
ret = ret / fs; /* in Cycles */
|
|
|
|
if (ret < sbic_min_period)
|
|
|
|
return(sbic_min_period);
|
|
|
|
|
|
|
|
/* verify rounding */
|
|
|
|
if (sbictoscsiperiod(dev, regs, ret) < p)
|
|
|
|
ret++;
|
|
|
|
return (ret >= 8) ? 0 : ret;
|
|
|
|
}
|
|
|
|
|
1995-08-18 19:27:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
|
|
|
sbicdumpstate()
|
1995-08-18 19:27:29 +04:00
|
|
|
{
|
|
|
|
u_char csr, asr;
|
|
|
|
|
|
|
|
GET_SBIC_asr(debug_sbic_regs,asr);
|
|
|
|
GET_SBIC_csr(debug_sbic_regs,csr);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: asr:csr(%02x:%02x)->(%02x:%02x)\n",
|
1995-08-18 19:27:29 +04:00
|
|
|
(routine==1)?"sbicgo":
|
|
|
|
(routine==2)?"sbicintr":
|
|
|
|
(routine==3)?"sbicicmd":
|
|
|
|
(routine==4)?"sbicnext":"unknown",
|
|
|
|
debug_asr, debug_csr, asr, csr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
|
|
|
sbictimeout(dev)
|
1995-08-18 19:27:29 +04:00
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
|
|
|
int s, asr;
|
|
|
|
|
1995-09-04 17:04:40 +04:00
|
|
|
s = splbio();
|
|
|
|
if (dev->sc_dmatimo) {
|
|
|
|
if (dev->sc_dmatimo > 1) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: dma timeout #%d\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_dev.dv_xname, dev->sc_dmatimo - 1);
|
1998-08-21 23:13:27 +04:00
|
|
|
GET_SBIC_asr(dev->sc_sbic, asr);
|
1995-09-04 17:04:40 +04:00
|
|
|
if( asr & SBIC_ASR_INT ) {
|
|
|
|
/* We need to service a missed IRQ */
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Servicing a missed int:(%02x,%02x)->(%02x,??)\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
debug_asr, debug_csr, asr);
|
|
|
|
sbicintr(dev);
|
|
|
|
}
|
|
|
|
sbicdumpstate();
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_dmatimo++;
|
|
|
|
}
|
|
|
|
splx(s);
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_reset(&dev->sc_timo_ch, 30 * hz,
|
|
|
|
(void *)sbictimeout, dev);
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sbic_dump_acb(acb)
|
|
|
|
struct sbic_acb *acb;
|
|
|
|
{
|
|
|
|
u_char *b = (u_char *) &acb->cmd;
|
|
|
|
int i;
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("acb@%p ", acb);
|
1995-09-04 17:04:40 +04:00
|
|
|
if (acb->xs == NULL) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("<unused>\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
return;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
printf("(%d:%d) flags %2x clen %2d cmd ",
|
2001-04-25 21:53:04 +04:00
|
|
|
acb->xs->xs_periph->periph_target,
|
|
|
|
acb->xs->xs_periph->periph_lun, acb->flags, acb->clen);
|
1995-09-04 17:04:40 +04:00
|
|
|
for (i = acb->clen; i; --i)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" %02x", *b++);
|
|
|
|
printf("\n");
|
|
|
|
printf(" xs: %8p data %8p:%04x ", acb->xs, acb->xs->data,
|
1995-09-04 17:04:40 +04:00
|
|
|
acb->xs->datalen);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("va %8p:%04x ", acb->sc_kv.dc_addr, acb->sc_kv.dc_count);
|
|
|
|
printf("pa %8p:%04x tcnt %lx\n", acb->sc_pa.dc_addr, acb->sc_pa.dc_count,
|
1995-09-04 17:04:40 +04:00
|
|
|
acb->sc_tcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sbic_dump(dev)
|
|
|
|
struct sbic_softc *dev;
|
|
|
|
{
|
1998-08-21 23:13:27 +04:00
|
|
|
sbic_regmap_t regs;
|
1995-09-04 17:04:40 +04:00
|
|
|
u_char csr, asr;
|
|
|
|
struct sbic_acb *acb;
|
|
|
|
int s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s = splbio();
|
1998-08-21 23:13:27 +04:00
|
|
|
regs = dev->sc_sbic;
|
1995-09-04 17:04:40 +04:00
|
|
|
#if CSR_TRACE_SIZE
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("csr trace: ");
|
1995-09-04 17:04:40 +04:00
|
|
|
i = csr_traceptr;
|
|
|
|
do {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%c%02x%02x%02x ", csr_trace[i].whr,
|
1995-09-04 17:04:40 +04:00
|
|
|
csr_trace[i].csr, csr_trace[i].asr, csr_trace[i].xtn);
|
|
|
|
switch(csr_trace[i].whr) {
|
|
|
|
case 'g':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("go "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 's':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("select "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'y':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("select+ "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'i':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("intr "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'f':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("finish "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case '>':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("out "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case '<':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("in "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'm':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("msgin "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'x':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("msginx "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'X':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("msginX "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'r':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("reselect "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'I':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("icmd "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 'a':
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("abort "); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
default:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("? ");
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
|
|
|
switch(csr_trace[i].csr) {
|
|
|
|
case 0x11:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("INITIATOR"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x16:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("S_XFERRED"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x20:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("MSGIN_ACK"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x41:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DISC"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x42:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("SEL_TIMEO"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x80:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("RSLT_NI"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x81:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("RSLT_IFY"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x85:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DISC_1"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x18: case 0x19: case 0x1a:
|
|
|
|
case 0x1b: case 0x1e: case 0x1f:
|
|
|
|
case 0x28: case 0x29: case 0x2a:
|
|
|
|
case 0x2b: case 0x2e: case 0x2f:
|
|
|
|
case 0x48: case 0x49: case 0x4a:
|
|
|
|
case 0x4b: case 0x4e: case 0x4f:
|
|
|
|
case 0x88: case 0x89: case 0x8a:
|
|
|
|
case 0x8b: case 0x8e: case 0x8f:
|
|
|
|
switch(csr_trace[i].csr & 0xf0) {
|
|
|
|
case 0x10:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DONE_"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x20:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("STOP_"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x40:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("ERR_"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 0x80:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("REQ_"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
|
|
|
switch(csr_trace[i].csr & 7) {
|
|
|
|
case 0:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DATA_OUT"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 1:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("DATA_IN"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 2:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("CMD"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 3:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("STATUS"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 6:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("MSG_OUT"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
case 7:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("MSG_IN"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
default:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("invld phs");
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
|
|
|
break;
|
1996-10-13 07:05:43 +04:00
|
|
|
default: printf("****"); break;
|
1995-09-04 17:04:40 +04:00
|
|
|
}
|
|
|
|
if (csr_trace[i].asr & SBIC_ASR_INT)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" ASR_INT");
|
1995-09-04 17:04:40 +04:00
|
|
|
if (csr_trace[i].asr & SBIC_ASR_LCI)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" ASR_LCI");
|
1995-09-04 17:04:40 +04:00
|
|
|
if (csr_trace[i].asr & SBIC_ASR_BSY)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" ASR_BSY");
|
1995-09-04 17:04:40 +04:00
|
|
|
if (csr_trace[i].asr & SBIC_ASR_CIP)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" ASR_CIP");
|
|
|
|
printf("\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
i = (i + 1) & (CSR_TRACE_SIZE - 1);
|
|
|
|
} while (i != csr_traceptr);
|
|
|
|
#endif
|
|
|
|
GET_SBIC_asr(regs, asr);
|
|
|
|
if ((asr & SBIC_ASR_INT) == 0)
|
|
|
|
GET_SBIC_csr(regs, csr);
|
|
|
|
else
|
|
|
|
csr = 0;
|
1999-10-05 00:28:01 +04:00
|
|
|
printf("%s@%p regs %p/%p asr %x csr %x\n", dev->sc_dev.dv_xname,
|
|
|
|
dev, regs.sbic_asr_p, regs.sbic_value_p, asr, csr);
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((acb = dev->free_list.tqh_first)) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Free list:\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
while (acb) {
|
|
|
|
sbic_dump_acb(acb);
|
|
|
|
acb = acb->chain.tqe_next;
|
|
|
|
}
|
|
|
|
}
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((acb = dev->ready_list.tqh_first)) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Ready list:\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
while (acb) {
|
|
|
|
sbic_dump_acb(acb);
|
|
|
|
acb = acb->chain.tqe_next;
|
|
|
|
}
|
|
|
|
}
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((acb = dev->nexus_list.tqh_first)) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Nexus list:\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
while (acb) {
|
|
|
|
sbic_dump_acb(acb);
|
|
|
|
acb = acb->chain.tqe_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev->sc_nexus) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("nexus:\n");
|
1995-09-04 17:04:40 +04:00
|
|
|
sbic_dump_acb(dev->sc_nexus);
|
|
|
|
}
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sc_xs %p targ %d lun %d flags %x tcnt %lx dmacmd %x mask %lx\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
dev->sc_xs, dev->target, dev->lun, dev->sc_flags, dev->sc_tcnt,
|
|
|
|
dev->sc_dmacmd, dev->sc_dmamask);
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (dev->sc_tinfo[i].cmds > 2) {
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("tgt %d: cmds %d disc %d lubusy %x\n",
|
1995-09-04 17:04:40 +04:00
|
|
|
i, dev->sc_tinfo[i].cmds,
|
|
|
|
dev->sc_tinfo[i].dconns,
|
|
|
|
dev->sc_tinfo[i].lubusy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
1995-08-18 19:27:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|