1996-03-31 00:01:21 +03:00
|
|
|
/* $NetBSD: ncr5380.c,v 1.18 1996/03/30 21:01:21 christos Exp $ */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Leo Weppelman.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Leo Weppelman.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1995-08-19 16:36:21 +04:00
|
|
|
/*
|
|
|
|
* Bit mask of targets you want debugging to be shown
|
|
|
|
*/
|
|
|
|
u_char dbg_target_mask = 0x7f;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set bit for target when parity checking must be disabled.
|
|
|
|
* My (LWP) Maxtor 7245S seems to generate parity errors on about 50%
|
|
|
|
* of all transfers while the data is correct!?
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
u_char ncr5380_no_parchk = 0xff;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-12-18 23:37:51 +03:00
|
|
|
#ifdef AUTO_SENSE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit masks of targets that accept linked commands, and those
|
|
|
|
* that we've already checked out
|
|
|
|
*/
|
|
|
|
u_char ncr_will_link = 0x00;
|
|
|
|
u_char ncr_test_link = 0x00;
|
|
|
|
|
|
|
|
#endif /* AUTO_SENSE */
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* This is the default sense-command we send.
|
|
|
|
*/
|
|
|
|
static u_char sense_cmd[] = {
|
1995-08-19 16:36:21 +04:00
|
|
|
REQUEST_SENSE, 0, 0, 0, sizeof(struct scsi_sense_data), 0
|
1995-03-26 11:12:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* True if the main co-routine is running
|
|
|
|
*/
|
|
|
|
static volatile int main_running = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask of targets selected
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
static u_char busy;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
static void ncr5380_minphys(struct buf *bp);
|
1995-03-26 11:12:03 +04:00
|
|
|
static int ncr5380_scsi_cmd(struct scsi_xfer *xs);
|
1996-02-23 00:07:05 +03:00
|
|
|
static void ncr5380_show_scsi_cmd(struct scsi_xfer *xs);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
struct scsi_adapter ncr5380_switch = {
|
|
|
|
ncr5380_scsi_cmd, /* scsi_cmd() */
|
|
|
|
ncr5380_minphys, /* scsi_minphys() */
|
|
|
|
0, /* open_target_lu() */
|
|
|
|
0 /* close_target_lu() */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct scsi_device ncr5380_dev = {
|
|
|
|
NULL, /* use default error handler */
|
|
|
|
NULL, /* do not have a start functio */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL /* Use default done routine */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static SC_REQ req_queue[NREQ];
|
|
|
|
static SC_REQ *free_head = NULL; /* Free request structures */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inline functions:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the size of a SCSI command.
|
|
|
|
*/
|
|
|
|
extern __inline__ int command_size(opcode)
|
|
|
|
u_char opcode;
|
|
|
|
{
|
1995-08-12 00:01:15 +04:00
|
|
|
switch ((opcode >> 4) & 0xf) {
|
1995-03-26 11:12:03 +04:00
|
|
|
case 0:
|
|
|
|
case 1:
|
1995-08-12 00:01:15 +04:00
|
|
|
return (6);
|
1995-03-26 11:12:03 +04:00
|
|
|
case 2:
|
|
|
|
case 3:
|
1995-08-12 00:01:15 +04:00
|
|
|
return (10);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
return (12);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for request-line to become active. When it doesn't return 0.
|
|
|
|
* Otherwise return != 0.
|
|
|
|
* The timeouts in the 'wait_req_*' functions are arbitrary and rather
|
|
|
|
* large. In 99% of the invocations nearly no timeout is needed but in
|
|
|
|
* some cases (especially when using my tapedrive, a Tandberg 3600) the
|
|
|
|
* device is busy internally and the first SCSI-phase will be delayed.
|
|
|
|
*/
|
|
|
|
extern __inline__ int wait_req_true(void)
|
|
|
|
{
|
|
|
|
int timeout = 25000;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
while (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_REQ) && --timeout)
|
1995-03-26 11:12:03 +04:00
|
|
|
delay(1);
|
1995-08-12 00:01:15 +04:00
|
|
|
return (GET_5380_REG(NCR5380_IDSTAT) & SC_S_REQ);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for request-line to become inactive. When it doesn't return 0.
|
|
|
|
* Otherwise return != 0.
|
|
|
|
*/
|
|
|
|
extern __inline__ int wait_req_false(void)
|
|
|
|
{
|
|
|
|
int timeout = 25000;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
while ((GET_5380_REG(NCR5380_IDSTAT) & SC_S_REQ) && --timeout)
|
1995-03-26 11:12:03 +04:00
|
|
|
delay(1);
|
1995-08-12 00:01:15 +04:00
|
|
|
return (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_REQ));
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-09-12 23:58:53 +04:00
|
|
|
extern __inline__ void ack_message()
|
|
|
|
{
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
}
|
|
|
|
|
1995-10-05 11:52:53 +03:00
|
|
|
extern __inline__ void nack_message(SC_REQ *reqp, u_char msg)
|
1995-09-12 23:58:53 +04:00
|
|
|
{
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ATN);
|
1995-10-05 11:52:53 +03:00
|
|
|
reqp->msgout = msg;
|
1995-09-12 23:58:53 +04:00
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
extern __inline__ void finish_req(SC_REQ *reqp)
|
|
|
|
{
|
|
|
|
int sps;
|
|
|
|
struct scsi_xfer *xs = reqp->xs;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
|
|
|
/*
|
|
|
|
* If we bounced, free the bounce buffer
|
|
|
|
*/
|
|
|
|
if (reqp->dr_flag & DRIVER_BOUNCING)
|
|
|
|
free_bounceb(reqp->bounceb);
|
|
|
|
#endif /* REAL_DMA */
|
1995-08-19 16:36:21 +04:00
|
|
|
#ifdef DBG_REQ
|
|
|
|
if (dbg_target_mask & (1 << reqp->targ_id))
|
|
|
|
show_request(reqp, "DONE");
|
|
|
|
#endif
|
|
|
|
#ifdef DBG_ERR_RET
|
|
|
|
if (reqp->xs->error != 0)
|
|
|
|
show_request(reqp, "ERR_RET");
|
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Return request to free-q
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
|
|
|
reqp->next = free_head;
|
|
|
|
free_head = reqp;
|
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
xs->flags |= ITSDONE;
|
1995-12-18 23:37:51 +03:00
|
|
|
if (!(reqp->dr_flag & DRIVER_LINKCHK))
|
|
|
|
scsi_done(xs);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Auto config stuff....
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
int ncr_cprint __P((void *auxp, char *));
|
1995-03-26 11:12:03 +04:00
|
|
|
void ncr_attach __P((struct device *, struct device *, void *));
|
1996-03-17 04:26:49 +03:00
|
|
|
int ncr_match __P((struct device *, void *, void *));
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
/*
|
|
|
|
* Tricks to make driver-name configurable
|
|
|
|
*/
|
1996-03-17 04:26:49 +03:00
|
|
|
#define CFNAME(n) __CONCAT(n,_cd)
|
|
|
|
#define CANAME(n) __CONCAT(n,_ca)
|
1995-08-12 00:01:15 +04:00
|
|
|
#define CFSTRING(n) __STRING(n)
|
|
|
|
|
1996-03-17 04:26:49 +03:00
|
|
|
struct cfattach CANAME(DRNAME) = {
|
|
|
|
sizeof(struct ncr_softc), ncr_match, ncr_attach
|
|
|
|
};
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
struct cfdriver CFNAME(DRNAME) = {
|
1996-03-17 04:26:49 +03:00
|
|
|
NULL, CFSTRING(DRNAME), DV_DULL, NULL, 0
|
|
|
|
};
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
int
|
1996-03-17 04:26:49 +03:00
|
|
|
ncr_match(pdp, match, auxp)
|
1995-03-26 11:12:03 +04:00
|
|
|
struct device *pdp;
|
1996-03-17 04:26:49 +03:00
|
|
|
void *match, *auxp;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
1996-03-17 04:26:49 +03:00
|
|
|
return (machine_match(pdp, match, auxp, &CFNAME(DRNAME)));
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ncr_attach(pdp, dp, auxp)
|
|
|
|
struct device *pdp, *dp;
|
|
|
|
void *auxp;
|
|
|
|
{
|
|
|
|
struct ncr_softc *sc;
|
1995-08-12 00:01:15 +04:00
|
|
|
int i;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
sc = (struct ncr_softc *)dp;
|
|
|
|
|
|
|
|
sc->sc_link.adapter_softc = sc;
|
|
|
|
sc->sc_link.adapter_target = 7;
|
|
|
|
sc->sc_link.adapter = &ncr5380_switch;
|
|
|
|
sc->sc_link.device = &ncr5380_dev;
|
|
|
|
sc->sc_link.openings = NREQ - 1;
|
|
|
|
|
1995-09-16 18:15:10 +04:00
|
|
|
/*
|
|
|
|
* bitmasks
|
|
|
|
*/
|
|
|
|
sc->sc_noselatn = 0;
|
|
|
|
sc->sc_selected = 0;
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
1995-08-12 00:01:15 +04:00
|
|
|
* Initialize machine-type specific things...
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_mach_init(sc);
|
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize request queue freelist.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
for (i = 0; i < NREQ; i++) {
|
1995-03-26 11:12:03 +04:00
|
|
|
req_queue[i].next = free_head;
|
|
|
|
free_head = &req_queue[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the host adapter
|
|
|
|
*/
|
|
|
|
scsi_idisable();
|
1995-08-12 00:01:15 +04:00
|
|
|
ENABLE_NCR5380(sc);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_TCOM, 0);
|
|
|
|
SET_5380_REG(NCR5380_IDSTAT, 0);
|
|
|
|
scsi_ienable();
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* attach all scsi units on us
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
config_found(dp, &sc->sc_link, ncr_cprint);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print diag if name is NULL else just extra
|
|
|
|
*/
|
|
|
|
int
|
1995-08-12 00:01:15 +04:00
|
|
|
ncr_cprint(auxp, name)
|
1995-03-26 11:12:03 +04:00
|
|
|
void *auxp;
|
|
|
|
char *name;
|
|
|
|
{
|
1995-08-12 00:01:15 +04:00
|
|
|
if (name == NULL)
|
|
|
|
return (UNCONF);
|
|
|
|
return (QUIET);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* End of auto config stuff....
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Carry out a request from the high level driver.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ncr5380_scsi_cmd(struct scsi_xfer *xs)
|
|
|
|
{
|
|
|
|
int sps;
|
1995-12-18 23:37:51 +03:00
|
|
|
SC_REQ *reqp, *link, *tmp;
|
1995-03-26 11:12:03 +04:00
|
|
|
int flags = xs->flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not queue RESET commands
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (flags & SCSI_RESET) {
|
1996-02-23 00:07:05 +03:00
|
|
|
scsi_reset_verbose(xs->sc_link->adapter_softc,
|
|
|
|
"Got reset-command");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (COMPLETE);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a request block
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((reqp = free_head) == 0) {
|
1995-03-26 11:12:03 +04:00
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
return (TRY_AGAIN_LATER);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
free_head = reqp->next;
|
|
|
|
reqp->next = NULL;
|
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize our private fields
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
reqp->dr_flag = (flags & SCSI_POLL) ? DRIVER_NOINT : 0;
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->phase = NR_PHASE;
|
|
|
|
reqp->msgout = MSG_NOOP;
|
|
|
|
reqp->status = SCSGOOD;
|
|
|
|
reqp->link = NULL;
|
|
|
|
reqp->xs = xs;
|
|
|
|
reqp->targ_id = xs->sc_link->target;
|
1995-08-12 00:01:15 +04:00
|
|
|
reqp->targ_lun = xs->sc_link->lun;
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xdata_ptr = (u_char*)xs->data;
|
|
|
|
reqp->xdata_len = xs->datalen;
|
|
|
|
memcpy(&reqp->xcmd, xs->cmd, sizeof(struct scsi_generic));
|
1995-08-12 00:01:15 +04:00
|
|
|
reqp->xcmd.bytes[0] |= reqp->targ_lun << 5;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
/*
|
|
|
|
* Sanity check on flags...
|
|
|
|
*/
|
|
|
|
if (flags & ITSDONE) {
|
|
|
|
ncr_tprint(reqp, "scsi_cmd: command already done.....\n");
|
|
|
|
xs->flags &= ~ITSDONE;
|
|
|
|
}
|
|
|
|
if (!(flags & INUSE)) {
|
|
|
|
ncr_tprint(reqp, "scsi_cmd: command not in use.....\n");
|
|
|
|
xs->flags |= ~INUSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef REAL_DMA
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Check if DMA can be used on this request
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (scsi_dmaok(reqp))
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->dr_flag |= DRIVER_DMAOK;
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif /* REAL_DMA */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the command into the issue queue. Note that 'REQUEST SENSE'
|
|
|
|
* commands are inserted at the head of the queue since any command
|
|
|
|
* will clear the existing contingent allegience condition and the sense
|
|
|
|
* data is only valid while the condition exists.
|
|
|
|
* When possible, link the command to a previous command to the same
|
|
|
|
* target. This is not very sensible when AUTO_SENSE is not defined!
|
|
|
|
* Interrupts are disabled while we are fiddling with the issue-queue.
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
1995-12-18 23:37:51 +03:00
|
|
|
link = NULL;
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((issue_q == NULL) || (reqp->xcmd.opcode == REQUEST_SENSE)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->next = issue_q;
|
|
|
|
issue_q = reqp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = issue_q;
|
|
|
|
do {
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!link && (tmp->targ_id == reqp->targ_id) && !tmp->link)
|
1995-03-26 11:12:03 +04:00
|
|
|
link = tmp;
|
1995-08-12 00:01:15 +04:00
|
|
|
} while (tmp->next && (tmp = tmp->next));
|
1995-03-26 11:12:03 +04:00
|
|
|
tmp->next = reqp;
|
|
|
|
#ifdef AUTO_SENSE
|
1995-12-18 23:37:51 +03:00
|
|
|
if (link && (ncr_will_link & (1<<reqp->targ_id))) {
|
1995-03-26 11:12:03 +04:00
|
|
|
link->link = reqp;
|
1995-11-30 03:56:23 +03:00
|
|
|
link->xcmd.bytes[link->xs->cmdlen-2] |= 1;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1995-12-18 23:37:51 +03:00
|
|
|
#ifdef AUTO_SENSE
|
|
|
|
/*
|
|
|
|
* If we haven't already, check the target for link support.
|
|
|
|
* Do this by prefixing the current command with a dummy
|
|
|
|
* Request_Sense command, link the dummy to the current
|
|
|
|
* command, and insert the dummy command at the head of the
|
|
|
|
* issue queue. Set the DRIVER_LINKCHK flag so that we'll
|
|
|
|
* ignore the results of the dummy command, since we only
|
|
|
|
* care about whether it was accepted or not.
|
|
|
|
*/
|
|
|
|
if (!link && !(ncr_test_link & (1<<reqp->targ_id)) &&
|
|
|
|
(tmp = free_head) && !(reqp->dr_flag & DRIVER_NOINT)) {
|
|
|
|
free_head = tmp->next;
|
|
|
|
tmp->dr_flag = (reqp->dr_flag & ~DRIVER_DMAOK) | DRIVER_LINKCHK;
|
|
|
|
tmp->phase = NR_PHASE;
|
|
|
|
tmp->msgout = MSG_NOOP;
|
|
|
|
tmp->status = SCSGOOD;
|
|
|
|
tmp->xs = reqp->xs;
|
|
|
|
tmp->targ_id = reqp->targ_id;
|
|
|
|
tmp->targ_lun = reqp->targ_lun;
|
|
|
|
bcopy(sense_cmd, &tmp->xcmd, sizeof(sense_cmd));
|
|
|
|
tmp->xdata_ptr = (u_char *)&tmp->xs->sense;
|
|
|
|
tmp->xdata_len = sizeof(tmp->xs->sense);
|
|
|
|
ncr_test_link |= 1<<tmp->targ_id;
|
|
|
|
tmp->link = reqp;
|
|
|
|
tmp->xcmd.bytes[sizeof(sense_cmd)-2] |= 1;
|
|
|
|
tmp->next = issue_q;
|
|
|
|
issue_q = tmp;
|
|
|
|
#ifdef DBG_REQ
|
|
|
|
if (dbg_target_mask & (1 << tmp->targ_id))
|
|
|
|
show_request(tmp, "LINKCHK");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << reqp->targ_id))
|
|
|
|
show_request(reqp, (reqp->xcmd.opcode == REQUEST_SENSE) ?
|
|
|
|
"HEAD":"TAIL");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
run_main(xs->sc_link->adapter_softc);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
if (xs->flags & (SCSI_POLL|ITSDONE))
|
|
|
|
return (COMPLETE); /* We're booting or run_main has completed */
|
1995-08-12 00:01:15 +04:00
|
|
|
return (SUCCESSFULLY_QUEUED);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
static void
|
1995-03-26 11:12:03 +04:00
|
|
|
ncr5380_minphys(struct buf *bp)
|
|
|
|
{
|
1995-08-19 16:36:21 +04:00
|
|
|
if (bp->b_bcount > MIN_PHYS)
|
1995-03-26 11:12:03 +04:00
|
|
|
bp->b_bcount = MIN_PHYS;
|
1995-08-13 00:30:45 +04:00
|
|
|
minphys(bp);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
#undef MIN_PHYS
|
|
|
|
|
1996-02-23 00:07:05 +03:00
|
|
|
static void
|
1995-03-26 11:12:03 +04:00
|
|
|
ncr5380_show_scsi_cmd(struct scsi_xfer *xs)
|
|
|
|
{
|
|
|
|
u_char *b = (u_char *) xs->cmd;
|
|
|
|
int i = 0;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!(xs->flags & SCSI_RESET)) {
|
|
|
|
printf("(%d:%d:%d,0x%x)-", xs->sc_link->scsibus,
|
1995-03-26 11:12:03 +04:00
|
|
|
xs->sc_link->target, xs->sc_link->lun, xs->sc_link->flags);
|
1995-08-12 00:01:15 +04:00
|
|
|
while (i < xs->cmdlen) {
|
|
|
|
if (i)
|
1995-03-26 11:12:03 +04:00
|
|
|
printf(",");
|
|
|
|
printf("%x",b[i++]);
|
|
|
|
}
|
|
|
|
printf("-\n");
|
|
|
|
}
|
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
printf("(%d:%d:%d)-RESET-\n",
|
1995-03-26 11:12:03 +04:00
|
|
|
xs->sc_link->scsibus,xs->sc_link->target, xs->sc_link->lun);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The body of the driver.
|
|
|
|
*/
|
|
|
|
static void
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_main(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *req, *prev;
|
|
|
|
int itype;
|
|
|
|
int sps;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While running in the driver SCSI-interrupts are disabled.
|
|
|
|
*/
|
|
|
|
scsi_idisable();
|
1995-08-12 00:01:15 +04:00
|
|
|
ENABLE_NCR5380(sc);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_main1");
|
|
|
|
for (;;) {
|
1995-03-26 11:12:03 +04:00
|
|
|
sps = splbio();
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!connected) {
|
|
|
|
/*
|
|
|
|
* Check if it is fair keep any exclusive access to DMA
|
|
|
|
* claimed. If not, stop queueing new jobs so the discon_q
|
|
|
|
* will be eventually drained and DMA can be given up.
|
|
|
|
*/
|
|
|
|
if (!fair_to_keep_dma())
|
|
|
|
goto main_exit;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Search through the issue-queue for a command
|
|
|
|
* destined for a target that isn't busy.
|
|
|
|
*/
|
|
|
|
prev = NULL;
|
1995-08-12 00:01:15 +04:00
|
|
|
for (req=issue_q; req != NULL; prev = req, req = req->next) {
|
|
|
|
if (!(busy & (1 << req->targ_id))) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Found one, remove it from the issue queue
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (prev == NULL)
|
1995-03-26 11:12:03 +04:00
|
|
|
issue_q = req->next;
|
|
|
|
else prev->next = req->next;
|
|
|
|
req->next = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a request has just ended, we get here before an other
|
|
|
|
* device detects that the bus is free and that it can
|
|
|
|
* reconnect. The problem is that when this happens, we always
|
|
|
|
* baffle the device because our (initiator) id is higher. This
|
|
|
|
* can cause a sort of starvation on slow devices. So we check
|
|
|
|
* for a pending reselection here.
|
|
|
|
* Note that 'connected' will be non-null if the reselection
|
|
|
|
* succeeds.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((GET_5380_REG(NCR5380_IDSTAT) & (SC_S_SEL|SC_S_IO))
|
1995-03-26 11:12:03 +04:00
|
|
|
== (SC_S_SEL|SC_S_IO)){
|
1995-08-12 00:01:15 +04:00
|
|
|
if (req != NULL) {
|
1995-03-26 11:12:03 +04:00
|
|
|
req->next = issue_q;
|
|
|
|
issue_q = req;
|
|
|
|
}
|
|
|
|
splx(sps);
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
reselect(sc);
|
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
goto connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The host is not connected and there is no request
|
|
|
|
* pending, exit.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (req == NULL) {
|
|
|
|
PID("scsi_main2");
|
1995-03-26 11:12:03 +04:00
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-enable interrupts before handling the request.
|
|
|
|
*/
|
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << req->targ_id))
|
|
|
|
show_request(req, "TARGET");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* We found a request. Try to connect to the target. If the
|
|
|
|
* initiator fails arbitration, the command is put back in the
|
|
|
|
* issue queue.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (scsi_select(req, 0)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
sps = splbio();
|
1995-08-19 16:36:21 +04:00
|
|
|
req->next = issue_q;
|
1995-03-26 11:12:03 +04:00
|
|
|
issue_q = req;
|
|
|
|
splx(sps);
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << req->targ_id))
|
|
|
|
ncr_tprint(req, "Select failed\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else splx(sps);
|
|
|
|
connected:
|
1995-08-12 00:01:15 +04:00
|
|
|
if (connected) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* If the host is currently connected but a 'real-dma' transfer
|
|
|
|
* is in progress, the 'end-of-dma' interrupt restarts main.
|
|
|
|
* So quit.
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
1995-08-12 00:01:15 +04:00
|
|
|
if (connected && (connected->dr_flag & DRIVER_IN_DMA)) {
|
|
|
|
PID("scsi_main3");
|
1995-03-26 11:12:03 +04:00
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Let the target guide us through the bus-phases
|
|
|
|
*/
|
1996-02-11 01:10:45 +03:00
|
|
|
while (information_transfer(sc) == -1)
|
1995-03-26 11:12:03 +04:00
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NEVER TO REACH HERE */
|
1995-08-12 00:01:15 +04:00
|
|
|
panic("ncr5380-SCSI: not designed to come here");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
main_exit:
|
|
|
|
/*
|
|
|
|
* We enter here with interrupts disabled. We are about to exit main
|
|
|
|
* so interrupts should be re-enabled. Because interrupts are edge
|
|
|
|
* triggered, we could already have missed the interrupt. Therefore
|
|
|
|
* we check the IRQ-line here and re-enter when we really missed a
|
|
|
|
* valid interrupt.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_main4");
|
1995-03-26 11:12:03 +04:00
|
|
|
scsi_ienable();
|
1996-02-11 01:10:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're not currently connected, enable reselection
|
|
|
|
* interrupts.
|
|
|
|
*/
|
|
|
|
if (!connected)
|
|
|
|
SET_5380_REG(NCR5380_IDSTAT, SC_HOST_ID);
|
|
|
|
|
|
|
|
if (scsi_ipending()) {
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((itype = check_intr(sc)) != INTR_SPURIOUS) {
|
1995-03-26 11:12:03 +04:00
|
|
|
scsi_idisable();
|
|
|
|
splx(sps);
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (itype == INTR_RESEL)
|
|
|
|
reselect(sc);
|
|
|
|
#ifdef REAL_DMA
|
|
|
|
else dma_ready();
|
|
|
|
#else
|
1995-09-16 18:15:10 +04:00
|
|
|
else {
|
|
|
|
if (pdma_ready())
|
|
|
|
goto connected;
|
|
|
|
panic("Got DMA interrupt without DMA");
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif
|
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
goto connected;
|
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
reconsider_dma();
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
main_running = 0;
|
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_main5");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* The SCSI-DMA interrupt.
|
|
|
|
* This interrupt can only be triggered when running in non-polled DMA
|
|
|
|
* mode. When DMA is not active, it will be silently ignored, it is usually
|
|
|
|
* to late because the EOP interrupt of the controller happens just a tiny
|
|
|
|
* bit earlier. It might become usefull when scatter/gather is implemented,
|
|
|
|
* because in that case only part of the DATAIN/DATAOUT transfer is taken
|
|
|
|
* out of a single buffer.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
static void
|
|
|
|
ncr_dma_intr(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *reqp;
|
|
|
|
int dma_done;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("ncr_dma_intr");
|
|
|
|
if ((reqp = connected) && (reqp->dr_flag & DRIVER_IN_DMA)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
scsi_idisable();
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!(dma_done = dma_ready())) {
|
1995-03-26 11:12:03 +04:00
|
|
|
transfer_dma(reqp, reqp->phase, 0);
|
|
|
|
return;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
run_main(sc);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif /* REAL_DMA */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The SCSI-controller interrupt. This interrupt occurs on reselections and
|
1995-08-12 00:01:15 +04:00
|
|
|
* at the end of non-polled DMA-interrupts. It is assumed to be called from
|
|
|
|
* the machine-dependent hardware interrupt.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
static void
|
|
|
|
ncr_ctrl_intr(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
int itype;
|
|
|
|
int dma_done;
|
|
|
|
|
1996-02-11 01:10:45 +03:00
|
|
|
while (scsi_ipending()) {
|
1995-03-26 11:12:03 +04:00
|
|
|
scsi_idisable();
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((itype = check_intr(sc)) != INTR_SPURIOUS) {
|
|
|
|
if (itype == INTR_RESEL)
|
|
|
|
reselect(sc);
|
1995-03-26 11:12:03 +04:00
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
|
|
|
if (!(dma_done = dma_ready())) {
|
1995-03-26 11:12:03 +04:00
|
|
|
transfer_dma(connected, connected->phase, 0);
|
|
|
|
return;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
#else
|
1995-09-16 18:15:10 +04:00
|
|
|
if (pdma_ready())
|
|
|
|
return;
|
1995-08-12 00:01:15 +04:00
|
|
|
panic("Got DMA interrupt without DMA\n");
|
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
run_main(sc);
|
1995-03-26 11:12:03 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("ncr_ctrl_intr1");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initiate a connection path between the host and the target. The function
|
|
|
|
* first goes into arbitration for the SCSI-bus. When this succeeds, the target
|
|
|
|
* is selected and an 'IDENTIFY' message is send.
|
|
|
|
* Returns -1 when the arbitration failed. Otherwise 0 is returned. When
|
|
|
|
* the target does not respond (to either selection or 'MESSAGE OUT') the
|
|
|
|
* 'done' function is executed.
|
|
|
|
* The result code given by the driver can be influenced by setting 'code'
|
|
|
|
* to a non-zero value. This is the case when 'select' is called by abort.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
scsi_select(reqp, code)
|
|
|
|
SC_REQ *reqp;
|
1996-02-23 00:07:05 +03:00
|
|
|
int code;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
1995-08-12 00:01:15 +04:00
|
|
|
u_char tmp[1];
|
|
|
|
u_char phase;
|
|
|
|
u_long cnt;
|
|
|
|
int sps;
|
1995-09-16 18:15:10 +04:00
|
|
|
u_int8_t atn_flag;
|
|
|
|
u_int8_t targ_bit;
|
1995-08-12 00:01:15 +04:00
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
sc = reqp->xs->sc_link->adapter_softc;
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_SELPRINT ("Starting arbitration\n", 0);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_select1");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
sps = splbio();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent a race condition here. If a reslection interrupt occurred
|
|
|
|
* between the decision to pick a new request and the call to select,
|
|
|
|
* we abort the selection.
|
|
|
|
* Interrupts are lowered when the 5380 is setup to arbitrate for the
|
|
|
|
* bus.
|
|
|
|
*/
|
1995-10-08 16:34:23 +03:00
|
|
|
if (connected) {
|
1995-03-26 11:12:03 +04:00
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_select2");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set phase bits to 0, otherwise the 5380 won't drive the bus during
|
|
|
|
* selection.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_TCOM, 0);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arbitrate for the bus.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_DATA, SC_HOST_ID);
|
|
|
|
SET_5380_REG(NCR5380_MODE, SC_ARBIT);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
splx(sps);
|
|
|
|
|
1995-10-08 16:34:23 +03:00
|
|
|
cnt = 10;
|
1995-08-12 00:01:15 +04:00
|
|
|
while (!(GET_5380_REG(NCR5380_ICOM) & SC_AIP) && --cnt)
|
1995-03-26 11:12:03 +04:00
|
|
|
delay(1);
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!(GET_5380_REG(NCR5380_ICOM) & SC_AIP)) {
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
1995-10-08 16:34:23 +03:00
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
DBG_SELPRINT ("Arbitration lost, bus not free\n",0);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_select3");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The arbitration delay is 2.2 usecs */
|
|
|
|
delay(3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the result of the arbitration. If we failed, return -1.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (GET_5380_REG(NCR5380_ICOM) & SC_LA) {
|
1995-10-08 16:34:23 +03:00
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
PID("scsi_select4");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The spec requires that we should read the data register to
|
|
|
|
* check for higher id's and check the SC_LA again.
|
|
|
|
*/
|
|
|
|
tmp[0] = GET_5380_REG(NCR5380_DATA);
|
|
|
|
if (tmp[0] & ~((SC_HOST_ID << 1) - 1)) {
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
DBG_SELPRINT ("Arbitration lost, higher id present\n",0);
|
|
|
|
PID("scsi_select5");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (GET_5380_REG(NCR5380_ICOM) & SC_LA) {
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
DBG_SELPRINT ("Arbitration lost,deassert SC_ARBIT\n",0);
|
|
|
|
PID("scsi_select6");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_SEL | SC_A_BSY);
|
|
|
|
if (GET_5380_REG(NCR5380_ICOM) & SC_LA) {
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_SELPRINT ("Arbitration lost, deassert SC_A_SEL\n", 0);
|
1995-10-08 16:34:23 +03:00
|
|
|
PID("scsi_select7");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
/* Bus settle delay + Bus clear delay = 1.2 usecs */
|
|
|
|
delay(2);
|
|
|
|
DBG_SELPRINT ("Arbitration complete\n", 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we won the arbitration, start the selection.
|
|
|
|
*/
|
1995-10-08 16:34:23 +03:00
|
|
|
targ_bit = 1 << reqp->targ_id;
|
1995-09-16 18:15:10 +04:00
|
|
|
SET_5380_REG(NCR5380_DATA, SC_HOST_ID | targ_bit);
|
|
|
|
|
|
|
|
if (sc->sc_noselatn & targ_bit)
|
|
|
|
atn_flag = 0;
|
|
|
|
else
|
|
|
|
atn_flag = SC_A_ATN;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Raise ATN while SEL is true before BSY goes false from arbitration,
|
|
|
|
* since this is the only way to guarantee that we'll get a MESSAGE OUT
|
|
|
|
* phase immediately after the selection.
|
|
|
|
*/
|
1995-09-16 18:15:10 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_BSY | SC_A_SEL | atn_flag | SC_ADTB);
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off reselection interrupts
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_IDSTAT, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset BSY. The delay following it, surpresses a glitch in the
|
|
|
|
* 5380 which causes us to see our own BSY signal instead of that of
|
|
|
|
* the target.
|
|
|
|
*/
|
1995-09-16 18:15:10 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_SEL | atn_flag | SC_ADTB);
|
1995-03-26 11:12:03 +04:00
|
|
|
delay(1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the target to react, the specs call for a timeout of
|
|
|
|
* 250 ms.
|
|
|
|
*/
|
1995-10-08 16:34:23 +03:00
|
|
|
cnt = 25000;
|
1995-08-12 00:01:15 +04:00
|
|
|
while (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY) && --cnt)
|
|
|
|
delay(10);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* There is no reaction from the target, start the selection
|
|
|
|
* timeout procedure. We release the databus but keep SEL
|
|
|
|
* asserted. After that we wait a 'selection abort time' (200
|
|
|
|
* usecs) and 2 deskew delays (90 ns) and check BSY again.
|
|
|
|
* When BSY is asserted, we assume the selection succeeded,
|
|
|
|
* otherwise we release the bus.
|
|
|
|
*/
|
1995-10-08 16:34:23 +03:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_SEL | atn_flag);
|
1995-03-26 11:12:03 +04:00
|
|
|
delay(201);
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY)) {
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xs->error = code ? code : XS_SELTIMEOUT;
|
|
|
|
DBG_SELPRINT ("Target %d not responding to sel\n",
|
|
|
|
reqp->targ_id);
|
1995-12-18 23:37:51 +03:00
|
|
|
if (reqp->dr_flag & DRIVER_LINKCHK)
|
|
|
|
ncr_test_link &= ~(1<<reqp->targ_id);
|
1995-03-26 11:12:03 +04:00
|
|
|
finish_req(reqp);
|
1995-10-08 16:34:23 +03:00
|
|
|
PID("scsi_select8");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-09-16 18:15:10 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, atn_flag);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
DBG_SELPRINT ("Target %d responding to select.\n", reqp->targ_id);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The SCSI-interrupts are disabled while a request is being handled.
|
|
|
|
*/
|
|
|
|
scsi_idisable();
|
|
|
|
|
|
|
|
/*
|
1995-09-16 18:15:10 +04:00
|
|
|
* If we did not request ATN, then don't try to send IDENTIFY.
|
|
|
|
*/
|
|
|
|
if (atn_flag == 0) {
|
|
|
|
reqp->phase = PH_CMD;
|
|
|
|
goto identify_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we prepare to send an 'IDENTIFY' message.
|
1995-03-26 11:12:03 +04:00
|
|
|
* Allow disconnect only when interrups are allowed.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
tmp[0] = MSG_IDENTIFY(reqp->targ_lun,
|
1995-09-16 18:15:10 +04:00
|
|
|
(reqp->dr_flag & DRIVER_NOINT) ? 0 : 1);
|
1995-03-26 11:12:03 +04:00
|
|
|
cnt = 1;
|
|
|
|
phase = PH_MSGOUT;
|
1995-09-16 18:15:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we followed the SCSI-spec and raised ATN while SEL was true
|
|
|
|
* but before BSY was false during the selection, a 'MESSAGE OUT'
|
|
|
|
* phase should follow. Unfortunately, this does not happen on
|
|
|
|
* all targets (Asante ethernet devices, for example), so we must
|
|
|
|
* check the actual mode if the message transfer fails--if the
|
|
|
|
* new phase is PH_CMD and has never been successfully selected
|
|
|
|
* w/ATN in the past, then we assume that it is an old device
|
|
|
|
* that doesn't support select w/ATN.
|
|
|
|
*/
|
1995-09-12 23:58:53 +04:00
|
|
|
if (transfer_pio(&phase, tmp, &cnt, 0) || cnt) {
|
1995-09-16 18:15:10 +04:00
|
|
|
|
|
|
|
if ((phase == PH_CMD) && !(sc->sc_selected & targ_bit)) {
|
|
|
|
DBG_SELPRINT ("Target %d: not responding to ATN.\n",
|
|
|
|
reqp->targ_id);
|
|
|
|
sc->sc_noselatn |= targ_bit;
|
|
|
|
reqp->phase = PH_CMD;
|
|
|
|
goto identify_failed;
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_SELPRINT ("Target %d: failed to send identify\n",
|
|
|
|
reqp->targ_id);
|
|
|
|
/*
|
1995-09-16 18:15:10 +04:00
|
|
|
* Try to disconnect from the target. We cannot leave
|
|
|
|
* it just hanging here.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!reach_msg_out(sc, sizeof(struct scsi_generic))) {
|
1995-03-26 11:12:03 +04:00
|
|
|
u_long len = 1;
|
|
|
|
u_char phase = PH_MSGOUT;
|
|
|
|
u_char msg = MSG_ABORT;
|
|
|
|
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, &msg, &len, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1996-02-23 00:07:05 +03:00
|
|
|
else scsi_reset_verbose(sc, "Connected to unidentified target");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xs->error = code ? code : XS_DRIVER_STUFFUP;
|
|
|
|
finish_req(reqp);
|
1995-10-08 16:34:23 +03:00
|
|
|
PID("scsi_select9");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
reqp->phase = PH_MSGOUT;
|
|
|
|
|
1995-09-16 18:15:10 +04:00
|
|
|
identify_failed:
|
|
|
|
sc->sc_selected |= targ_bit;
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
#ifdef notyet /* LWP: Do we need timeouts in the driver? */
|
|
|
|
/*
|
|
|
|
* Command is connected, start timer ticking.
|
|
|
|
*/
|
|
|
|
ccb_p->xtimeout = ccb_p->timeout + Lbolt;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
connected = reqp;
|
1995-09-16 18:15:10 +04:00
|
|
|
busy |= targ_bit;
|
1995-10-08 16:34:23 +03:00
|
|
|
PID("scsi_select10");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return codes:
|
1996-02-11 01:10:45 +03:00
|
|
|
* 0: Job has finished or disconnected, find something else
|
|
|
|
* -1: keep on calling information_transfer() from scsi_main()
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
|
|
|
static int
|
1996-02-11 01:10:45 +03:00
|
|
|
information_transfer(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *reqp = connected;
|
|
|
|
u_char tmp, phase;
|
|
|
|
u_long len;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf1");
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Clear pending interrupts from 5380-chip.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-11 01:10:45 +03:00
|
|
|
* The SCSI-spec requires BSY to be true while connected to a target,
|
|
|
|
* loosing it means we lost the target...
|
|
|
|
* Also REQ needs to be asserted here to indicate that the bus-phase
|
|
|
|
* is valid. When the target does not supply REQ within a 'reasonable'
|
|
|
|
* amount of time, it's probably lost in it's own maze of twisting
|
|
|
|
* passages, we have to reset the bus to free it.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1996-02-11 01:10:45 +03:00
|
|
|
if (GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY)
|
|
|
|
wait_req_true();
|
1995-08-12 00:01:15 +04:00
|
|
|
tmp = GET_5380_REG(NCR5380_IDSTAT);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1996-02-11 01:10:45 +03:00
|
|
|
|
|
|
|
if ((tmp & (SC_S_BSY|SC_S_REQ)) != (SC_S_BSY|SC_S_REQ)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
busy &= ~(1 << reqp->targ_id);
|
|
|
|
connected = NULL;
|
1996-02-11 01:10:45 +03:00
|
|
|
reqp->xs->error = XS_TIMEOUT;
|
1995-03-26 11:12:03 +04:00
|
|
|
finish_req(reqp);
|
1996-02-11 01:10:45 +03:00
|
|
|
if (!(tmp & SC_S_REQ))
|
1996-02-23 00:07:05 +03:00
|
|
|
scsi_reset_verbose(sc,
|
|
|
|
"Timeout waiting for phase-change");
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf2");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1996-02-11 01:10:45 +03:00
|
|
|
phase = (tmp >> 2) & 7;
|
|
|
|
if (phase != reqp->phase) {
|
|
|
|
reqp->phase = phase;
|
|
|
|
DBG_INFPRINT(show_phase, reqp, phase);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
switch (phase) {
|
1995-03-26 11:12:03 +04:00
|
|
|
case PH_DATAOUT:
|
|
|
|
#ifdef DBG_NOWRITE
|
1995-08-12 00:01:15 +04:00
|
|
|
ncr_tprint(reqp, "NOWRITE set -- write attempt aborted.");
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->msgout = MSG_ABORT;
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ATN);
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif /* DBG_NOWRITE */
|
1995-08-12 00:01:15 +04:00
|
|
|
/*
|
|
|
|
* If this is the first write using DMA, fill
|
|
|
|
* the bounce buffer.
|
|
|
|
*/
|
|
|
|
if (reqp->xdata_ptr == reqp->xs->data) { /* XXX */
|
|
|
|
if (reqp->dr_flag & DRIVER_BOUNCING)
|
|
|
|
bcopy(reqp->xdata_ptr, reqp->bounceb, reqp->xdata_len);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
case PH_DATAIN:
|
|
|
|
#ifdef REAL_DMA
|
1995-08-12 00:01:15 +04:00
|
|
|
if (reqp->dr_flag & DRIVER_DMAOK) {
|
1995-03-26 11:12:03 +04:00
|
|
|
int poll = REAL_DMA_POLL|(reqp->dr_flag & DRIVER_NOINT);
|
|
|
|
transfer_dma(reqp, phase, poll);
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!poll)
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf3");
|
1995-03-26 11:12:03 +04:00
|
|
|
len = reqp->xdata_len;
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef USE_PDMA
|
1995-09-05 11:02:21 +04:00
|
|
|
if (transfer_pdma(&phase, reqp->xdata_ptr, &len) == 0)
|
|
|
|
return (0);
|
1995-08-12 00:01:15 +04:00
|
|
|
#else
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, reqp->xdata_ptr, &len, 0);
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xdata_ptr += reqp->xdata_len - len;
|
|
|
|
reqp->xdata_len = len;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
case PH_MSGIN:
|
|
|
|
/*
|
|
|
|
* We only expect single byte messages here.
|
|
|
|
*/
|
|
|
|
len = 1;
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, &tmp, &len, 1);
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->message = tmp;
|
1995-08-12 00:01:15 +04:00
|
|
|
return (handle_message(reqp, tmp));
|
1995-03-26 11:12:03 +04:00
|
|
|
case PH_MSGOUT:
|
|
|
|
len = 1;
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, &reqp->msgout, &len, 0);
|
1995-08-12 00:01:15 +04:00
|
|
|
if (reqp->msgout == MSG_ABORT) {
|
1995-03-26 11:12:03 +04:00
|
|
|
busy &= ~(1 << reqp->targ_id);
|
|
|
|
connected = NULL;
|
|
|
|
reqp->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
finish_req(reqp);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf4");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
reqp->msgout = MSG_NOOP;
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
case PH_CMD :
|
|
|
|
len = command_size(reqp->xcmd.opcode);
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, (u_char *)&reqp->xcmd, &len, 0);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf5");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
case PH_STATUS:
|
|
|
|
len = 1;
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, &tmp, &len, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->status = tmp;
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf6");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
default :
|
1995-08-12 00:01:15 +04:00
|
|
|
ncr_tprint(reqp, "Unknown phase\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("info_transf7");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the message 'msg' send to us by the target.
|
|
|
|
* Return values:
|
|
|
|
* 0 : The current command has completed.
|
|
|
|
* -1 : Get on to the next phase.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
handle_message(reqp, msg)
|
|
|
|
SC_REQ *reqp;
|
|
|
|
u_int msg;
|
|
|
|
{
|
|
|
|
int sps;
|
1995-11-30 03:56:23 +03:00
|
|
|
SC_REQ *prev, *req;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage1");
|
|
|
|
switch (msg) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Linking lets us reduce the time required to get
|
|
|
|
* the next command to the device, skipping the arbitration
|
|
|
|
* and selection time. In the current implementation,
|
|
|
|
* we merely have to start the next command pointed
|
|
|
|
* to by 'next_link'.
|
|
|
|
*/
|
|
|
|
case MSG_LINK_CMD_COMPLETE:
|
|
|
|
case MSG_LINK_CMD_COMPLETEF:
|
1995-08-12 00:01:15 +04:00
|
|
|
if (reqp->link == NULL) {
|
|
|
|
ncr_tprint(reqp, "No link for linked command");
|
1995-10-05 11:52:53 +03:00
|
|
|
nack_message(reqp, MSG_ABORT);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage2");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-09-12 23:58:53 +04:00
|
|
|
ack_message();
|
1995-11-30 03:56:23 +03:00
|
|
|
if (!(reqp->dr_flag & DRIVER_AUTOSEN)) {
|
|
|
|
reqp->xs->resid = reqp->xdata_len;
|
|
|
|
reqp->xs->error = 0;
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
#ifdef AUTO_SENSE
|
1995-11-30 03:56:23 +03:00
|
|
|
if (check_autosense(reqp, 1) == -1)
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif /* AUTO_SENSE */
|
|
|
|
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << reqp->targ_id))
|
|
|
|
show_request(reqp->link, "LINK");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
connected = reqp->link;
|
1995-11-30 03:56:23 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink the 'linked' request from the issue_q
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
|
|
|
prev = NULL;
|
|
|
|
req = issue_q;
|
|
|
|
for (; req != NULL; prev = req, req = req->next) {
|
|
|
|
if (req == connected)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (req == NULL)
|
|
|
|
panic("Inconsistent issue_q");
|
|
|
|
if (prev == NULL)
|
|
|
|
issue_q = req->next;
|
|
|
|
else prev->next = req->next;
|
|
|
|
req->next = NULL;
|
|
|
|
splx(sps);
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
finish_req(reqp);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage3");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
case MSG_ABORT:
|
|
|
|
case MSG_CMDCOMPLETE:
|
1995-09-12 23:58:53 +04:00
|
|
|
ack_message();
|
1995-08-19 16:36:21 +04:00
|
|
|
connected = NULL;
|
1995-03-26 11:12:03 +04:00
|
|
|
busy &= ~(1 << reqp->targ_id);
|
1995-08-19 16:36:21 +04:00
|
|
|
if (!(reqp->dr_flag & DRIVER_AUTOSEN)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xs->resid = reqp->xdata_len;
|
|
|
|
reqp->xs->error = 0;
|
1995-08-19 16:36:21 +04:00
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
#ifdef AUTO_SENSE
|
1995-08-12 00:01:15 +04:00
|
|
|
if (check_autosense(reqp, 0) == -1) {
|
|
|
|
PID("hmessage4");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
#endif /* AUTO_SENSE */
|
|
|
|
|
|
|
|
finish_req(reqp);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage5");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
case MSG_MESSAGE_REJECT:
|
1995-09-12 23:58:53 +04:00
|
|
|
ack_message();
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage6");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
case MSG_DISCONNECT:
|
1995-09-12 23:58:53 +04:00
|
|
|
ack_message();
|
1995-03-26 11:12:03 +04:00
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << reqp->targ_id))
|
|
|
|
show_request(reqp, "DISCON");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
sps = splbio();
|
|
|
|
connected = NULL;
|
|
|
|
reqp->next = discon_q;
|
|
|
|
discon_q = reqp;
|
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage7");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
case MSG_SAVEDATAPOINTER:
|
|
|
|
case MSG_RESTOREPOINTERS:
|
|
|
|
/*
|
|
|
|
* We save pointers implicitely at disconnect.
|
|
|
|
* So we can ignore these messages.
|
|
|
|
*/
|
1995-09-12 23:58:53 +04:00
|
|
|
ack_message();
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("hmessage8");
|
|
|
|
return (-1);
|
1995-09-12 23:58:53 +04:00
|
|
|
case MSG_EXTENDED:
|
1995-10-05 11:52:53 +03:00
|
|
|
nack_message(reqp, MSG_MESSAGE_REJECT);
|
1995-09-12 23:58:53 +04:00
|
|
|
PID("hmessage9");
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
default:
|
1995-10-05 11:52:53 +03:00
|
|
|
ncr_tprint(reqp, "Unknown message %x\n", msg);
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-09-12 23:58:53 +04:00
|
|
|
PID("hmessage10");
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle reselection. If a valid reconnection occurs, connected
|
|
|
|
* points at the reconnected command. The command is removed from the
|
|
|
|
* disconnected queue.
|
|
|
|
*/
|
|
|
|
static void
|
1995-08-12 00:01:15 +04:00
|
|
|
reselect(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
u_char phase;
|
|
|
|
u_long len;
|
|
|
|
u_char msg;
|
|
|
|
u_char target_mask;
|
|
|
|
int abort = 0;
|
1996-02-23 00:07:05 +03:00
|
|
|
SC_REQ *tmp = NULL, *prev;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("reselect1");
|
|
|
|
target_mask = GET_5380_REG(NCR5380_DATA) & ~SC_HOST_ID;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we have detected that our SCSI-id is on the bus,
|
|
|
|
* SEL is true and BSY was false for at least one bus settle
|
|
|
|
* delay (400 ns.).
|
|
|
|
* We must assert BSY ourselves, until the target drops the SEL signal.
|
1995-09-12 23:58:53 +04:00
|
|
|
* The SCSI-spec specifies no maximum time for this, so we have to
|
|
|
|
* choose something long enough to suit all targets.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_BSY);
|
1995-11-30 03:56:23 +03:00
|
|
|
len = 250000;
|
1995-09-05 11:02:21 +04:00
|
|
|
while ((GET_5380_REG(NCR5380_IDSTAT) & SC_S_SEL) && (len > 0)) {
|
|
|
|
delay(1);
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
if (GET_5380_REG(NCR5380_IDSTAT) & SC_S_SEL) {
|
|
|
|
/* Damn SEL isn't dropping */
|
1996-02-23 00:07:05 +03:00
|
|
|
scsi_reset_verbose(sc, "Target won't drop SEL during Reselect");
|
1995-09-05 11:02:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Check if the reselection is still valid. Check twice because
|
|
|
|
* of possible line glitches - cheaper than delay(1) and we need
|
|
|
|
* only a few nanoseconds.
|
|
|
|
*/
|
|
|
|
if (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY)) {
|
|
|
|
if (!(GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY)) {
|
|
|
|
ncr_aprint(sc, "Stepped into the reselection timeout\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Get the expected identify message.
|
|
|
|
*/
|
|
|
|
phase = PH_MSGIN;
|
|
|
|
len = 1;
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(&phase, &msg, &len, 0);
|
1995-08-12 00:01:15 +04:00
|
|
|
if (len || !MSG_ISIDENTIFY(msg)) {
|
|
|
|
ncr_aprint(sc, "Expecting IDENTIFY, got 0x%x\n", msg);
|
1995-03-26 11:12:03 +04:00
|
|
|
abort = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Find the command reconnecting
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
for (tmp = discon_q, prev = NULL; tmp; prev = tmp, tmp = tmp->next){
|
|
|
|
if (target_mask == (1 << tmp->targ_id)) {
|
|
|
|
if (prev)
|
1995-03-26 11:12:03 +04:00
|
|
|
prev->next = tmp->next;
|
|
|
|
else discon_q = tmp->next;
|
|
|
|
tmp->next = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (tmp == NULL) {
|
|
|
|
ncr_aprint(sc, "No disconnected job for targetmask %x\n",
|
1995-03-26 11:12:03 +04:00
|
|
|
target_mask);
|
1995-08-12 00:01:15 +04:00
|
|
|
abort = 1;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (abort) {
|
1995-03-26 11:12:03 +04:00
|
|
|
msg = MSG_ABORT;
|
|
|
|
len = 1;
|
|
|
|
phase = PH_MSGOUT;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ATN);
|
1995-12-18 23:37:51 +03:00
|
|
|
if (transfer_pio(&phase, &msg, &len, 0) || len)
|
1996-02-23 00:07:05 +03:00
|
|
|
scsi_reset_verbose(sc, "Failure to abort reselection");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
connected = tmp;
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
if (dbg_target_mask & (1 << tmp->targ_id))
|
|
|
|
show_request(tmp, "RECON");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("reselect2");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-08-12 00:01:15 +04:00
|
|
|
* Transfer data in a given phase using programmed I/O.
|
1995-03-26 11:12:03 +04:00
|
|
|
* Returns -1 when a different phase is entered without transferring the
|
1995-09-12 23:58:53 +04:00
|
|
|
* maximum number of bytes, 0 if all bytes transferred or exit is in the same
|
1995-03-26 11:12:03 +04:00
|
|
|
* phase.
|
|
|
|
*/
|
|
|
|
static int
|
1995-09-12 23:58:53 +04:00
|
|
|
transfer_pio(phase, data, len, dont_drop_ack)
|
1995-03-26 11:12:03 +04:00
|
|
|
u_char *phase;
|
|
|
|
u_char *data;
|
|
|
|
u_long *len;
|
1995-09-12 23:58:53 +04:00
|
|
|
int dont_drop_ack;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
u_int cnt = *len;
|
|
|
|
u_char ph = *phase;
|
1995-09-12 23:58:53 +04:00
|
|
|
u_char tmp, new_icom;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
DBG_PIOPRINT ("SCSI: transfer_pio start: phase: %d, len: %d\n", ph,cnt);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("tpio1");
|
|
|
|
SET_5380_REG(NCR5380_TCOM, ph);
|
1995-03-26 11:12:03 +04:00
|
|
|
do {
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!wait_req_true()) {
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_PIOPRINT ("SCSI: transfer_pio: missing REQ\n", 0, 0);
|
|
|
|
break;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (((GET_5380_REG(NCR5380_IDSTAT) >> 2) & 7) != ph) {
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_PIOPRINT ("SCSI: transfer_pio: phase mismatch\n", 0, 0);
|
|
|
|
break;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (PH_IN(ph)) {
|
|
|
|
*data++ = GET_5380_REG(NCR5380_DATA);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ACK);
|
1995-09-12 23:58:53 +04:00
|
|
|
if ((cnt == 1) && dont_drop_ack)
|
|
|
|
new_icom = SC_A_ACK;
|
|
|
|
else new_icom = 0;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_DATA, *data++);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The SCSI-standard suggests that in the 'MESSAGE OUT' phase,
|
|
|
|
* the initiator should drop ATN on the last byte of the
|
|
|
|
* message phase after REQ has been asserted for the handshake
|
|
|
|
* but before the initiator raises ACK.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!( (ph == PH_MSGOUT) && (cnt > 1) )) {
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_ADTB);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_ADTB | SC_A_ACK);
|
1995-09-12 23:58:53 +04:00
|
|
|
new_icom = 0;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_ADTB | SC_A_ATN);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_ADTB|SC_A_ATN|SC_A_ACK);
|
1995-09-12 23:58:53 +04:00
|
|
|
new_icom = SC_A_ATN;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!wait_req_false()) {
|
1995-03-26 11:12:03 +04:00
|
|
|
DBG_PIOPRINT ("SCSI: transfer_pio - REQ not dropping\n", 0, 0);
|
|
|
|
break;
|
|
|
|
}
|
1995-09-12 23:58:53 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, new_icom);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
} while (--cnt);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((tmp = GET_5380_REG(NCR5380_IDSTAT)) & SC_S_REQ)
|
1995-03-26 11:12:03 +04:00
|
|
|
*phase = (tmp >> 2) & 7;
|
|
|
|
else *phase = NR_PHASE;
|
|
|
|
*len = cnt;
|
|
|
|
DBG_PIOPRINT ("SCSI: transfer_pio done: phase: %d, len: %d\n",
|
|
|
|
*phase, cnt);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("tpio2");
|
|
|
|
if (!cnt || (*phase == ph))
|
|
|
|
return (0);
|
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Start a DMA-transfer on the device using the current pointers.
|
1995-08-12 00:01:15 +04:00
|
|
|
* If 'poll' is true, the function busy-waits until DMA has completed.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
transfer_dma(reqp, phase, poll)
|
|
|
|
SC_REQ *reqp;
|
|
|
|
u_int phase;
|
|
|
|
int poll;
|
|
|
|
{
|
1995-08-12 00:01:15 +04:00
|
|
|
int dma_done;
|
1995-03-26 11:12:03 +04:00
|
|
|
u_char mbase = 0;
|
|
|
|
int sps;
|
|
|
|
|
|
|
|
again:
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("tdma1");
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* We should be in phase, otherwise we are not allowed to
|
|
|
|
* drive the bus.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_TCOM, phase);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Defer interrupts until DMA is fully running.
|
|
|
|
*/
|
|
|
|
sps = splbio();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear pending interrupts and parity errors.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!poll) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Enable SCSI interrupts and set IN_DMA flag, set 'mbase'
|
|
|
|
* to the interrupts we want enabled.
|
|
|
|
*/
|
|
|
|
scsi_ienable();
|
|
|
|
reqp->dr_flag |= DRIVER_IN_DMA;
|
|
|
|
mbase = SC_E_EOPI | SC_MON_BSY;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
else scsi_idisable();
|
|
|
|
mbase |= IMODE_BASE | SC_M_DMA;
|
|
|
|
scsi_dma_setup(reqp, phase, mbase);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
splx(sps);
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (poll) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
1995-08-12 00:01:15 +04:00
|
|
|
* On polled-dma transfers, we wait here until the
|
|
|
|
* 'end-of-dma' condition occurs.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
poll_edma(reqp);
|
|
|
|
if (!(dma_done = dma_ready()))
|
1995-03-26 11:12:03 +04:00
|
|
|
goto again;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("tdma2");
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check results of a DMA data-transfer.
|
|
|
|
*/
|
|
|
|
static int
|
1995-08-12 00:01:15 +04:00
|
|
|
dma_ready()
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *reqp = connected;
|
1995-08-12 00:01:15 +04:00
|
|
|
int dmstat, is_edma;
|
|
|
|
long bytes_left, bytes_done;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
is_edma = get_dma_result(reqp, &bytes_left);
|
|
|
|
dmstat = GET_5380_REG(NCR5380_DMSTAT);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the call is sensible and not caused by any spurious
|
|
|
|
* interrupt.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!is_edma && !(dmstat & (SC_END_DMA|SC_BSY_ERR))
|
|
|
|
&& (dmstat & SC_PHS_MTCH) ) {
|
1996-01-06 23:17:15 +03:00
|
|
|
ncr_tprint(reqp, "dma_ready: spurious call "
|
1995-08-12 00:01:15 +04:00
|
|
|
"(dm:%x,last_hit: %s)\n",
|
|
|
|
#ifdef DBG_PID
|
1996-01-06 23:17:15 +03:00
|
|
|
dmstat, last_hit[DBG_PID-1]);
|
1995-08-12 00:01:15 +04:00
|
|
|
#else
|
1996-01-06 23:17:15 +03:00
|
|
|
dmstat, "unknown");
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-08-12 00:01:15 +04:00
|
|
|
* Clear all (pending) interrupts.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update various transfer-pointers/lengths
|
|
|
|
*/
|
|
|
|
bytes_done = reqp->dm_cur->dm_count - bytes_left;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((reqp->dr_flag & DRIVER_BOUNCING) && (PH_IN(reqp->phase))) {
|
|
|
|
/*
|
|
|
|
* Copy the bytes read until now from the bounce buffer
|
|
|
|
* to the 'real' destination. Flush the data-cache
|
|
|
|
* before copying.
|
|
|
|
*/
|
|
|
|
PCIA();
|
|
|
|
bcopy(reqp->bouncerp, reqp->xdata_ptr, bytes_done);
|
|
|
|
reqp->bouncerp += bytes_done;
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xdata_ptr = &reqp->xdata_ptr[bytes_done]; /* XXX */
|
|
|
|
reqp->xdata_len -= bytes_done; /* XXX */
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((reqp->dm_cur->dm_count -= bytes_done) == 0)
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->dm_cur++;
|
|
|
|
else reqp->dm_cur->dm_addr += bytes_done;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (PH_IN(reqp->phase) && (dmstat & SC_PAR_ERR)) {
|
|
|
|
if (!(ncr5380_no_parchk & (1 << reqp->targ_id)))
|
1995-03-26 11:12:03 +04:00
|
|
|
/* XXX: Should be parity error ???? */
|
|
|
|
reqp->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA mode should always be reset even when we will continue with the
|
1995-10-08 16:34:23 +03:00
|
|
|
* next chain. It is also essential to clear the MON_BUSY because
|
|
|
|
* when LOST_BUSY is unexpectedly set, we will not be able to drive
|
|
|
|
* the bus....
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-10-08 16:34:23 +03:00
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
1995-08-12 00:01:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
if ((dmstat & SC_BSY_ERR) || !(dmstat & SC_PHS_MTCH)
|
|
|
|
|| (reqp->dm_cur > reqp->dm_last) || (reqp->xs->error)) {
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell interrupt functions DMA mode has ended.
|
|
|
|
*/
|
|
|
|
reqp->dr_flag &= ~DRIVER_IN_DMA;
|
|
|
|
|
|
|
|
/*
|
1995-08-12 00:01:15 +04:00
|
|
|
* Clear mode and icom
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (dmstat & SC_BSY_ERR) {
|
|
|
|
if (!reqp->xs->error)
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xs->error = XS_BUSY;
|
|
|
|
finish_req(reqp);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("dma_ready1");
|
|
|
|
return (1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (reqp->xs->error != 0) {
|
|
|
|
ncr_tprint(reqp, "dma-ready: code = %d\n", reqp->xs->error); /* LWP */
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->msgout = MSG_ABORT;
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ATN);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("dma_ready2");
|
|
|
|
return (1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif /* REAL_DMA */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
check_autosense(reqp, linked)
|
|
|
|
SC_REQ *reqp;
|
|
|
|
int linked;
|
|
|
|
{
|
|
|
|
int sps;
|
|
|
|
|
1995-12-18 23:37:51 +03:00
|
|
|
/*
|
|
|
|
* If this is the driver's Link Check for this target, ignore
|
|
|
|
* the results of the command. All we care about is whether we
|
|
|
|
* got here from a LINK_CMD_COMPLETE or CMD_COMPLETE message.
|
|
|
|
*/
|
|
|
|
PID("linkcheck");
|
|
|
|
if (reqp->dr_flag & DRIVER_LINKCHK) {
|
|
|
|
if (linked)
|
|
|
|
ncr_will_link |= 1<<reqp->targ_id;
|
|
|
|
else ncr_tprint(reqp, "Does not support linked commands\n");
|
|
|
|
return (0);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* If we not executing an auto-sense and the status code
|
|
|
|
* is request-sense, we automatically issue a request
|
|
|
|
* sense command.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("cautos1");
|
|
|
|
if (!(reqp->dr_flag & DRIVER_AUTOSEN)) {
|
1995-11-30 03:56:23 +03:00
|
|
|
switch (reqp->status & SCSMASK) {
|
|
|
|
case SCSCHKC:
|
|
|
|
bcopy(sense_cmd, &reqp->xcmd, sizeof(sense_cmd));
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xdata_ptr = (u_char *)&reqp->xs->sense;
|
|
|
|
reqp->xdata_len = sizeof(reqp->xs->sense);
|
|
|
|
reqp->dr_flag |= DRIVER_AUTOSEN;
|
|
|
|
reqp->dr_flag &= ~DRIVER_DMAOK;
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!linked) {
|
1995-03-26 11:12:03 +04:00
|
|
|
sps = splbio();
|
|
|
|
reqp->next = issue_q;
|
|
|
|
issue_q = reqp;
|
|
|
|
splx(sps);
|
|
|
|
}
|
1995-12-18 23:37:51 +03:00
|
|
|
else reqp->xcmd.bytes[sizeof(sense_cmd)-2] |= 1;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
#ifdef DBG_REQ
|
1995-08-19 16:36:21 +04:00
|
|
|
bzero(reqp->xdata_ptr, reqp->xdata_len);
|
|
|
|
if (dbg_target_mask & (1 << reqp->targ_id))
|
|
|
|
show_request(reqp, "AUTO-SENSE");
|
1995-03-26 11:12:03 +04:00
|
|
|
#endif
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("cautos2");
|
|
|
|
return (-1);
|
1995-11-30 03:56:23 +03:00
|
|
|
case SCSBUSY:
|
|
|
|
reqp->xs->error = XS_BUSY;
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* An auto-sense has finished
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((reqp->status & SCSMASK) != SCSGOOD)
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xs->error = XS_DRIVER_STUFFUP; /* SC_E_AUTOSEN; */
|
|
|
|
else reqp->xs->error = XS_SENSE;
|
|
|
|
reqp->status = SCSCHKC;
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("cautos3");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1995-08-12 00:01:15 +04:00
|
|
|
reach_msg_out(sc, len)
|
|
|
|
struct ncr_softc *sc;
|
|
|
|
u_long len;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
u_char phase;
|
|
|
|
u_char data;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
ncr_aprint(sc, "Trying to reach Message-out phase\n");
|
|
|
|
if ((phase = GET_5380_REG(NCR5380_IDSTAT)) & SC_S_REQ)
|
1995-03-26 11:12:03 +04:00
|
|
|
phase = (phase >> 2) & 7;
|
1995-08-12 00:01:15 +04:00
|
|
|
else return (-1);
|
|
|
|
ncr_aprint(sc, "Trying to reach Message-out phase, now: %d\n", phase);
|
|
|
|
if (phase == PH_MSGOUT)
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_TCOM, phase);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
do {
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!wait_req_true())
|
1995-03-26 11:12:03 +04:00
|
|
|
break;
|
1995-08-12 00:01:15 +04:00
|
|
|
if (((GET_5380_REG(NCR5380_IDSTAT) >> 2) & 7) != phase)
|
1995-03-26 11:12:03 +04:00
|
|
|
break;
|
1995-08-12 00:01:15 +04:00
|
|
|
if (PH_IN(phase)) {
|
|
|
|
data = GET_5380_REG(NCR5380_DATA);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ACK | SC_A_ATN);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_DATA, 0);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_ADTB|SC_A_ACK|SC_A_ATN);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!wait_req_false())
|
1995-03-26 11:12:03 +04:00
|
|
|
break;
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_ATN);
|
|
|
|
} while (--len);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((phase = GET_5380_REG(NCR5380_IDSTAT)) & SC_S_REQ) {
|
1995-03-26 11:12:03 +04:00
|
|
|
phase = (phase >> 2) & 7;
|
1995-08-12 00:01:15 +04:00
|
|
|
if (phase == PH_MSGOUT) {
|
|
|
|
ncr_aprint(sc, "Message-out phase reached.\n");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
return (-1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1996-02-23 00:07:05 +03:00
|
|
|
void
|
|
|
|
scsi_reset()
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *tmp, *next;
|
1995-08-12 00:01:15 +04:00
|
|
|
int sps;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_reset1");
|
1995-03-26 11:12:03 +04:00
|
|
|
sps = splbio();
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, SC_A_RST);
|
1996-02-11 01:10:45 +03:00
|
|
|
delay(100);
|
1995-08-12 00:01:15 +04:00
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
1996-02-11 01:10:45 +03:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* None of the jobs in the discon_q will ever be reconnected,
|
|
|
|
* notify this to the higher level code.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
for (tmp = discon_q; tmp ;) {
|
1995-03-26 11:12:03 +04:00
|
|
|
next = tmp->next;
|
|
|
|
tmp->next = NULL;
|
|
|
|
tmp->xs->error = XS_TIMEOUT;
|
|
|
|
busy &= ~(1 << tmp->targ_id);
|
|
|
|
finish_req(tmp);
|
|
|
|
tmp = next;
|
|
|
|
}
|
|
|
|
discon_q = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The current job will never finish either.
|
|
|
|
* The problem is that we can't finish the job because an instance
|
|
|
|
* of main is running on it. Our best guess is that the job is currently
|
|
|
|
* doing REAL-DMA. In that case 'dma_ready()' should correctly finish
|
|
|
|
* the job because it detects BSY-loss.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (tmp = connected) {
|
|
|
|
if (tmp->dr_flag & DRIVER_IN_DMA) {
|
1995-03-26 11:12:03 +04:00
|
|
|
tmp->xs->error = XS_DRIVER_STUFFUP;
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
|
|
|
dma_ready();
|
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
PID("scsi_reset2");
|
1996-02-11 01:10:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the attached devices some time to handle the reset. This
|
|
|
|
* value is arbitrary but should be relatively long.
|
|
|
|
*/
|
|
|
|
delay(100000);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1996-02-23 00:07:05 +03:00
|
|
|
static void
|
|
|
|
scsi_reset_verbose(sc, why)
|
|
|
|
struct ncr_softc *sc;
|
|
|
|
const char *why;
|
|
|
|
{
|
|
|
|
ncr_aprint(sc, "Resetting SCSI-bus (%s)\n", why);
|
|
|
|
|
|
|
|
scsi_reset();
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Check validity of the IRQ set by the 5380. If the interrupt is valid,
|
|
|
|
* the appropriate action is carried out (reselection or DMA ready) and
|
|
|
|
* INTR_RESEL or INTR_DMA is returned. Otherwise a console notice is written
|
|
|
|
* and INTR_SPURIOUS is returned.
|
|
|
|
*/
|
|
|
|
static int
|
1995-08-12 00:01:15 +04:00
|
|
|
check_intr(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
SC_REQ *reqp;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((GET_5380_REG(NCR5380_IDSTAT) & (SC_S_SEL|SC_S_IO))
|
|
|
|
==(SC_S_SEL|SC_S_IO))
|
|
|
|
return (INTR_RESEL);
|
1995-03-26 11:12:03 +04:00
|
|
|
else {
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((reqp = connected) && (reqp->dr_flag & DRIVER_IN_DMA)){
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->dr_flag &= ~DRIVER_IN_DMA;
|
1995-08-12 00:01:15 +04:00
|
|
|
return (INTR_DMA);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_clr_ipend();
|
1995-03-26 11:12:03 +04:00
|
|
|
printf("-->");
|
|
|
|
scsi_show();
|
1995-08-12 00:01:15 +04:00
|
|
|
ncr_aprint(sc, "Spurious interrupt.\n");
|
|
|
|
return (INTR_SPURIOUS);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
#ifdef REAL_DMA
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Check if DMA can be used for this request. This function also builds
|
|
|
|
* the dma-chain.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
scsi_dmaok(reqp)
|
|
|
|
SC_REQ *reqp;
|
|
|
|
{
|
|
|
|
u_long phy_buf;
|
|
|
|
u_long phy_len;
|
|
|
|
void *req_addr;
|
|
|
|
u_long req_len;
|
|
|
|
struct dma_chain *dm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize locals and requests' DMA-chain.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
req_len = reqp->xdata_len;
|
|
|
|
req_addr = (void*)reqp->xdata_ptr;
|
|
|
|
dm = reqp->dm_cur = reqp->dm_last = reqp->dm_chain;
|
|
|
|
dm->dm_count = dm->dm_addr = 0;
|
|
|
|
reqp->dr_flag &= ~DRIVER_BOUNCING;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not accept zero length DMA.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if (req_len == 0)
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LWP: I think that this restriction is not strictly nessecary.
|
|
|
|
*/
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((req_len & 0x1) || ((u_int)req_addr & 0x3))
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the DMA-chain.
|
|
|
|
*/
|
|
|
|
dm->dm_addr = phy_buf = kvtop(req_addr);
|
1995-08-12 00:01:15 +04:00
|
|
|
while (req_len) {
|
|
|
|
if (req_len < (phy_len = NBPG - ((u_long)req_addr & PGOFSET)))
|
1995-03-26 11:12:03 +04:00
|
|
|
phy_len = req_len;
|
|
|
|
|
|
|
|
req_addr += phy_len;
|
|
|
|
req_len -= phy_len;
|
|
|
|
dm->dm_count += phy_len;
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (req_len) {
|
1995-03-26 11:12:03 +04:00
|
|
|
u_long tmp = kvtop(req_addr);
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if ((phy_buf + phy_len) != tmp) {
|
|
|
|
if (wrong_dma_range(reqp, dm)) {
|
|
|
|
if (reqp->dr_flag & DRIVER_BOUNCING)
|
|
|
|
goto bounceit;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++dm >= &reqp->dm_chain[MAXDMAIO]) {
|
|
|
|
ncr_tprint(reqp,"dmaok: DMA chain too long!\n");
|
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
dm->dm_count = 0;
|
|
|
|
dm->dm_addr = tmp;
|
|
|
|
}
|
|
|
|
phy_buf = tmp;
|
|
|
|
}
|
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
if (wrong_dma_range(reqp, dm)) {
|
|
|
|
if (reqp->dr_flag & DRIVER_BOUNCING)
|
|
|
|
goto bounceit;
|
|
|
|
return (0);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->dm_last = dm;
|
1995-08-12 00:01:15 +04:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
bounceit:
|
|
|
|
if ((reqp->bounceb = alloc_bounceb(reqp->xdata_len)) == NULL) {
|
|
|
|
/*
|
|
|
|
* If we can't get a bounce buffer, forget DMA
|
|
|
|
*/
|
|
|
|
reqp->dr_flag &= ~DRIVER_BOUNCING;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Initialize a single DMA-range containing the bounced request
|
|
|
|
*/
|
|
|
|
dm = reqp->dm_cur = reqp->dm_last = reqp->dm_chain;
|
|
|
|
dm->dm_addr = kvtop(reqp->bounceb);
|
|
|
|
dm->dm_count = reqp->xdata_len;
|
|
|
|
reqp->bouncerp = reqp->bounceb;
|
|
|
|
|
|
|
|
return (1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-08-12 00:01:15 +04:00
|
|
|
#endif /* REAL_DMA */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
static void
|
1995-08-12 00:01:15 +04:00
|
|
|
run_main(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
int sps = splbio();
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
if (!main_running) {
|
|
|
|
/*
|
|
|
|
* If shared resources are required, claim them
|
|
|
|
* before entering 'scsi_main'. If we can't get them
|
|
|
|
* now, assume 'run_main' will be called when the resource
|
|
|
|
* becomes available.
|
|
|
|
*/
|
|
|
|
if (!claimed_dma()) {
|
|
|
|
splx(sps);
|
|
|
|
return;
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
main_running = 1;
|
|
|
|
splx(sps);
|
1995-08-12 00:01:15 +04:00
|
|
|
scsi_main(sc);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
else splx(sps);
|
|
|
|
}
|
|
|
|
|
1995-08-12 00:01:15 +04:00
|
|
|
/*
|
|
|
|
* Prefix message with full target info.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ncr_tprint(SC_REQ *reqp, char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
sc_print_addr(reqp->xs->sc_link);
|
1996-03-31 00:01:21 +03:00
|
|
|
printf("%:", fmt, ap);
|
1995-08-12 00:01:15 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prefix message with adapter info.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ncr_aprint(struct ncr_softc *sc, char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
1996-03-31 00:01:21 +03:00
|
|
|
printf("%s : %:", sc->sc_dev.dv_xname, fmt, ap);
|
1995-08-12 00:01:15 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
/****************************************************************************
|
|
|
|
* Start Debugging Functions *
|
|
|
|
****************************************************************************/
|
|
|
|
static void
|
|
|
|
show_data_sense(xs)
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
{
|
1995-08-19 16:36:21 +04:00
|
|
|
u_char *p1, *p2;
|
1995-03-26 11:12:03 +04:00
|
|
|
int i;
|
|
|
|
int sz;
|
|
|
|
|
1995-08-19 16:36:21 +04:00
|
|
|
p1 = (u_char *) xs->cmd;
|
|
|
|
p2 = (u_char *)&xs->sense;
|
|
|
|
if(*p2 == 0)
|
|
|
|
return; /* No(n)sense */
|
|
|
|
printf("cmd[%d,%d]: ", xs->cmdlen, sz = command_size(*p1));
|
1995-08-12 00:01:15 +04:00
|
|
|
for (i = 0; i < sz; i++)
|
1995-08-19 16:36:21 +04:00
|
|
|
printf("%x ", p1[i]);
|
1995-03-26 11:12:03 +04:00
|
|
|
printf("\nsense: ");
|
1995-08-12 00:01:15 +04:00
|
|
|
for (i = 0; i < sizeof(xs->sense); i++)
|
1995-08-19 16:36:21 +04:00
|
|
|
printf("%x ", p2[i]);
|
1995-03-26 11:12:03 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_request(reqp, qtxt)
|
|
|
|
SC_REQ *reqp;
|
|
|
|
char *qtxt;
|
|
|
|
{
|
1996-02-23 00:07:05 +03:00
|
|
|
printf("REQ-%s: %d %p[%d] cmd[0]=%x S=%x M=%x R=%x resid=%d dr_flag=%x %s\n",
|
1995-08-19 16:36:21 +04:00
|
|
|
qtxt, reqp->targ_id, reqp->xdata_ptr, reqp->xdata_len,
|
1995-03-26 11:12:03 +04:00
|
|
|
reqp->xcmd.opcode, reqp->status, reqp->message,
|
1995-12-18 23:37:51 +03:00
|
|
|
reqp->xs->error, reqp->xs->resid, reqp->dr_flag,
|
|
|
|
reqp->link ? "L":"");
|
1995-08-12 00:01:15 +04:00
|
|
|
if (reqp->status == SCSCHKC)
|
1995-03-26 11:12:03 +04:00
|
|
|
show_data_sense(reqp->xs);
|
|
|
|
}
|
|
|
|
|
1995-09-12 23:58:53 +04:00
|
|
|
static char *sig_names[] = {
|
|
|
|
"PAR", "SEL", "I/O", "C/D", "MSG", "REQ", "BSY", "RST",
|
|
|
|
"ACK", "ATN", "LBSY", "PMATCH", "IRQ", "EPAR", "DREQ", "EDMA"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_signals(dmstat, idstat)
|
|
|
|
u_char dmstat, idstat;
|
|
|
|
{
|
|
|
|
u_short tmp, mask;
|
1996-02-23 00:07:05 +03:00
|
|
|
int j, need_pipe;
|
1995-09-12 23:58:53 +04:00
|
|
|
|
|
|
|
tmp = idstat | ((dmstat & 3) << 8);
|
|
|
|
printf("Bus signals (%02x/%02x): ", idstat, dmstat & 3);
|
|
|
|
for (mask = 1, j = need_pipe = 0; mask <= tmp; mask <<= 1, j++) {
|
|
|
|
if (tmp & mask)
|
|
|
|
printf("%s%s", need_pipe++ ? "|" : "", sig_names[j]);
|
|
|
|
}
|
|
|
|
printf("\nDma status (%02x): ", dmstat);
|
|
|
|
for (mask = 4, j = 10, need_pipe = 0; mask <= dmstat; mask <<= 1, j++) {
|
|
|
|
if (dmstat & mask)
|
|
|
|
printf("%s%s", need_pipe++ ? "|" : "", sig_names[j]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
1996-02-23 00:07:05 +03:00
|
|
|
void
|
1995-03-26 11:12:03 +04:00
|
|
|
scsi_show()
|
|
|
|
{
|
|
|
|
SC_REQ *tmp;
|
|
|
|
int sps = splhigh();
|
1995-09-12 23:58:53 +04:00
|
|
|
u_char idstat, dmstat;
|
1996-01-06 23:17:15 +03:00
|
|
|
int i;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1996-02-23 00:07:05 +03:00
|
|
|
printf("scsi_show: main_running is%s running\n",
|
|
|
|
main_running ? "" : " not");
|
1995-08-12 00:01:15 +04:00
|
|
|
for (tmp = issue_q; tmp; tmp = tmp->next)
|
1995-03-26 11:12:03 +04:00
|
|
|
show_request(tmp, "ISSUED");
|
1995-08-12 00:01:15 +04:00
|
|
|
for (tmp = discon_q; tmp; tmp = tmp->next)
|
1995-03-26 11:12:03 +04:00
|
|
|
show_request(tmp, "DISCONNECTED");
|
1995-08-12 00:01:15 +04:00
|
|
|
if (connected)
|
1995-03-26 11:12:03 +04:00
|
|
|
show_request(connected, "CONNECTED");
|
1995-09-12 23:58:53 +04:00
|
|
|
idstat = GET_5380_REG(NCR5380_IDSTAT);
|
|
|
|
dmstat = GET_5380_REG(NCR5380_DMSTAT);
|
|
|
|
show_signals(dmstat, idstat);
|
1995-08-12 00:01:15 +04:00
|
|
|
if (connected)
|
1995-03-26 11:12:03 +04:00
|
|
|
printf("phase = %d, ", connected->phase);
|
1996-01-06 23:17:15 +03:00
|
|
|
printf("busy:%x, spl:%04x\n", busy, sps);
|
|
|
|
#ifdef DBG_PID
|
|
|
|
for (i=0; i<DBG_PID; i++)
|
|
|
|
printf("\t%d\t%s\n", i, last_hit[i]);
|
|
|
|
#endif
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
splx(sps);
|
|
|
|
}
|