1994-11-17 20:22:31 +00:00
|
|
|
/*
|
1995-01-13 02:24:31 +00:00
|
|
|
* Generic driver for the aic7xxx based adaptec SCSI controllers
|
|
|
|
* Product specific probe and attach routines can be found in:
|
1996-01-03 06:32:12 +00:00
|
|
|
* i386/eisa/aic7770.c 27/284X and aic7770 motherboard controllers
|
1996-10-25 06:42:53 +00:00
|
|
|
* pci/aic7870.c 3940, 2940, aic7880, aic7870, aic7860,
|
|
|
|
* and aic7850 controllers
|
1995-01-13 02:24:31 +00:00
|
|
|
*
|
1997-01-29 05:27:03 +00:00
|
|
|
* Copyright (c) 1994, 1995, 1996, 1997 Justin T. Gibbs.
|
1996-04-20 21:29:27 +00:00
|
|
|
* All rights reserved.
|
1994-11-17 20:22:31 +00:00
|
|
|
*
|
1996-04-20 21:29:27 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* this list of conditions, and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
1994-11-17 20:22:31 +00:00
|
|
|
*
|
1996-04-20 21:29:27 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
1994-11-17 20:22:31 +00:00
|
|
|
*
|
1997-03-16 07:12:07 +00:00
|
|
|
* $Id: aic7xxx.c,v 1.105 1997/03/01 06:50:41 gibbs Exp $
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* Implement Target Mode
|
|
|
|
*
|
1996-10-25 06:42:53 +00:00
|
|
|
* A few notes on features of the driver.
|
1996-04-20 21:29:27 +00:00
|
|
|
*
|
|
|
|
* SCB paging takes advantage of the fact that devices stay disconnected
|
|
|
|
* from the bus a relatively long time and that while they're disconnected,
|
1996-10-25 06:42:53 +00:00
|
|
|
* having the SCBs for these transactions down on the host adapter is of
|
|
|
|
* little use. Instead of leaving this idle SCB down on the card we copy
|
|
|
|
* it back up into kernel memory and reuse the SCB slot on the card to
|
|
|
|
* schedule another transaction. This can be a real payoff when doing random
|
|
|
|
* I/O to tagged queueing devices since there are more transactions active at
|
|
|
|
* once for the device to sort for optimal seek reduction. The algorithm goes
|
|
|
|
* like this...
|
1996-04-20 21:29:27 +00:00
|
|
|
*
|
1996-10-25 06:42:53 +00:00
|
|
|
* The sequencer maintains two lists of its hardware SCBs. The first is the
|
|
|
|
* singly linked free list which tracks all SCBs that are not currently in
|
|
|
|
* use. The second is the doubly linked disconnected list which holds the
|
|
|
|
* SCBs of transactions that are in the disconnected state sorted most
|
|
|
|
* recently disconnected first. When the kernel queues a transaction to
|
|
|
|
* the card, a hardware SCB to "house" this transaction is retrieved from
|
|
|
|
* either of these two lists. If the SCB came from the disconnected list,
|
|
|
|
* a check is made to see if any data transfer or SCB linking (more on linking
|
|
|
|
* in a bit) information has been changed since it was copied from the host
|
|
|
|
* and if so, DMAs the SCB back up before it can be used. Once a hardware
|
|
|
|
* SCB has been obtained, the SCB is DMAed from the host. Before any work
|
|
|
|
* can begin on this SCB, the sequencer must ensure that either the SCB is
|
|
|
|
* for a tagged transaction or the target is not already working on another
|
|
|
|
* non-tagged transaction. If a conflict arises in the non-tagged case, the
|
|
|
|
* sequencer finds the SCB for the active transactions and sets the SCB_LINKED
|
|
|
|
* field in that SCB to this next SCB to execute. To facilitate finding
|
|
|
|
* active non-tagged SCBs, the last four bytes of up to the first four hardware
|
|
|
|
* SCBs serve as a storage area for the currently active SCB ID for each
|
|
|
|
* target.
|
1996-04-20 21:29:27 +00:00
|
|
|
*
|
1996-10-25 06:42:53 +00:00
|
|
|
* When a device reconnects, a search is made of the hardware SCBs to find
|
|
|
|
* the SCB for this transaction. If the search fails, a hardware SCB is
|
|
|
|
* pulled from either the free or disconnected SCB list and the proper
|
|
|
|
* SCB is DMAed from the host. If the SCB_ABORTED control bit is set
|
|
|
|
* in the control byte of the SCB while it was disconnected, the sequencer
|
|
|
|
* will send an abort or abort tag message to the target during the
|
|
|
|
* reconnection and signal the kernel that the abort was successfull.
|
1996-04-20 21:29:27 +00:00
|
|
|
*
|
1996-10-25 06:42:53 +00:00
|
|
|
* When a command completes, a check for non-zero status and residuals is
|
|
|
|
* made. If either of these conditions exists, the SCB is DMAed back up to
|
|
|
|
* the host so that it can interpret this information. Additionally, in the
|
|
|
|
* case of bad status, the sequencer generates a special interrupt and pauses
|
|
|
|
* itself. This allows the host to setup a request sense command if it
|
|
|
|
* chooses for this target synchronously with the error so that sense
|
|
|
|
* information isn't lost.
|
1996-04-20 21:29:27 +00:00
|
|
|
*
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
#endif /* defined(__NetBSD__) */
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
#include <scsi/scsi_all.h>
|
1996-10-06 16:38:45 +00:00
|
|
|
#include <scsi/scsi_message.h>
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <scsi/scsi_debug.h>
|
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
#include <scsi/scsiconf.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1995-03-07 08:59:28 +00:00
|
|
|
#include <machine/clock.h>
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1995-12-06 23:52:35 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1995-01-13 02:27:08 +00:00
|
|
|
#include <i386/scsi/aic7xxx.h>
|
1997-03-16 07:12:07 +00:00
|
|
|
#include <dev/aic7xxx/sequencer.h>
|
|
|
|
#include <aic7xxx_reg.h>
|
|
|
|
#include <aic7xxx_seq.h>
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif /* defined(__FreeBSD__) */
|
|
|
|
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <dev/ic/aic7xxxreg.h>
|
|
|
|
#include <dev/ic/aic7xxxvar.h>
|
|
|
|
|
|
|
|
#define bootverbose 1
|
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
#if DEBUGTARGET < 0 /* Negative numbers for disabling cause warnings */
|
1996-10-25 06:42:53 +00:00
|
|
|
#define DEBUGTARGET 17
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
|
|
|
#endif /* defined(__NetBSD__) */
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
1996-10-25 06:42:53 +00:00
|
|
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
1995-07-31 08:25:36 +00:00
|
|
|
#define ALL_TARGETS -1
|
1997-02-25 03:05:35 +00:00
|
|
|
#define ALL_LUNS -1
|
1997-01-29 05:27:03 +00:00
|
|
|
#define ALL_CHANNELS '\0'
|
Fixes to the aic7xxx sequencer code and device driver from Justin Gibbs:
1) If a target initiated a sync negotiation with us and happened to chose a
value above 15, the old code inadvertantly truncated it with an "& 0x0f".
If the periferal picked something really bad like 0x32, you'd end up with
an offset of 2 which would hang the drive since it didn't expect to ever
get something so low. We now do a MIN(maxoffset, given_offset).
2) In the case of Wide cards, we were turning on sync transfers after a
sucessfull wide negotiation. Now we leave the offset alone in the per
target scratch space (which implies asyncronous transfers since we initialize
it that way) until a syncronous negotation occurs.
3) We were advertizing a max offset of 15 instead of 8 for wide devices.
4) If the upper level SCSI code sent down a "SCSI_RESET", it would hang the
system because we would end up sending a null command to the sequencer. Now
we handle SCSI_RESET correctly by having the sequencer interrupt us when it
is about to fill the message buffer so that we can fill it in ourselves.
The sequencer will also "simulate" a command complete for these "message only"
SCBs so that the kernel driver can finish up properly. The cdplay utility
will send a "SCSI_REST" to the cdplayer if you use the reset command.
5) The code that handles SCSIINTs was broken in that if more than one type
of error was true at once, we'd do outbs without the card being paused.
The else clause after the busfree case was also an accident waiting to
happen. I've now turned this into an if, else if, else type of thing, since
in most cases when we handle one type of error, it should be okay to ignore
the rest (ie if we have a SELTO, who cares if there was a parity error on
the transaction?), but the section should really be rewritten after 2.0.5.
This fix was the least obtrusive way to patch the problem.
6) Only tag either SDTR or WDTR negotiation on an SCB. The real problem is
that I don't account for the case when an SCB that is tagged to do a particular
type of negotiation completes or SELTOs (selection timeout) without the
negotiation taking place, so the accounting of sdtrpending and wdtrpending
gets screwed up. In the wide case, if we tag it to do both wdtr and sdtr,
it only performs wdtr (since wdtr must occur first and we spread out the
negotiation over two commands) so we always have sdtrpending set for that
target and we never do a real SDTR. I fill properly fix the accounting
after 2.0.5 goes out the door, but this works (as confirmed by Dan) on
wide targets.
Other stuff that is also included:
1) Don't do a bzero when recycling SCBs. The only thing that must explicitly
be set to zero is the scb control byte which is done in ahc_get_scb. We also
need to set the SG_list_pointer and SG_list_count to 0 for commands that do
not transfer data.
2) Mask the interrupt type printout for the aic7870 case. The bit we were
using to determine interrupt type is only valid for the aic7770.
Submitted by: Justin Gibbs
1995-05-17 07:06:02 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1995-11-06 05:21:13 +00:00
|
|
|
u_long ahc_unit = 0;
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-04-20 21:29:27 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1996-05-30 07:19:59 +00:00
|
|
|
static int ahc_debug = AHC_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AHC_BROKEN_CACHE
|
|
|
|
int ahc_broken_cache = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "wbinvd" cause writing back whole cache (both CPU internal & external)
|
|
|
|
* to memory, so that the instruction takes a lot of time.
|
|
|
|
* This makes machine slow.
|
|
|
|
*/
|
|
|
|
#define INVALIDATE_CACHE() __asm __volatile("wbinvd")
|
1996-04-20 21:29:27 +00:00
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
/**** bit definitions for SCSIDEF ****/
|
1995-01-13 02:24:31 +00:00
|
|
|
#define HSCSIID 0x07 /* our SCSI ID */
|
|
|
|
#define HWSCSIID 0x0f /* our SCSI ID if Wide Bus */
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
static void ahcminphys __P((struct buf *bp));
|
|
|
|
static int32_t ahc_scsi_cmd __P((struct scsi_xfer *xs));
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_run_waiting_queue __P((struct ahc_softc *ahc));
|
1996-10-25 06:42:53 +00:00
|
|
|
static struct scb *
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc_get_scb __P((struct ahc_softc *ahc, u_int32_t flags));
|
|
|
|
static void ahc_free_scb __P((struct ahc_softc *ahc, struct scb *scb));
|
1996-10-25 06:42:53 +00:00
|
|
|
static struct scb *
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc_alloc_scb __P((struct ahc_softc *ahc));
|
|
|
|
static inline void pause_sequencer __P((struct ahc_softc *ahc));
|
|
|
|
static inline void unpause_sequencer __P((struct ahc_softc *ahc,
|
1996-10-06 16:38:45 +00:00
|
|
|
int unpause_always));
|
1996-10-28 06:10:02 +00:00
|
|
|
static inline void restart_sequencer __P((struct ahc_softc *ahc));
|
1995-12-15 23:49:42 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
static int timeouts_work; /*
|
|
|
|
* Boolean that lets the driver know
|
|
|
|
* that it can safely use timeouts
|
|
|
|
* for event scheduling. Timeouts
|
|
|
|
* don't work early in the boot
|
1997-02-25 03:05:35 +00:00
|
|
|
* process.
|
1997-01-29 05:27:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define AHC_BUSRESET_DELAY 1000 /* Reset delay in us */
|
|
|
|
#define AHC_BUSSETTLE_DELAY (100 * 1000)/* Delay before taking commands
|
|
|
|
* after a reset in us
|
|
|
|
*/
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static struct scsi_adapter ahc_switch =
|
1995-05-30 08:16:23 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc_scsi_cmd,
|
|
|
|
ahcminphys,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-10-25 06:42:53 +00:00
|
|
|
NULL,
|
|
|
|
"ahc",
|
|
|
|
{ 0, 0 }
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1995-05-30 08:16:23 +00:00
|
|
|
};
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static struct scsi_device ahc_dev =
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
NULL, /* Use default error handler */
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL, /* Use default 'done' routine */
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-10-25 06:42:53 +00:00
|
|
|
"ahc",
|
|
|
|
0,
|
|
|
|
{ 0, 0 }
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
};
|
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
static inline void
|
|
|
|
pause_sequencer(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
{
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, HCNTRL, ahc->pause);
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the sequencer can disable pausing in a critical section, we
|
|
|
|
* must loop until it actually stops.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
while ((ahc_inb(ahc, HCNTRL) & PAUSE) == 0)
|
1996-01-03 06:32:12 +00:00
|
|
|
;
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
static inline void
|
|
|
|
unpause_sequencer(ahc, unpause_always)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
int unpause_always;
|
|
|
|
{
|
|
|
|
if (unpause_always
|
1996-11-11 05:24:46 +00:00
|
|
|
|| (ahc_inb(ahc, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) == 0)
|
|
|
|
ahc_outb(ahc, HCNTRL, ahc->unpause);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restart the sequencer program from address zero
|
|
|
|
*/
|
1996-10-06 16:38:45 +00:00
|
|
|
static inline void
|
|
|
|
restart_sequencer(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
{
|
|
|
|
do {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SEQCTL, SEQRESET|FASTMODE);
|
|
|
|
} while ((ahc_inb(ahc, SEQADDR0) != 0)
|
|
|
|
|| (ahc_inb(ahc, SEQADDR1) != 0));
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
|
|
|
}
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#define IS_SCSIBUS_B(ahc, sc_link) \
|
1997-02-09 03:26:56 +00:00
|
|
|
(((u_int32_t)((sc_link)->fordriver) & SELBUSB) != 0)
|
1996-10-25 06:42:53 +00:00
|
|
|
#else /* NetBSD/OpenBSD */
|
1996-05-30 07:19:59 +00:00
|
|
|
#define IS_SCSIBUS_B(ahc, sc_link) \
|
|
|
|
((sc_link)->scsibus == (ahc)->sc_link_b.scsibus)
|
|
|
|
#endif
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
static u_int8_t ahc_abort_wscb __P((struct ahc_softc *ahc, struct scb *scbp,
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t scbpos, u_int8_t prev,
|
|
|
|
u_int32_t xs_error));
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_done __P((struct ahc_softc *ahc, struct scb *scbp));
|
|
|
|
static void ahc_handle_seqint __P((struct ahc_softc *ahc, u_int8_t intstat));
|
|
|
|
static void ahc_handle_scsiint __P((struct ahc_softc *ahc,
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t intstat));
|
1996-11-22 08:28:45 +00:00
|
|
|
static void ahc_handle_devreset __P((struct ahc_softc *ahc,
|
|
|
|
struct scb *scb));
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_loadseq __P((struct ahc_softc *ahc));
|
1997-03-16 07:12:07 +00:00
|
|
|
static struct patch *
|
|
|
|
ahc_next_patch __P((struct patch *cur_patch, int options,
|
|
|
|
int instrptr));
|
|
|
|
static void ahc_download_instr __P((struct ahc_softc *ahc, int options,
|
|
|
|
int instrptr));
|
1997-01-29 05:27:03 +00:00
|
|
|
static int ahc_match_scb __P((struct scb *scb, int target, char channel,
|
1997-02-25 03:05:35 +00:00
|
|
|
int lun, u_int8_t tag));
|
1996-10-28 06:10:02 +00:00
|
|
|
static int ahc_poll __P((struct ahc_softc *ahc, int wait));
|
1995-12-15 23:49:42 +00:00
|
|
|
#ifdef AHC_DEBUG
|
|
|
|
static void ahc_print_scb __P((struct scb *scb));
|
|
|
|
#endif
|
1997-02-03 16:29:07 +00:00
|
|
|
static u_int8_t ahc_find_scb __P((struct ahc_softc *ahc, struct scb *scb));
|
1997-02-09 03:26:56 +00:00
|
|
|
static int ahc_search_qinfifo __P((struct ahc_softc *ahc, int target,
|
1997-02-25 03:05:35 +00:00
|
|
|
char channel, int lun, u_int8_t tag,
|
1997-02-09 03:26:56 +00:00
|
|
|
u_int32_t flags, u_int32_t xs_error,
|
|
|
|
int requeue));
|
1996-10-28 06:10:02 +00:00
|
|
|
static int ahc_reset_channel __P((struct ahc_softc *ahc, char channel,
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int32_t xs_error, int initiate_reset));
|
1996-10-28 06:10:02 +00:00
|
|
|
static int ahc_reset_device __P((struct ahc_softc *ahc, int target,
|
1997-02-25 03:05:35 +00:00
|
|
|
char channel, int lun, u_int8_t tag,
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
u_int32_t xs_error));
|
1997-02-25 03:05:35 +00:00
|
|
|
static u_int8_t ahc_rem_scb_from_disc_list __P((struct ahc_softc *ahc,
|
1997-02-28 03:58:21 +00:00
|
|
|
u_int8_t scbptr));
|
|
|
|
static void ahc_add_curscb_to_free_list __P((struct ahc_softc *ahc));
|
|
|
|
static void ahc_clear_intstat __P((struct ahc_softc *ahc));
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_reset_current_bus __P((struct ahc_softc *ahc));
|
|
|
|
static void ahc_run_done_queue __P((struct ahc_softc *ahc));
|
|
|
|
static void ahc_scsirate __P((struct ahc_softc* ahc, u_int8_t *scsirate,
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int8_t *period, u_int8_t *offset,
|
|
|
|
char channel, int target));
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1995-12-15 23:49:42 +00:00
|
|
|
static timeout_t
|
|
|
|
ahc_timeout;
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
static void ahc_timeout __P((void *));
|
|
|
|
#endif
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
static timeout_t
|
|
|
|
ahc_first_timeout;
|
|
|
|
|
|
|
|
static timeout_t
|
|
|
|
ahc_busreset_complete;
|
|
|
|
|
|
|
|
static timeout_t
|
|
|
|
ahc_busreset_settle_complete;
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
static u_int8_t ahc_index_busy_target __P((struct ahc_softc *ahc, int target,
|
|
|
|
char channel, int unbusy));
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1997-03-01 06:50:41 +00:00
|
|
|
static void ahc_busy_target __P((struct ahc_softc *ahc, int target,
|
|
|
|
char channel, u_int8_t scbid));
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_construct_sdtr __P((struct ahc_softc *ahc, int start_byte,
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t period, u_int8_t offset));
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
static void ahc_construct_wdtr __P((struct ahc_softc *ahc, int start_byte,
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int8_t bus_width));
|
1996-05-30 07:19:59 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
static void ahc_calc_residual __P((struct scb *scb));
|
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
|
|
|
|
char *ahc_name(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-05-30 07:19:59 +00:00
|
|
|
{
|
|
|
|
static char name[10];
|
|
|
|
|
|
|
|
sprintf(name, "ahc%d", ahc->unit);
|
|
|
|
return (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
struct cfdriver ahc_cd = {
|
|
|
|
NULL, "ahc", DV_DULL
|
|
|
|
};
|
|
|
|
#endif
|
1995-12-15 23:49:42 +00:00
|
|
|
|
1995-02-22 01:43:25 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc_print_scb(scb)
|
|
|
|
struct scb *scb;
|
|
|
|
{
|
1996-11-11 05:24:46 +00:00
|
|
|
struct hardware_scb *hscb = scb->hscb;
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("scb:%p control:0x%x tcl:0x%x cmdlen:%d cmdpointer:0x%lx\n",
|
|
|
|
scb,
|
1996-11-11 05:24:46 +00:00
|
|
|
hscb->control,
|
|
|
|
hscb->tcl,
|
|
|
|
hscb->cmdlen,
|
|
|
|
hscb->cmdpointer );
|
1996-10-25 06:42:53 +00:00
|
|
|
printf(" datlen:%d data:0x%lx segs:0x%x segp:0x%lx\n",
|
1996-11-11 05:24:46 +00:00
|
|
|
hscb->datalen,
|
|
|
|
hscb->data,
|
|
|
|
hscb->SG_segment_count,
|
|
|
|
hscb->SG_list_pointer);
|
1996-10-25 06:42:53 +00:00
|
|
|
printf(" sg_addr:%lx sg_len:%ld\n",
|
1996-11-11 05:24:46 +00:00
|
|
|
hscb->ahc_dma[0].addr,
|
|
|
|
hscb->ahc_dma[0].len);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1995-02-22 01:43:25 +00:00
|
|
|
#endif
|
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
static struct {
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t errno;
|
1994-11-17 20:22:31 +00:00
|
|
|
char *errmesg;
|
|
|
|
} hard_error[] = {
|
1995-03-07 08:59:28 +00:00
|
|
|
{ ILLHADDR, "Illegal Host Access" },
|
|
|
|
{ ILLSADDR, "Illegal Sequencer Address referrenced" },
|
|
|
|
{ ILLOPCODE, "Illegal Opcode in sequencer program" },
|
|
|
|
{ PARERR, "Sequencer Ram Parity Error" }
|
1995-05-30 08:16:23 +00:00
|
|
|
};
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Valid SCSIRATE values. (p. 3-17)
|
|
|
|
* Provides a mapping of tranfer periods in ns to the proper value to
|
|
|
|
* stick in the scsiscfr reg to use that transfer rate.
|
|
|
|
*/
|
|
|
|
static struct {
|
1996-10-25 06:42:53 +00:00
|
|
|
int sxfr;
|
1995-10-26 23:57:18 +00:00
|
|
|
/* Rates in Ultra mode have bit 8 of sxfr set */
|
|
|
|
#define ULTRA_SXFR 0x100
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t period; /* Period to send to SCSI target */
|
1994-11-17 20:22:31 +00:00
|
|
|
char *rate;
|
|
|
|
} ahc_syncrates[] = {
|
1996-10-06 16:38:45 +00:00
|
|
|
{ 0x100, 12, "20.0" },
|
|
|
|
{ 0x110, 15, "16.0" },
|
|
|
|
{ 0x120, 18, "13.4" },
|
|
|
|
{ 0x000, 25, "10.0" },
|
|
|
|
{ 0x010, 31, "8.0" },
|
|
|
|
{ 0x020, 37, "6.67" },
|
|
|
|
{ 0x030, 43, "5.7" },
|
|
|
|
{ 0x040, 50, "5.0" },
|
|
|
|
{ 0x050, 56, "4.4" },
|
|
|
|
{ 0x060, 62, "4.0" },
|
|
|
|
{ 0x070, 68, "3.6" }
|
1994-11-17 20:22:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ahc_num_syncrates =
|
|
|
|
sizeof(ahc_syncrates) / sizeof(ahc_syncrates[0]);
|
|
|
|
|
|
|
|
/*
|
1997-03-16 07:12:07 +00:00
|
|
|
* Allocate a controller structure for a new device and initialize it.
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *
|
|
|
|
ahc_alloc(unit, iobase, maddr, type, flags, scb_data)
|
1995-01-13 02:24:31 +00:00
|
|
|
int unit;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int32_t iobase;
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
void
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc_construct(ahc, bc, ioh, maddr, type, flags)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-05-30 07:19:59 +00:00
|
|
|
bus_chipset_tag_t bc;
|
|
|
|
bus_io_handle_t ioh;
|
|
|
|
#endif
|
1996-10-25 06:42:53 +00:00
|
|
|
vm_offset_t maddr;
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc_type type;
|
1995-09-05 23:52:03 +00:00
|
|
|
ahc_flag flags;
|
1996-10-28 06:10:02 +00:00
|
|
|
struct scb_data *scb_data;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-01-03 06:32:12 +00:00
|
|
|
/*
|
|
|
|
* find unit and check we have that many defined
|
|
|
|
*/
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
|
|
|
size_t alloc_size;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-01-03 06:32:12 +00:00
|
|
|
/*
|
|
|
|
* Allocate a storage area for us
|
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
if (scb_data == NULL)
|
|
|
|
/*
|
|
|
|
* We are not sharing SCB space with another controller
|
|
|
|
* so allocate our own SCB data space.
|
|
|
|
*/
|
|
|
|
alloc_size = sizeof(struct full_ahc_softc);
|
|
|
|
else
|
|
|
|
alloc_size = sizeof(struct ahc_softc);
|
|
|
|
ahc = malloc(alloc_size, M_DEVBUF, M_NOWAIT);
|
1996-01-03 06:32:12 +00:00
|
|
|
if (!ahc) {
|
|
|
|
printf("ahc%d: cannot malloc!\n", unit);
|
|
|
|
return NULL;
|
|
|
|
}
|
1996-10-28 06:10:02 +00:00
|
|
|
bzero(ahc, alloc_size);
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1996-10-28 06:10:02 +00:00
|
|
|
if (scb_data == NULL) {
|
|
|
|
struct full_ahc_softc* full_softc = (struct full_ahc_softc*)ahc;
|
|
|
|
ahc->scb_data = &full_softc->scb_data_storage;
|
|
|
|
STAILQ_INIT(&ahc->scb_data->free_scbs);
|
|
|
|
} else
|
|
|
|
ahc->scb_data = scb_data;
|
1996-04-20 21:29:27 +00:00
|
|
|
STAILQ_INIT(&ahc->waiting_scbs);
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-04-20 21:29:27 +00:00
|
|
|
ahc->unit = unit;
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
1996-04-20 21:29:27 +00:00
|
|
|
ahc->baseport = iobase;
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
ahc->sc_bc = bc;
|
|
|
|
ahc->sc_ioh = ioh;
|
|
|
|
#endif
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc->maddr = (volatile u_int8_t *)maddr;
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc->type = type;
|
1995-09-05 23:52:03 +00:00
|
|
|
ahc->flags = flags;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->unpause = (ahc_inb(ahc, HCNTRL) & IRQMS) | INTEN;
|
1995-11-05 04:50:55 +00:00
|
|
|
ahc->pause = ahc->unpause | PAUSE;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1997-02-03 02:16:16 +00:00
|
|
|
ahc->busreset_args.ahc = ahc;
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc->busreset_args.bus = 'A';
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc->busreset_args_b.ahc = ahc;
|
|
|
|
ahc->busreset_args_b.bus = 'B';
|
1997-01-29 05:27:03 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-01-03 06:32:12 +00:00
|
|
|
return (ahc);
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1995-11-05 04:50:55 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1995-11-05 04:50:55 +00:00
|
|
|
void
|
|
|
|
ahc_free(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1995-11-05 04:50:55 +00:00
|
|
|
{
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1995-11-05 04:50:55 +00:00
|
|
|
free(ahc, M_DEVBUF);
|
|
|
|
return;
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1995-11-05 04:50:55 +00:00
|
|
|
void
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_reset(ahc)
|
|
|
|
struct ahc_softc *ahc;
|
1995-11-05 04:50:55 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t hcntrl;
|
1995-11-05 04:50:55 +00:00
|
|
|
int wait;
|
|
|
|
|
|
|
|
/* Retain the IRQ type accross the chip reset */
|
1996-11-11 05:24:46 +00:00
|
|
|
hcntrl = (ahc_inb(ahc, HCNTRL) & IRQMS) | INTEN;
|
1996-05-30 07:19:59 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, HCNTRL, CHIPRST | PAUSE);
|
1995-11-05 04:50:55 +00:00
|
|
|
/*
|
|
|
|
* Ensure that the reset has finished
|
|
|
|
*/
|
|
|
|
wait = 1000;
|
1996-11-11 05:24:46 +00:00
|
|
|
while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK))
|
1995-11-05 04:50:55 +00:00
|
|
|
DELAY(1000);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (wait == 0) {
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: WARNING - Failed chip reset! "
|
1996-11-11 05:24:46 +00:00
|
|
|
"Trying to initialize anyway.\n", ahc_name(ahc));
|
1995-11-05 04:50:55 +00:00
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, HCNTRL, hcntrl | PAUSE);
|
1995-11-05 04:50:55 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up the valid period to SCSIRATE conversion in our table.
|
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1996-05-21 18:37:25 +00:00
|
|
|
ahc_scsirate(ahc, scsirate, period, offset, channel, target )
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int8_t *scsirate;
|
|
|
|
u_int8_t *period;
|
|
|
|
u_int8_t *offset;
|
|
|
|
char channel;
|
|
|
|
int target;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-01-03 06:32:12 +00:00
|
|
|
int i;
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int32_t ultra_enb_addr;
|
|
|
|
u_int8_t sxfrctl0;
|
|
|
|
u_int8_t ultra_enb;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
i = ahc_num_syncrates; /* Default to async */
|
|
|
|
|
|
|
|
if (*period >= ahc_syncrates[0].period && *offset != 0) {
|
|
|
|
for (i = 0; i < ahc_num_syncrates; i++) {
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
if (*period <= ahc_syncrates[i].period) {
|
1996-05-21 18:37:25 +00:00
|
|
|
/*
|
1996-10-06 16:38:45 +00:00
|
|
|
* Watch out for Ultra speeds when ultra is not
|
|
|
|
* enabled and vice-versa.
|
1996-05-21 18:37:25 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if (!(ahc->type & AHC_ULTRA)
|
|
|
|
&& (ahc_syncrates[i].sxfr & ULTRA_SXFR)) {
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* This should only happen if the
|
|
|
|
* drive is the first to negotiate
|
|
|
|
* and chooses a high rate. We'll
|
|
|
|
* just move down the table util
|
|
|
|
* we hit a non ultra speed.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*scsirate = (ahc_syncrates[i].sxfr & 0xF0)
|
|
|
|
| (*offset & 0x0f);
|
|
|
|
*period = ahc_syncrates[i].period;
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
printf("%s: target %d synchronous at "
|
|
|
|
"%sMHz, offset = 0x%x\n",
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_name(ahc), target,
|
|
|
|
ahc_syncrates[i].rate, *offset );
|
|
|
|
}
|
|
|
|
break;
|
1995-09-05 23:52:03 +00:00
|
|
|
}
|
1996-01-03 06:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
if (i >= ahc_num_syncrates) {
|
1997-03-16 07:12:07 +00:00
|
|
|
/* Use asynchronous transfers. */
|
1996-10-06 16:38:45 +00:00
|
|
|
*scsirate = 0;
|
|
|
|
*period = 0;
|
|
|
|
*offset = 0;
|
1996-10-06 22:50:56 +00:00
|
|
|
if (bootverbose)
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("%s: target %d using asynchronous transfers\n",
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_name(ahc), target );
|
1995-09-05 23:52:03 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* Ensure Ultra mode is set properly for
|
|
|
|
* this target.
|
|
|
|
*/
|
|
|
|
ultra_enb_addr = ULTRA_ENB;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (channel == 'B' || target > 7)
|
1996-10-06 16:38:45 +00:00
|
|
|
ultra_enb_addr++;
|
1996-11-11 05:24:46 +00:00
|
|
|
ultra_enb = ahc_inb(ahc, ultra_enb_addr);
|
|
|
|
sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
|
1996-10-06 16:38:45 +00:00
|
|
|
if (*scsirate != 0 && ahc_syncrates[i].sxfr & ULTRA_SXFR) {
|
|
|
|
ultra_enb |= 0x01 << (target & 0x07);
|
1997-02-09 03:26:56 +00:00
|
|
|
sxfrctl0 |= FAST20;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1996-10-06 16:38:45 +00:00
|
|
|
ultra_enb &= ~(0x01 << (target & 0x07));
|
1997-02-09 03:26:56 +00:00
|
|
|
sxfrctl0 &= ~FAST20;
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, ultra_enb_addr, ultra_enb);
|
|
|
|
ahc_outb(ahc, SXFRCTL0, sxfrctl0);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
int
|
|
|
|
ahcprint(aux, name)
|
|
|
|
void *aux;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
if (name != NULL)
|
|
|
|
printf("%s: scsibus ", name);
|
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1994-11-17 20:22:31 +00:00
|
|
|
int
|
1996-01-03 06:32:12 +00:00
|
|
|
ahc_attach(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1995-08-23 23:03:17 +00:00
|
|
|
struct scsibus_data *scbus;
|
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#ifdef AHC_BROKEN_CACHE
|
|
|
|
if (cpu_class == CPUCLASS_386) /* doesn't have "wbinvd" instruction */
|
|
|
|
ahc_broken_cache = 0;
|
|
|
|
#endif
|
1995-08-23 23:03:17 +00:00
|
|
|
/*
|
1996-05-10 16:21:05 +00:00
|
|
|
* fill in the prototype scsi_links.
|
1995-08-23 23:03:17 +00:00
|
|
|
*/
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-01-03 06:32:12 +00:00
|
|
|
ahc->sc_link.adapter_unit = ahc->unit;
|
1995-08-23 23:03:17 +00:00
|
|
|
ahc->sc_link.adapter_targ = ahc->our_id;
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc->sc_link.fordriver = 0;
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
ahc->sc_link.adapter_target = ahc->our_id;
|
|
|
|
#endif
|
1996-01-07 19:24:36 +00:00
|
|
|
ahc->sc_link.adapter_softc = ahc;
|
1995-08-23 23:03:17 +00:00
|
|
|
ahc->sc_link.adapter = &ahc_switch;
|
1995-03-17 23:58:27 +00:00
|
|
|
ahc->sc_link.opennings = 2;
|
1995-08-23 23:03:17 +00:00
|
|
|
ahc->sc_link.device = &ahc_dev;
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc->sc_link.flags = DEBUGLEVEL;
|
1994-11-18 20:34:30 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_TWIN) {
|
1996-05-10 16:21:05 +00:00
|
|
|
/* Configure the second scsi bus */
|
|
|
|
ahc->sc_link_b = ahc->sc_link;
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-05-10 16:21:05 +00:00
|
|
|
ahc->sc_link_b.adapter_targ = ahc->our_id_b;
|
|
|
|
ahc->sc_link_b.adapter_bus = 1;
|
|
|
|
ahc->sc_link_b.fordriver = (void *)SELBUSB;
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
ahc->sc_link_b.adapter_target = ahc->our_id_b;
|
|
|
|
#endif
|
1996-05-10 16:21:05 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
1995-08-23 23:03:17 +00:00
|
|
|
/*
|
|
|
|
* Prepare the scsibus_data area for the upperlevel
|
|
|
|
* scsi code.
|
|
|
|
*/
|
|
|
|
scbus = scsi_alloc_bus();
|
|
|
|
if(!scbus)
|
|
|
|
return 0;
|
1996-05-10 16:21:05 +00:00
|
|
|
scbus->adapter_link = (ahc->flags & AHC_CHANNEL_B_PRIMARY) ?
|
|
|
|
&ahc->sc_link_b : &ahc->sc_link;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_WIDE)
|
1995-08-23 23:03:17 +00:00
|
|
|
scbus->maxtarg = 15;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1996-05-10 16:21:05 +00:00
|
|
|
printf("ahc%d: Probing channel %c\n", ahc->unit,
|
|
|
|
(ahc->flags & AHC_CHANNEL_B_PRIMARY) ? 'B' : 'A');
|
1995-08-23 23:03:17 +00:00
|
|
|
scsi_attachdevs(scbus);
|
|
|
|
scbus = NULL; /* Upper-level SCSI code owns this now */
|
1996-05-10 16:21:05 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_TWIN) {
|
1995-08-23 23:03:17 +00:00
|
|
|
scbus = scsi_alloc_bus();
|
1996-10-25 06:42:53 +00:00
|
|
|
if (!scbus)
|
1995-08-23 23:03:17 +00:00
|
|
|
return 0;
|
1996-05-10 16:21:05 +00:00
|
|
|
scbus->adapter_link = (ahc->flags & AHC_CHANNEL_B_PRIMARY) ?
|
|
|
|
&ahc->sc_link : &ahc->sc_link_b;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_WIDE)
|
1995-08-23 23:03:17 +00:00
|
|
|
scbus->maxtarg = 15;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1996-05-10 16:21:05 +00:00
|
|
|
printf("ahc%d: Probing Channel %c\n", ahc->unit,
|
|
|
|
(ahc->flags & AHC_CHANNEL_B_PRIMARY) ? 'A': 'B');
|
1995-08-23 23:03:17 +00:00
|
|
|
scsi_attachdevs(scbus);
|
|
|
|
scbus = NULL; /* Upper-level SCSI code owns this now */
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
/*
|
|
|
|
* XXX - Update MI SCSI code
|
|
|
|
*
|
|
|
|
* if(ahc->type & AHC_WIDE)
|
|
|
|
* max target of both channel A and B = 15;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
*/
|
|
|
|
if ((ahc->flags & AHC_CHANNEL_B_PRIMARY) == 0) {
|
|
|
|
/* make IS_SCSIBUS_B() == false, while probing channel A */
|
|
|
|
ahc->sc_link_b.scsibus = 0xff;
|
|
|
|
|
|
|
|
if (ahc->type & AHC_TWIN)
|
|
|
|
printf("%s: Probing channel A\n", ahc_name(ahc));
|
|
|
|
config_found((void *)ahc, &ahc->sc_link, ahcprint);
|
|
|
|
if (ahc->type & AHC_TWIN) {
|
|
|
|
printf("%s: Probing channel B\n", ahc_name(ahc));
|
|
|
|
config_found((void *)ahc, &ahc->sc_link_b, ahcprint);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* if implementation of IS_SCSIBUS_B() is changed to use
|
|
|
|
* ahc->sc_link.scsibus, then "ahc->sc_link.scsibus = 0xff;"
|
|
|
|
* is needed, here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* assert(ahc->type & AHC_TWIN); */
|
|
|
|
printf("%s: Probing channel B\n", ahc_name(ahc));
|
|
|
|
config_found((void *)ahc, &ahc->sc_link_b, ahcprint);
|
|
|
|
printf("%s: Probing channel A\n", ahc_name(ahc));
|
|
|
|
config_found((void *)ahc, &ahc->sc_link, ahcprint);
|
|
|
|
}
|
|
|
|
#endif
|
1995-08-23 23:03:17 +00:00
|
|
|
return 1;
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
* Catch an interrupt from the adapter
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-01-23 21:48:28 +00:00
|
|
|
void
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined (__NetBSD__)
|
|
|
|
int
|
|
|
|
#endif
|
1996-01-23 21:48:28 +00:00
|
|
|
ahc_intr(arg)
|
1995-11-05 04:50:55 +00:00
|
|
|
void *arg;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t intstat;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc = (struct ahc_softc *)arg;
|
1996-11-11 05:24:46 +00:00
|
|
|
intstat = ahc_inb(ahc, INTSTAT);
|
1995-03-31 13:54:41 +00:00
|
|
|
/*
|
|
|
|
* Is this interrupt for me? or for
|
1997-03-16 07:12:07 +00:00
|
|
|
* someone who is sharing my interrupt?
|
1995-03-31 13:54:41 +00:00
|
|
|
*/
|
|
|
|
if (!(intstat & INT_PEND))
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-01-23 21:48:28 +00:00
|
|
|
return;
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
return 0;
|
|
|
|
#endif
|
1995-11-05 04:50:55 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (intstat & CMDCMPLT) {
|
|
|
|
struct scb *scb;
|
|
|
|
u_int8_t scb_index;
|
|
|
|
u_int8_t qoutcnt;
|
|
|
|
int int_cleared;
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
int_cleared = 0;
|
1996-11-11 05:24:46 +00:00
|
|
|
while (qoutcnt = (ahc_inb(ahc, QOUTCNT) & ahc->qcntmask)) {
|
1996-10-25 06:42:53 +00:00
|
|
|
for (; qoutcnt > 0; qoutcnt--) {
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, QOUTFIFO);
|
1996-10-28 06:10:02 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1996-10-25 06:42:53 +00:00
|
|
|
if (!scb || !(scb->flags & SCB_ACTIVE)) {
|
|
|
|
printf("%s: WARNING "
|
|
|
|
"no command for scb %d "
|
|
|
|
"(cmdcmplt)\nQOUTCNT == %d\n",
|
|
|
|
ahc_name(ahc), scb_index,
|
|
|
|
qoutcnt);
|
|
|
|
continue;
|
|
|
|
}
|
1996-04-20 21:29:27 +00:00
|
|
|
/*
|
1996-10-25 06:42:53 +00:00
|
|
|
* Save off the residual if there is one.
|
1996-04-20 21:29:27 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if (scb->hscb->residual_SG_segment_count != 0)
|
|
|
|
ahc_calc_residual(scb);
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((scb->flags & SCB_QUEUED_ABORT) != 0) {
|
|
|
|
/* Have to clean up any possible
|
|
|
|
* entries in the waiting queue and
|
|
|
|
* QINFIFO.
|
|
|
|
*/
|
|
|
|
int target;
|
|
|
|
char channel;
|
|
|
|
int lun;
|
|
|
|
u_int8_t tag;
|
|
|
|
|
|
|
|
tag = SCB_LIST_NULL;
|
|
|
|
target = scb->xs->sc_link->target;
|
|
|
|
lun = scb->xs->sc_link->lun;
|
|
|
|
channel = (scb->hscb->tcl & SELBUSB)
|
|
|
|
? 'B': 'A';
|
|
|
|
if (scb->hscb->control & TAG_ENB)
|
|
|
|
tag = scb->hscb->tag;
|
|
|
|
ahc_reset_device(ahc,
|
|
|
|
target,
|
|
|
|
channel,
|
|
|
|
lun,
|
|
|
|
tag,
|
|
|
|
scb->xs->error);
|
|
|
|
ahc_run_done_queue(ahc);
|
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
if (scb->hscb->status != SCSI_QUEUE_FULL)
|
|
|
|
ahc_done(ahc, scb);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRCMDINT);
|
1996-10-25 06:42:53 +00:00
|
|
|
int_cleared++;
|
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (int_cleared == 0)
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRCMDINT);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
if (intstat & BRKADRINT) {
|
|
|
|
/*
|
|
|
|
* We upset the sequencer :-(
|
|
|
|
* Lookup the error message
|
|
|
|
*/
|
|
|
|
int i, error, num_errors;
|
|
|
|
|
|
|
|
error = ahc_inb(ahc, ERROR);
|
|
|
|
num_errors = sizeof(hard_error)/sizeof(hard_error[0]);
|
|
|
|
for (i = 0; error != 1 && i < num_errors; i++)
|
|
|
|
error >>= 1;
|
|
|
|
printf("%s: brkadrint, %s at seqaddr = 0x%x\n",
|
|
|
|
ahc_name(ahc), hard_error[i].errmesg,
|
|
|
|
(ahc_inb(ahc, SEQADDR1) << 8) |
|
|
|
|
ahc_inb(ahc, SEQADDR0));
|
|
|
|
|
|
|
|
ahc_reset_device(ahc, ALL_TARGETS, ALL_CHANNELS, ALL_LUNS,
|
|
|
|
SCB_LIST_NULL, XS_DRIVER_STUFFUP);
|
|
|
|
ahc_run_done_queue(ahc);
|
|
|
|
}
|
|
|
|
if (intstat & SEQINT)
|
|
|
|
ahc_handle_seqint(ahc, intstat);
|
|
|
|
|
|
|
|
if (intstat & SCSIINT)
|
|
|
|
ahc_handle_scsiint(ahc, intstat);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
if (ahc->waiting_scbs.stqh_first != NULL)
|
|
|
|
ahc_run_waiting_queue(ahc);
|
1996-10-06 16:38:45 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_handle_seqint(ahc, intstat)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int8_t intstat;
|
|
|
|
{
|
|
|
|
struct scb *scb;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int16_t targ_mask;
|
1997-03-01 06:50:41 +00:00
|
|
|
u_int8_t target;
|
|
|
|
int scratch_offset;
|
|
|
|
char channel;
|
1996-10-06 16:38:45 +00:00
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
if ((ahc_inb(ahc, SEQ_FLAGS) & RESELECTED) != 0)
|
1997-03-01 06:50:41 +00:00
|
|
|
target = ahc_inb(ahc, SELID);
|
|
|
|
else
|
|
|
|
target = ahc_inb(ahc, SCSIID);
|
|
|
|
target = (target >> 4) & 0x0f;
|
|
|
|
scratch_offset = target;
|
|
|
|
channel = ahc_inb(ahc, SBLKCTL) & SELBUSB ? 'B': 'A';
|
1996-10-06 16:38:45 +00:00
|
|
|
if (channel == 'B')
|
|
|
|
scratch_offset += 8;
|
1997-03-16 07:12:07 +00:00
|
|
|
targ_mask = (0x01 << scratch_offset);
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
switch (intstat & SEQINT_MASK) {
|
|
|
|
case NO_MATCH:
|
1996-10-28 06:10:02 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This could be for a normal abort request.
|
|
|
|
* Figure out the SCB that we were trying to find
|
|
|
|
* and only give an error if we didn't ask for this
|
|
|
|
* to happen.
|
|
|
|
*/
|
|
|
|
u_int8_t scb_index;
|
|
|
|
u_int8_t busy_scbid;
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
busy_scbid = ahc_index_busy_target(ahc, target, channel,
|
|
|
|
/*unbusy*/FALSE);
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, ARG_1);
|
1996-10-28 06:10:02 +00:00
|
|
|
|
|
|
|
if (scb_index == SCB_LIST_NULL)
|
|
|
|
/* Untagged Request */
|
|
|
|
scb_index = busy_scbid;
|
|
|
|
|
|
|
|
if (scb_index < ahc->scb_data->numscbs) {
|
1997-02-03 02:16:16 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1996-10-28 06:10:02 +00:00
|
|
|
|
|
|
|
if (scb->hscb->control & ABORT_SCB) {
|
1997-02-25 03:05:35 +00:00
|
|
|
/*
|
|
|
|
* We expected this. Let the busfree
|
|
|
|
* handler take care of this when we
|
|
|
|
* the abort is finially sent.
|
|
|
|
* Set IDENTIFY_SEEN so that the busfree
|
|
|
|
* handler knows that there is an SCB to
|
|
|
|
* cleanup.
|
|
|
|
*/
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SEQ_FLAGS, ahc_inb(ahc, SEQ_FLAGS)
|
1997-02-25 03:05:35 +00:00
|
|
|
| IDENTIFY_SEEN);
|
1996-10-28 06:10:02 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1997-02-25 03:05:35 +00:00
|
|
|
printf("reconnect SCB abort successfull\n");
|
1996-10-28 06:10:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
/*
|
|
|
|
* We expect a busfree to occur, so don't bother to interrupt
|
|
|
|
* when it happens - we've already handled the error.
|
|
|
|
*/
|
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
|
|
|
|
|
|
|
|
busy_scbid = ahc_index_busy_target(ahc, target, channel,
|
|
|
|
/*unbusy*/TRUE);
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("%s:%c:%d: no active SCB for reconnecting "
|
|
|
|
"target - issuing ABORT\n",
|
|
|
|
ahc_name(ahc), channel, target);
|
|
|
|
printf("SAVED_TCL == 0x%x\n",
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_inb(ahc, SAVED_TCL));
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
1996-10-28 06:10:02 +00:00
|
|
|
}
|
|
|
|
case NO_MATCH_BUSY:
|
|
|
|
{
|
1997-01-29 05:27:03 +00:00
|
|
|
/*
|
|
|
|
* XXX Leave this as a panic for the time being since
|
|
|
|
* it indicates a bug in the timeout code for this
|
|
|
|
* to happen.
|
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
u_int8_t scb_index;
|
|
|
|
u_int8_t busy_scbindex;
|
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, CUR_SCBID);
|
1996-10-28 06:10:02 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
panic("%s:%c:%d: Target busy link failure.\n",
|
|
|
|
ahc_name(ahc), (scb->hscb->tcl & SELBUSB) ? 'B' : 'A',
|
|
|
|
scb->xs->sc_link->target);
|
1996-10-28 06:10:02 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
case SEND_REJECT:
|
|
|
|
{
|
1996-11-11 05:24:46 +00:00
|
|
|
u_int8_t rejbyte = ahc_inb(ahc, REJBYTE);
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("%s:%c:%d: Warning - unknown message received from "
|
1996-10-06 16:38:45 +00:00
|
|
|
"target (0x%x). Rejecting\n",
|
|
|
|
ahc_name(ahc), channel, target, rejbyte);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NO_IDENT:
|
1997-02-28 03:58:21 +00:00
|
|
|
{
|
1997-01-29 05:27:03 +00:00
|
|
|
/*
|
1997-02-28 03:58:21 +00:00
|
|
|
* The reconnecting target either did not send an identify
|
|
|
|
* message, or did, but we didn't find and SCB to match and
|
|
|
|
* before it could respond to our ATN/abort, it hit a dataphase.
|
|
|
|
* The only safe thing to do is to blow it away with a bus
|
|
|
|
* reset.
|
1997-01-29 05:27:03 +00:00
|
|
|
*/
|
1997-02-28 03:58:21 +00:00
|
|
|
int found;
|
|
|
|
|
|
|
|
printf("%s:%c:%d: Target did not send an IDENTIFY message. "
|
|
|
|
"LASTPHASE = 0x%x, SAVED_TCL == 0x%x\n",
|
|
|
|
ahc_name(ahc), channel, target, ahc_inb(ahc, LASTPHASE),
|
|
|
|
ahc_inb(ahc, SAVED_TCL));
|
|
|
|
found = ahc_reset_channel(ahc, channel, XS_TIMEOUT,
|
1997-03-16 07:12:07 +00:00
|
|
|
/*initiate reset*/TRUE);
|
1997-02-28 03:58:21 +00:00
|
|
|
printf("%s: Issued Channel %c Bus Reset. "
|
|
|
|
"%d SCBs aborted\n", ahc_name(ahc), channel, found);
|
1997-03-16 07:12:07 +00:00
|
|
|
break;
|
1997-02-28 03:58:21 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
case BAD_PHASE:
|
1997-03-16 07:12:07 +00:00
|
|
|
if (ahc_inb(ahc, LASTPHASE) == P_BUSFREE) {
|
|
|
|
printf("%s:%c:%d: Missed busfree.\n", ahc_name(ahc),
|
|
|
|
channel, target);
|
|
|
|
restart_sequencer(ahc);
|
|
|
|
} else {
|
|
|
|
printf("%s:%c:%d: unknown scsi bus phase. Attempting "
|
|
|
|
"to continue\n", ahc_name(ahc), channel, target);
|
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
case EXTENDED_MSG:
|
|
|
|
{
|
|
|
|
u_int8_t message_length;
|
|
|
|
u_int8_t message_code;
|
1997-02-25 03:05:35 +00:00
|
|
|
u_int8_t scb_index;
|
1995-01-13 02:24:31 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
message_length = ahc_inb(ahc, MSGIN_EXT_LEN);
|
|
|
|
message_code = ahc_inb(ahc, MSGIN_EXT_OPCODE);
|
1997-02-25 03:05:35 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1996-10-25 06:42:53 +00:00
|
|
|
switch (message_code) {
|
1996-10-06 16:38:45 +00:00
|
|
|
case MSG_EXT_SDTR:
|
|
|
|
{
|
|
|
|
u_int8_t period;
|
|
|
|
u_int8_t offset;
|
1996-10-06 19:43:36 +00:00
|
|
|
u_int8_t saved_offset;
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int8_t targ_scratch;
|
|
|
|
u_int8_t maxoffset;
|
|
|
|
u_int8_t rate;
|
|
|
|
|
|
|
|
if (message_length != MSG_EXT_SDTR_LEN) {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_REJ);
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-03-16 07:12:07 +00:00
|
|
|
period = ahc_inb(ahc, MSGIN_EXT_BYTES);
|
|
|
|
saved_offset = ahc_inb(ahc, MSGIN_EXT_BYTES + 1);
|
1996-11-11 05:24:46 +00:00
|
|
|
targ_scratch = ahc_inb(ahc, TARG_SCRATCH
|
1996-10-06 16:38:45 +00:00
|
|
|
+ scratch_offset);
|
|
|
|
if (targ_scratch & WIDEXFER)
|
|
|
|
maxoffset = MAX_OFFSET_16BIT;
|
|
|
|
else
|
|
|
|
maxoffset = MAX_OFFSET_8BIT;
|
1996-10-06 19:43:36 +00:00
|
|
|
offset = MIN(saved_offset, maxoffset);
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_scsirate(ahc, &rate, &period, &offset,
|
|
|
|
channel, target);
|
|
|
|
/* Preserve the WideXfer flag */
|
|
|
|
targ_scratch = rate | (targ_scratch & WIDEXFER);
|
1995-01-13 02:24:31 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* Update both the target scratch area and the
|
|
|
|
* current SCSIRATE.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, TARG_SCRATCH + scratch_offset,
|
1996-10-06 16:38:45 +00:00
|
|
|
targ_scratch);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCSIRATE, targ_scratch);
|
1995-01-13 02:24:31 +00:00
|
|
|
|
1996-10-06 19:43:36 +00:00
|
|
|
/*
|
|
|
|
* See if we initiated Sync Negotiation
|
|
|
|
* and didn't have to fall down to async
|
|
|
|
* transfers.
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((scb->flags & SCB_MSGOUT_SDTR) != 0) {
|
1996-11-22 08:28:45 +00:00
|
|
|
/* We started it */
|
1996-11-05 07:57:29 +00:00
|
|
|
if (saved_offset == offset) {
|
|
|
|
/*
|
|
|
|
* Don't send an SDTR back to
|
|
|
|
* the target
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, 0);
|
1996-11-05 07:57:29 +00:00
|
|
|
} else
|
1996-11-11 05:24:46 +00:00
|
|
|
/* Went too low - force async */
|
|
|
|
ahc_outb(ahc, RETURN_1, SEND_REJ);
|
1996-10-06 16:38:45 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Send our own SDTR in reply
|
1995-01-16 16:33:47 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("Sending SDTR!!\n");
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_construct_sdtr(ahc, /*start_byte*/0,
|
|
|
|
period, offset);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_MSG);
|
1995-01-16 16:33:47 +00:00
|
|
|
}
|
1996-11-05 07:57:29 +00:00
|
|
|
ahc->needsdtr &= ~targ_mask;
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MSG_EXT_WDTR:
|
|
|
|
{
|
|
|
|
u_int8_t scratch, bus_width;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
if (message_length != MSG_EXT_WDTR_LEN) {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_REJ);
|
1994-12-31 19:31:56 +00:00
|
|
|
break;
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1996-01-29 03:17:39 +00:00
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
bus_width = ahc_inb(ahc, MSGIN_EXT_BYTES);
|
1996-11-11 05:24:46 +00:00
|
|
|
scratch = ahc_inb(ahc, TARG_SCRATCH + scratch_offset);
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((scb->flags & SCB_MSGOUT_WDTR) != 0) {
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* Don't send a WDTR back to the
|
|
|
|
* target, since we asked first.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, 0);
|
1996-10-25 06:42:53 +00:00
|
|
|
switch (bus_width){
|
1996-10-06 16:38:45 +00:00
|
|
|
case BUS_8_BIT:
|
|
|
|
scratch &= 0x7f;
|
|
|
|
break;
|
|
|
|
case BUS_16_BIT:
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1996-10-06 16:38:45 +00:00
|
|
|
printf("%s: target %d using "
|
|
|
|
"16Bit transfers\n",
|
|
|
|
ahc_name(ahc), target);
|
|
|
|
scratch |= WIDEXFER;
|
|
|
|
break;
|
|
|
|
case BUS_32_BIT:
|
1996-01-03 06:32:12 +00:00
|
|
|
/*
|
1996-10-06 16:38:45 +00:00
|
|
|
* How can we do 32bit transfers
|
|
|
|
* on a 16bit bus?
|
1996-01-03 06:32:12 +00:00
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_REJ);
|
1996-10-06 16:38:45 +00:00
|
|
|
printf("%s: target %d requested 32Bit "
|
|
|
|
"transfers. Rejecting...\n",
|
|
|
|
ahc_name(ahc), target);
|
|
|
|
break;
|
|
|
|
default:
|
1995-01-16 16:33:47 +00:00
|
|
|
break;
|
1994-12-31 19:31:56 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
} else {
|
1994-12-31 19:31:56 +00:00
|
|
|
/*
|
1996-10-06 16:38:45 +00:00
|
|
|
* Send our own WDTR in reply
|
1994-12-31 19:31:56 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
switch (bus_width) {
|
1996-10-06 16:38:45 +00:00
|
|
|
case BUS_8_BIT:
|
|
|
|
scratch &= 0x7f;
|
|
|
|
break;
|
|
|
|
case BUS_32_BIT:
|
|
|
|
case BUS_16_BIT:
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_WIDE) {
|
1996-10-06 16:38:45 +00:00
|
|
|
/* Negotiate 16_BITS */
|
|
|
|
bus_width = BUS_16_BIT;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1996-10-06 16:38:45 +00:00
|
|
|
printf("%s: target %d "
|
|
|
|
"using 16Bit "
|
|
|
|
"transfers\n",
|
|
|
|
ahc_name(ahc),
|
|
|
|
target);
|
|
|
|
scratch |= WIDEXFER;
|
|
|
|
} else
|
|
|
|
bus_width = BUS_8_BIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ahc_construct_wdtr(ahc, /*start_byte*/0,
|
|
|
|
bus_width);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_MSG);
|
1994-12-31 19:31:56 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc->needwdtr &= ~targ_mask;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, TARG_SCRATCH + scratch_offset, scratch);
|
|
|
|
ahc_outb(ahc, SCSIRATE, scratch);
|
1994-12-31 19:31:56 +00:00
|
|
|
break;
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* Unknown extended message. Reject it. */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_REJ);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1996-11-05 07:57:29 +00:00
|
|
|
break;
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
|
|
|
case REJECT_MSG:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* What we care about here is if we had an
|
|
|
|
* outstanding SDTR or WDTR message for this
|
|
|
|
* target. If we did, this is a signal that
|
|
|
|
* the target is refusing negotiation.
|
|
|
|
*/
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t targ_scratch;
|
1997-02-25 03:05:35 +00:00
|
|
|
u_int8_t scb_index;
|
|
|
|
|
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1996-10-06 16:38:45 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
targ_scratch = ahc_inb(ahc, TARG_SCRATCH
|
1996-10-06 16:38:45 +00:00
|
|
|
+ scratch_offset);
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((scb->flags & SCB_MSGOUT_WDTR) != 0) {
|
1996-10-06 16:38:45 +00:00
|
|
|
/* note 8bit xfers and clear flag */
|
|
|
|
targ_scratch &= 0x7f;
|
|
|
|
ahc->needwdtr &= ~targ_mask;
|
|
|
|
printf("%s:%c:%d: refuses WIDE negotiation. Using "
|
|
|
|
"8bit transfers\n", ahc_name(ahc),
|
|
|
|
channel, target);
|
1997-02-25 03:05:35 +00:00
|
|
|
} else if ((scb->flags & SCB_MSGOUT_SDTR) != 0) {
|
1996-10-06 16:38:45 +00:00
|
|
|
/* note asynch xfers and clear flag */
|
|
|
|
targ_scratch &= 0xf0;
|
|
|
|
ahc->needsdtr &= ~targ_mask;
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("%s:%c:%d: refuses synchronous negotiation. "
|
|
|
|
"Using asynchronous transfers\n",
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_name(ahc),
|
|
|
|
channel, target);
|
|
|
|
} else {
|
1995-03-31 13:54:41 +00:00
|
|
|
/*
|
1996-10-06 16:38:45 +00:00
|
|
|
* Otherwise, we ignore it.
|
1995-03-31 13:54:41 +00:00
|
|
|
*/
|
1996-10-06 16:38:45 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc_debug & AHC_SHOWMISC)
|
1996-10-06 16:38:45 +00:00
|
|
|
printf("%s:%c:%d: Message reject -- ignored\n",
|
|
|
|
ahc_name(ahc), channel, target);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, TARG_SCRATCH + scratch_offset, targ_scratch);
|
|
|
|
ahc_outb(ahc, SCSIRATE, targ_scratch);
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAD_STATUS:
|
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t scb_index;
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
struct hardware_scb *hscb;
|
1996-10-06 16:38:45 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* The sequencer will notify us when a command
|
1996-10-06 16:38:45 +00:00
|
|
|
* has an error that would be of interest to
|
|
|
|
* the kernel. This allows us to leave the sequencer
|
|
|
|
* running in the common case of command completes
|
1996-10-25 06:42:53 +00:00
|
|
|
* without error. The sequencer will already have
|
|
|
|
* dma'd the SCB back up to us, so we can reference
|
|
|
|
* the in kernel copy directly.
|
1996-10-06 16:38:45 +00:00
|
|
|
*/
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
1996-10-28 06:10:02 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb = scb->hscb;
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* Set the default return value to 0 (don't
|
|
|
|
* send sense). The sense code will change
|
|
|
|
* this if needed and this reduces code
|
|
|
|
* duplication.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, 0);
|
1996-10-06 16:38:45 +00:00
|
|
|
if (!(scb && (scb->flags & SCB_ACTIVE))) {
|
|
|
|
printf("%s:%c:%d: ahc_intr - referenced scb "
|
|
|
|
"not valid during seqint 0x%x scb(%d)\n",
|
|
|
|
ahc_name(ahc),
|
|
|
|
channel, target, intstat,
|
|
|
|
scb_index);
|
|
|
|
goto clear;
|
|
|
|
}
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
xs = scb->xs;
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
xs->status = hscb->status;
|
|
|
|
switch (hscb->status){
|
1996-10-06 16:38:45 +00:00
|
|
|
case SCSI_OK:
|
|
|
|
printf("%s: Interrupted for staus of"
|
|
|
|
" 0???\n", ahc_name(ahc));
|
|
|
|
break;
|
|
|
|
case SCSI_CHECK:
|
|
|
|
#ifdef AHC_DEBUG
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc_debug & AHC_SHOWSENSE) {
|
1996-10-06 16:38:45 +00:00
|
|
|
sc_print_addr(xs->sc_link);
|
1997-02-25 03:05:35 +00:00
|
|
|
printf("SCB %d: requests Check Status\n",
|
|
|
|
scb->hscb->tag);
|
Fixes to the aic7xxx sequencer code and device driver from Justin Gibbs:
1) If a target initiated a sync negotiation with us and happened to chose a
value above 15, the old code inadvertantly truncated it with an "& 0x0f".
If the periferal picked something really bad like 0x32, you'd end up with
an offset of 2 which would hang the drive since it didn't expect to ever
get something so low. We now do a MIN(maxoffset, given_offset).
2) In the case of Wide cards, we were turning on sync transfers after a
sucessfull wide negotiation. Now we leave the offset alone in the per
target scratch space (which implies asyncronous transfers since we initialize
it that way) until a syncronous negotation occurs.
3) We were advertizing a max offset of 15 instead of 8 for wide devices.
4) If the upper level SCSI code sent down a "SCSI_RESET", it would hang the
system because we would end up sending a null command to the sequencer. Now
we handle SCSI_RESET correctly by having the sequencer interrupt us when it
is about to fill the message buffer so that we can fill it in ourselves.
The sequencer will also "simulate" a command complete for these "message only"
SCBs so that the kernel driver can finish up properly. The cdplay utility
will send a "SCSI_REST" to the cdplayer if you use the reset command.
5) The code that handles SCSIINTs was broken in that if more than one type
of error was true at once, we'd do outbs without the card being paused.
The else clause after the busfree case was also an accident waiting to
happen. I've now turned this into an if, else if, else type of thing, since
in most cases when we handle one type of error, it should be okay to ignore
the rest (ie if we have a SELTO, who cares if there was a parity error on
the transaction?), but the section should really be rewritten after 2.0.5.
This fix was the least obtrusive way to patch the problem.
6) Only tag either SDTR or WDTR negotiation on an SCB. The real problem is
that I don't account for the case when an SCB that is tagged to do a particular
type of negotiation completes or SELTOs (selection timeout) without the
negotiation taking place, so the accounting of sdtrpending and wdtrpending
gets screwed up. In the wide case, if we tag it to do both wdtr and sdtr,
it only performs wdtr (since wdtr must occur first and we spread out the
negotiation over two commands) so we always have sdtrpending set for that
target and we never do a real SDTR. I fill properly fix the accounting
after 2.0.5 goes out the door, but this works (as confirmed by Dan) on
wide targets.
Other stuff that is also included:
1) Don't do a bzero when recycling SCBs. The only thing that must explicitly
be set to zero is the scb control byte which is done in ahc_get_scb. We also
need to set the SG_list_pointer and SG_list_count to 0 for commands that do
not transfer data.
2) Mask the interrupt type printout for the aic7870 case. The bit we were
using to determine interrupt type is only valid for the aic7770.
Submitted by: Justin Gibbs
1995-05-17 07:06:02 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((xs->error == XS_NOERROR)
|
1996-10-25 06:42:53 +00:00
|
|
|
&& !(scb->flags & SCB_SENSE)) {
|
1996-10-06 16:38:45 +00:00
|
|
|
struct ahc_dma_seg *sg = scb->ahc_dma;
|
|
|
|
struct scsi_sense *sc = &(scb->sense_cmd);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save off the residual if there is one.
|
|
|
|
*/
|
|
|
|
if (hscb->residual_SG_segment_count != 0)
|
|
|
|
ahc_calc_residual(scb);
|
1997-02-03 02:16:16 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc_debug & AHC_SHOWSENSE) {
|
1996-10-06 16:38:45 +00:00
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("Sending Sense\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
sc->op_code = REQUEST_SENSE;
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
sc->opcode = REQUEST_SENSE;
|
|
|
|
#endif
|
|
|
|
sc->byte2 = xs->sc_link->lun << 5;
|
|
|
|
sc->length = sizeof(struct scsi_sense_data);
|
|
|
|
sc->control = 0;
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
sg->addr = vtophys(&xs->sense);
|
1996-10-06 16:38:45 +00:00
|
|
|
sg->len = sizeof(struct scsi_sense_data);
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control &= DISCENB;
|
|
|
|
hscb->status = 0;
|
|
|
|
hscb->SG_segment_count = 1;
|
|
|
|
hscb->SG_list_pointer = vtophys(sg);
|
|
|
|
hscb->data = sg->addr;
|
1996-11-05 07:57:29 +00:00
|
|
|
/* Maintain SCB_LINKED_NEXT */
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->datalen &= 0xFF000000;
|
|
|
|
hscb->datalen |= sg->len;
|
|
|
|
hscb->cmdpointer = vtophys(sc);
|
|
|
|
hscb->cmdlen = sizeof(*sc);
|
1997-02-11 17:10:37 +00:00
|
|
|
scb->sg_count = hscb->SG_segment_count;
|
1996-10-06 16:38:45 +00:00
|
|
|
scb->flags |= SCB_SENSE;
|
1997-03-01 06:50:41 +00:00
|
|
|
/*
|
|
|
|
* Ensure the target is busy since this
|
|
|
|
* will be an untagged request.
|
|
|
|
*/
|
|
|
|
ahc_busy_target(ahc, target, channel,
|
|
|
|
hscb->tag);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, RETURN_1, SEND_SENSE);
|
1997-02-03 02:16:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure we have enough time to actually
|
|
|
|
* retrieve the sense.
|
|
|
|
*/
|
|
|
|
untimeout(ahc_timeout, (caddr_t)scb);
|
1997-02-14 03:13:37 +00:00
|
|
|
timeout(ahc_timeout, (caddr_t)scb, hz);
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1996-06-09 17:33:18 +00:00
|
|
|
/*
|
1996-10-06 16:38:45 +00:00
|
|
|
* Clear the SCB_SENSE Flag and have
|
|
|
|
* the sequencer do a normal command
|
|
|
|
* complete with either a "DRIVER_STUFFUP"
|
|
|
|
* error or whatever other error condition
|
|
|
|
* we already had.
|
1996-06-09 17:33:18 +00:00
|
|
|
*/
|
1996-10-06 16:38:45 +00:00
|
|
|
scb->flags &= ~SCB_SENSE;
|
|
|
|
if (xs->error == XS_NOERROR)
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-06-09 17:33:18 +00:00
|
|
|
break;
|
1996-11-16 01:19:14 +00:00
|
|
|
case SCSI_QUEUE_FULL:
|
|
|
|
if (scb->hscb->control & TAG_ENB) {
|
|
|
|
/*
|
|
|
|
* The upper level SCSI code in 3.0
|
|
|
|
* handles this properly...
|
|
|
|
*/
|
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
sc_link = xs->sc_link;
|
|
|
|
if (sc_link->active > 2
|
|
|
|
&& sc_link->opennings != 0) {
|
|
|
|
/* truncate the opennings */
|
|
|
|
sc_link->opennings = 0;
|
|
|
|
sc_print_addr(sc_link);
|
|
|
|
printf("Tagged openings reduced to "
|
|
|
|
"%d\n", sc_link->active);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX requeue this unconditionally.
|
|
|
|
*/
|
|
|
|
STAILQ_INSERT_TAIL(&ahc->waiting_scbs, scb,
|
|
|
|
links);
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags |= SCB_WAITINGQ;
|
1996-11-22 08:28:45 +00:00
|
|
|
/* Give the command a new lease on life */
|
|
|
|
untimeout(ahc_timeout, (caddr_t)scb);
|
|
|
|
timeout(ahc_timeout, (caddr_t)scb,
|
|
|
|
(scb->xs->timeout * hz) / 1000);
|
1996-11-16 01:19:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Else treat as if it is a BUSY condition */
|
|
|
|
scb->hscb->status = SCSI_BUSY;
|
|
|
|
/* Fall Through... */
|
1996-10-06 16:38:45 +00:00
|
|
|
case SCSI_BUSY:
|
|
|
|
xs->error = XS_BUSY;
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("Target Busy\n");
|
1996-01-03 06:32:12 +00:00
|
|
|
break;
|
1996-10-06 16:38:45 +00:00
|
|
|
default:
|
|
|
|
sc_print_addr(xs->sc_link);
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("unexpected targ_status: %x\n", hscb->status);
|
1996-10-06 16:38:45 +00:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-03-31 03:15:31 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AWAITING_MSG:
|
|
|
|
{
|
1997-02-03 02:16:16 +00:00
|
|
|
int scb_index;
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int8_t message_offset;
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
1996-10-28 06:10:02 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
1997-02-03 02:16:16 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
1996-10-25 06:42:53 +00:00
|
|
|
* This SCB had MK_MESSAGE set in its control byte,
|
|
|
|
* informing the sequencer that we wanted to send a
|
|
|
|
* special message to this target.
|
1996-10-06 16:38:45 +00:00
|
|
|
*/
|
1997-02-03 02:16:16 +00:00
|
|
|
message_offset = ahc_inb(ahc, MSG_LEN);
|
1996-10-06 16:38:45 +00:00
|
|
|
if (scb->flags & SCB_DEVICE_RESET) {
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT, MSG_BUS_DEV_RESET);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, 1);
|
1997-02-25 03:05:35 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1996-10-06 16:38:45 +00:00
|
|
|
printf("Bus Device Reset Message Sent\n");
|
1997-02-28 03:58:21 +00:00
|
|
|
} else if (scb->flags & SCB_ABORT) {
|
|
|
|
if ((scb->hscb->control & TAG_ENB) != 0)
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT + message_offset,
|
1997-02-28 03:58:21 +00:00
|
|
|
MSG_ABORT_TAG);
|
|
|
|
else
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT + message_offset,
|
|
|
|
MSG_ABORT);
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, message_offset + 1);
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("Abort Message Sent\n");
|
1996-10-06 16:38:45 +00:00
|
|
|
} else if (scb->flags & SCB_MSGOUT_WDTR) {
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_construct_wdtr(ahc, message_offset, BUS_16_BIT);
|
1996-10-06 16:38:45 +00:00
|
|
|
} else if (scb->flags & SCB_MSGOUT_SDTR) {
|
|
|
|
int sxfr;
|
|
|
|
int i;
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int16_t ultraenable;
|
|
|
|
u_int8_t target_scratch;
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
/* Pull the user defined setting */
|
1996-11-11 05:24:46 +00:00
|
|
|
target_scratch = ahc_inb(ahc, TARG_SCRATCH
|
1996-10-06 16:38:45 +00:00
|
|
|
+ scratch_offset);
|
|
|
|
|
|
|
|
sxfr = target_scratch & SXFR;
|
1997-01-22 18:05:31 +00:00
|
|
|
ultraenable = ahc_inb(ahc, ULTRA_ENB)
|
|
|
|
| (ahc_inb(ahc, ULTRA_ENB + 1) << 8);
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
if (ultraenable & targ_mask)
|
|
|
|
/* Want an ultra speed in the table */
|
|
|
|
sxfr |= 0x100;
|
|
|
|
|
|
|
|
for (i = 0; i < ahc_num_syncrates; i++)
|
1996-10-06 22:50:56 +00:00
|
|
|
if (sxfr == ahc_syncrates[i].sxfr)
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_construct_sdtr(ahc, message_offset,
|
1996-10-06 16:38:45 +00:00
|
|
|
ahc_syncrates[i].period,
|
1996-10-25 06:42:53 +00:00
|
|
|
(target_scratch & WIDEXFER) ?
|
1996-10-06 16:38:45 +00:00
|
|
|
MAX_OFFSET_16BIT : MAX_OFFSET_8BIT);
|
|
|
|
} else
|
|
|
|
panic("ahc_intr: AWAITING_MSG for an SCB that "
|
|
|
|
"does not have a waiting message");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DATA_OVERRUN:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* When the sequencer detects an overrun, it
|
|
|
|
* sets STCNT to 0x00ffffff and allows the
|
|
|
|
* target to complete its transfer in
|
|
|
|
* BITBUCKET mode.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
u_int8_t scbindex = ahc_inb(ahc, SCB_TAG);
|
1997-02-11 17:10:37 +00:00
|
|
|
u_int8_t lastphase = ahc_inb(ahc, LASTPHASE);
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int32_t overrun;
|
1997-02-11 17:10:37 +00:00
|
|
|
int i;
|
1996-10-28 06:10:02 +00:00
|
|
|
scb = ahc->scb_data->scbarray[scbindex];
|
1997-03-16 07:12:07 +00:00
|
|
|
overrun = ahc_inb(ahc, STCNT)
|
|
|
|
| (ahc_inb(ahc, STCNT + 1) << 8)
|
|
|
|
| (ahc_inb(ahc, STCNT + 2) << 16);
|
1996-10-06 16:38:45 +00:00
|
|
|
overrun = 0x00ffffff - overrun;
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1997-02-11 17:10:37 +00:00
|
|
|
printf("data overrun of %d bytes detected in %s phase."
|
|
|
|
" Tag == 0x%x. Forcing a retry.\n", overrun,
|
|
|
|
lastphase == P_DATAIN ? "Data-In" : "Data-Out",
|
|
|
|
scb->hscb->tag);
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("%s seen Data Phase. Length = %d. NumSGs = %d.\n",
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
|
1997-02-11 17:10:37 +00:00
|
|
|
scb->xs->datalen, scb->sg_count);
|
|
|
|
for (i = 0; i < scb->sg_count; i++) {
|
|
|
|
printf("sg[%d] - Addr 0x%x : Length %d\n",
|
|
|
|
i,
|
|
|
|
scb->ahc_dma[i].addr,
|
|
|
|
scb->ahc_dma[i].len);
|
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
/*
|
|
|
|
* Set this and it will take affect when the
|
|
|
|
* target does a command complete.
|
|
|
|
*/
|
|
|
|
scb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if NOT_YET
|
|
|
|
/* XXX Fill these in later */
|
|
|
|
case MESG_BUFFER_BUSY:
|
|
|
|
break;
|
|
|
|
case MSGIN_PHASEMIS:
|
|
|
|
break;
|
1996-11-16 01:19:14 +00:00
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
case SCB_TRACE_POINT:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Print out the bus phase
|
|
|
|
*/
|
|
|
|
char *phase;
|
|
|
|
u_int8_t scbindex = ahc_inb(ahc, SCB_TAG);
|
|
|
|
u_int8_t lastphase = ahc_inb(ahc, LASTPHASE);
|
|
|
|
|
|
|
|
scb = ahc->scb_data->scbarray[scbindex];
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
|
|
|
|
switch (lastphase) {
|
|
|
|
case P_DATAOUT:
|
|
|
|
phase = "Data-Out";
|
|
|
|
break;
|
|
|
|
case P_DATAIN:
|
|
|
|
phase = "Data-In";
|
|
|
|
break;
|
|
|
|
case P_COMMAND:
|
|
|
|
phase = "Command";
|
|
|
|
break;
|
|
|
|
case P_MESGOUT:
|
|
|
|
phase = "Message-Out";
|
|
|
|
break;
|
|
|
|
case P_STATUS:
|
|
|
|
phase = "Status";
|
|
|
|
break;
|
|
|
|
case P_MESGIN:
|
|
|
|
phase = "Message-In";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
phase = "busfree";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("- %s\n", phase);
|
|
|
|
break;
|
|
|
|
}
|
1996-05-30 07:19:59 +00:00
|
|
|
#endif
|
1997-02-25 03:05:35 +00:00
|
|
|
case ABORT_CMDCMPLT:
|
|
|
|
/* This interrupt serves to pause the sequencer
|
|
|
|
* until we can clean up the QOUTFIFO allowing us
|
|
|
|
* to hanle any abort SCBs that may have completed
|
|
|
|
* yet still have an SCB in the QINFIFO or
|
|
|
|
* waiting for selection queue. By the time we get
|
|
|
|
* here, we should have already cleaned up the
|
|
|
|
* queues, so all we need to do is unpause the sequencer.
|
|
|
|
*/
|
|
|
|
break;
|
1996-10-06 16:38:45 +00:00
|
|
|
default:
|
|
|
|
printf("ahc_intr: seqint, "
|
|
|
|
"intstat == 0x%x, scsisigi = 0x%x\n",
|
1996-11-11 05:24:46 +00:00
|
|
|
intstat, ahc_inb(ahc, SCSISIGI));
|
1996-10-06 16:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear:
|
|
|
|
/*
|
|
|
|
* Clear the upper byte that holds SEQINT status
|
|
|
|
* codes and clear the SEQINT bit.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRSEQINT);
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The sequencer is paused immediately on
|
|
|
|
* a SEQINT, so we should restart it when
|
|
|
|
* we're done.
|
|
|
|
*/
|
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1995-11-04 14:43:30 +00:00
|
|
|
}
|
1995-07-04 21:14:45 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
static void
|
|
|
|
ahc_handle_scsiint(ahc, intstat)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t intstat;
|
|
|
|
{
|
|
|
|
u_int8_t scb_index;
|
|
|
|
u_int8_t status;
|
|
|
|
struct scb *scb;
|
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
|
|
|
status = ahc_inb(ahc, SSTAT1);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-11-22 08:28:45 +00:00
|
|
|
if (scb_index < ahc->scb_data->numscbs) {
|
|
|
|
scb = ahc->scb_data->scbarray[scb_index];
|
|
|
|
if ((scb->flags & SCB_ACTIVE) == 0)
|
|
|
|
scb = NULL;
|
|
|
|
} else
|
|
|
|
scb = NULL;
|
|
|
|
|
|
|
|
if ((status & SCSIRSTI) != 0) {
|
1996-10-25 06:42:53 +00:00
|
|
|
char channel;
|
1996-11-11 05:24:46 +00:00
|
|
|
channel = (ahc_inb(ahc, SBLKCTL) & SELBUSB) ? 'B' : 'A';
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("%s: Someone reset channel %c\n",
|
|
|
|
ahc_name(ahc), channel);
|
|
|
|
ahc_reset_channel(ahc,
|
|
|
|
channel,
|
|
|
|
XS_BUSY,
|
|
|
|
/* Initiate Reset */FALSE);
|
|
|
|
scb = NULL;
|
1996-11-22 08:28:45 +00:00
|
|
|
} else if ((status & BUSFREE) != 0 && (status & SELTO) == 0) {
|
|
|
|
/*
|
|
|
|
* First look at what phase we were last in.
|
|
|
|
* If its message out, chances are pretty good
|
|
|
|
* that the busfree was in response to one of
|
|
|
|
* our abort requests.
|
|
|
|
*/
|
|
|
|
u_int8_t lastphase = ahc_inb(ahc, LASTPHASE);
|
|
|
|
u_int8_t target = (ahc_inb(ahc, SCSIID) >> 4) & 0x0f;
|
1997-02-25 03:05:35 +00:00
|
|
|
u_int8_t scbptr = ahc_inb(ahc, SCBPTR);
|
|
|
|
u_int8_t scb_control = ahc_inb(ahc, SCB_CONTROL);
|
1996-11-22 08:28:45 +00:00
|
|
|
char channel = ahc_inb(ahc, SBLKCTL) & SELBUSB ? 'B': 'A';
|
|
|
|
int printerror = 1;
|
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SCSISEQ, 0);
|
1996-11-22 08:28:45 +00:00
|
|
|
if (lastphase != P_BUSFREE) {
|
1997-03-16 07:12:07 +00:00
|
|
|
u_int8_t flags = ahc_inb(ahc, SEQ_FLAGS)
|
1996-11-22 08:28:45 +00:00
|
|
|
& (IDENTIFY_SEEN|RESELECTED);
|
|
|
|
|
|
|
|
if (flags == 0 || flags == (IDENTIFY_SEEN|RESELECTED)) {
|
|
|
|
/*
|
|
|
|
* We have an SCB we have to clean up.
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((scb_control & DISCONNECTED) != 0)
|
|
|
|
ahc_rem_scb_from_disc_list(ahc, scbptr);
|
|
|
|
else {
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_add_curscb_to_free_list(ahc);
|
1996-11-22 08:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we ask for this?? */
|
1997-02-25 03:05:35 +00:00
|
|
|
if ((lastphase == P_MESGOUT
|
|
|
|
|| lastphase == P_MESGIN) && scb != NULL) {
|
1996-11-22 08:28:45 +00:00
|
|
|
if (scb->flags & SCB_DEVICE_RESET) {
|
|
|
|
ahc_handle_devreset(ahc, scb);
|
1997-01-29 05:27:03 +00:00
|
|
|
scb = NULL;
|
1996-11-22 08:28:45 +00:00
|
|
|
printerror = 0;
|
1997-01-29 05:27:03 +00:00
|
|
|
} else if (scb->flags & SCB_ABORT) {
|
1997-02-18 04:25:31 +00:00
|
|
|
struct hardware_scb *hscb;
|
|
|
|
u_int8_t tag;
|
1997-02-25 03:05:35 +00:00
|
|
|
int lun;
|
1997-02-18 04:25:31 +00:00
|
|
|
|
|
|
|
hscb = scb->hscb;
|
|
|
|
tag = SCB_LIST_NULL;
|
1997-02-25 03:05:35 +00:00
|
|
|
lun = hscb->tcl & 0x7;
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("SCB %d - Abort "
|
|
|
|
"Completed.\n",
|
|
|
|
scbptr);
|
1997-02-18 04:25:31 +00:00
|
|
|
if (hscb->control & TAG_ENB)
|
|
|
|
tag = scb->hscb->tag;
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_reset_device(ahc,
|
|
|
|
target,
|
|
|
|
channel,
|
1997-02-25 03:05:35 +00:00
|
|
|
lun,
|
1997-02-18 04:25:31 +00:00
|
|
|
tag,
|
1997-01-29 05:27:03 +00:00
|
|
|
XS_TIMEOUT);
|
|
|
|
ahc_run_done_queue(ahc);
|
1997-01-22 18:05:31 +00:00
|
|
|
scb = NULL;
|
1996-11-22 08:28:45 +00:00
|
|
|
printerror = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (printerror != 0) {
|
|
|
|
if (scb != NULL) {
|
1997-02-25 03:05:35 +00:00
|
|
|
u_int8_t next;
|
|
|
|
ahc_index_busy_target(ahc, target,
|
|
|
|
channel, /*unbusy*/TRUE);
|
|
|
|
|
|
|
|
ahc_outb(ahc, SCBPTR, scbptr);
|
|
|
|
next = ahc_inb(ahc, SCB_LINKED_NEXT);
|
|
|
|
if (next != SCB_LIST_NULL) {
|
|
|
|
/*
|
|
|
|
* Re-queue the waiting SCB via the
|
|
|
|
* waiting list.
|
|
|
|
*/
|
|
|
|
struct scb *next_scb;
|
|
|
|
|
|
|
|
next_scb =
|
|
|
|
ahc->scb_data->scbarray[next];
|
|
|
|
STAILQ_INSERT_HEAD(&ahc->waiting_scbs,
|
|
|
|
next_scb, links);
|
|
|
|
next_scb->flags |= SCB_WAITINGQ;
|
|
|
|
}
|
1996-11-22 08:28:45 +00:00
|
|
|
scb->xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
ahc_done(ahc, scb);
|
1997-01-22 18:05:31 +00:00
|
|
|
scb = NULL;
|
1996-11-22 08:28:45 +00:00
|
|
|
} else
|
|
|
|
printf("%s: ", ahc_name(ahc));
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("Unexpected busfree. LASTPHASE == 0x%x\n"
|
|
|
|
"SEQADDR == 0x%x\n",
|
|
|
|
lastphase, (ahc_inb(ahc, SEQADDR1) << 8)
|
|
|
|
| ahc_inb(ahc, SEQADDR0));
|
1996-11-22 08:28:45 +00:00
|
|
|
}
|
1997-02-03 02:16:16 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
|
1996-12-03 17:06:00 +00:00
|
|
|
ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
|
|
|
|
restart_sequencer(ahc);
|
1997-02-09 03:26:56 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
1996-11-22 08:28:45 +00:00
|
|
|
} else if (scb == NULL) {
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("%s: ahc_intr - referenced scb not "
|
1997-03-16 07:12:07 +00:00
|
|
|
"valid during scsiint 0x%x scb(%d)\n"
|
|
|
|
"SIMODE0 = 0x%x, SIMODE1 = 0x%x, SSTAT0 = 0x%x\n"
|
|
|
|
"SEQADDR = 0x%x\n", ahc_name(ahc),
|
|
|
|
status, scb_index, ahc_inb(ahc, SIMODE0),
|
|
|
|
ahc_inb(ahc, SIMODE1), ahc_inb(ahc, SSTAT0),
|
|
|
|
(ahc_inb(ahc, SEQADDR1) << 8)
|
|
|
|
| ahc_inb(ahc, SEQADDR0));
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRSINT1, status);
|
1996-10-25 06:42:53 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
1996-10-25 06:42:53 +00:00
|
|
|
scb = NULL;
|
1996-11-22 08:28:45 +00:00
|
|
|
} else if ((status & SCSIPERR) != 0) {
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Determine the bus phase and
|
|
|
|
* queue an appropriate message
|
|
|
|
*/
|
|
|
|
char *phase;
|
|
|
|
u_int8_t mesg_out = MSG_NOOP;
|
1996-11-11 05:24:46 +00:00
|
|
|
u_int8_t lastphase = ahc_inb(ahc, LASTPHASE);
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
|
|
|
|
xs = scb->xs;
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
|
|
|
|
switch (lastphase) {
|
|
|
|
case P_DATAOUT:
|
|
|
|
phase = "Data-Out";
|
|
|
|
break;
|
|
|
|
case P_DATAIN:
|
|
|
|
phase = "Data-In";
|
|
|
|
mesg_out = MSG_INITIATOR_DET_ERR;
|
|
|
|
break;
|
|
|
|
case P_COMMAND:
|
|
|
|
phase = "Command";
|
|
|
|
break;
|
|
|
|
case P_MESGOUT:
|
|
|
|
phase = "Message-Out";
|
|
|
|
break;
|
|
|
|
case P_STATUS:
|
|
|
|
phase = "Status";
|
|
|
|
mesg_out = MSG_INITIATOR_DET_ERR;
|
|
|
|
break;
|
|
|
|
case P_MESGIN:
|
|
|
|
phase = "Message-In";
|
|
|
|
mesg_out = MSG_PARITY_ERROR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
phase = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("parity error during %s phase.\n", phase);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've set the hardware to assert ATN if we
|
|
|
|
* get a parity error on "in" phases, so all we
|
|
|
|
* need to do is stuff the message buffer with
|
|
|
|
* the appropriate message. "In" phases have set
|
|
|
|
* mesg_out to something other than MSG_NOP.
|
|
|
|
*/
|
|
|
|
if (mesg_out != MSG_NOOP) {
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT, mesg_out);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, 1);
|
1997-01-29 05:27:03 +00:00
|
|
|
scb = NULL;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else
|
|
|
|
/*
|
|
|
|
* Should we allow the target to make
|
1997-01-29 05:27:03 +00:00
|
|
|
* this decision for us? If we get a
|
|
|
|
* sense request from the drive, we will
|
|
|
|
* not fetch it since xs->error != XS_NOERROR.
|
|
|
|
* perhaps we need two error fields in the
|
|
|
|
* xs structure?
|
1996-10-25 06:42:53 +00:00
|
|
|
*/
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
|
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
1996-11-22 08:28:45 +00:00
|
|
|
} else if ((status & SELTO) != 0) {
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
u_int8_t scbptr;
|
|
|
|
u_int8_t nextscb;
|
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
/*
|
|
|
|
* XXX If we queued an abort tag, go clean up the
|
|
|
|
* disconnected list.
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
xs = scb->xs;
|
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
/*
|
|
|
|
* Clear any pending messages for the timed out
|
|
|
|
* target, and mark the target as free
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, 0);
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_index_busy_target(ahc, xs->sc_link->target,
|
|
|
|
IS_SCSIBUS_B(ahc, xs->sc_link) ? 'B' : 'A',
|
|
|
|
/*unbusy*/TRUE);
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Stop the selection */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCSISEQ, 0);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCB_CONTROL, 0);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-12-03 17:06:00 +00:00
|
|
|
ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
/* Shift the waiting Q forward. */
|
1996-11-11 05:24:46 +00:00
|
|
|
scbptr = ahc_inb(ahc, WAITING_SCBH);
|
|
|
|
ahc_outb(ahc, SCBPTR, scbptr);
|
|
|
|
nextscb = ahc_inb(ahc, SCB_NEXT);
|
|
|
|
ahc_outb(ahc, WAITING_SCBH, nextscb);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_add_curscb_to_free_list(ahc);
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
restart_sequencer(ahc);
|
1996-11-22 08:28:45 +00:00
|
|
|
} else {
|
1996-10-25 06:42:53 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("Unknown SCSIINT. Status = 0x%x\n", status);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRSINT1, status);
|
1996-10-25 06:42:53 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
1996-10-25 06:42:53 +00:00
|
|
|
scb = NULL;
|
|
|
|
}
|
|
|
|
if (scb != NULL) {
|
|
|
|
/* We want to process the command */
|
|
|
|
ahc_done(ahc, scb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-11-22 08:28:45 +00:00
|
|
|
static void
|
|
|
|
ahc_handle_devreset(ahc, scb)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
struct scb *scb;
|
|
|
|
{
|
|
|
|
u_int16_t targ_mask;
|
|
|
|
u_int8_t targ_scratch;
|
1997-02-25 03:05:35 +00:00
|
|
|
int target = scb->xs->sc_link->target;
|
|
|
|
int lun = scb->xs->sc_link->lun;
|
1996-11-22 08:28:45 +00:00
|
|
|
int scratch_offset = target;
|
|
|
|
char channel = (scb->hscb->tcl & SELBUSB) ? 'B': 'A';
|
|
|
|
int found;
|
|
|
|
|
|
|
|
if (channel == 'B')
|
|
|
|
scratch_offset += 8;
|
|
|
|
targ_mask = (0x01 << scratch_offset);
|
|
|
|
/*
|
|
|
|
* Go back to async/narrow transfers and
|
|
|
|
* renegotiate.
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_index_busy_target(ahc, target, channel, /*unbusy*/TRUE);
|
1996-11-22 08:28:45 +00:00
|
|
|
ahc->needsdtr |= ahc->needsdtr_orig & targ_mask;
|
|
|
|
ahc->needwdtr |= ahc->needwdtr_orig & targ_mask;
|
|
|
|
ahc->sdtrpending &= ~targ_mask;
|
|
|
|
ahc->wdtrpending &= ~targ_mask;
|
|
|
|
targ_scratch = ahc_inb(ahc, TARG_SCRATCH + scratch_offset);
|
|
|
|
targ_scratch &= SXFR;
|
|
|
|
ahc_outb(ahc, TARG_SCRATCH + scratch_offset, targ_scratch);
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1997-02-25 03:05:35 +00:00
|
|
|
found = ahc_reset_device(ahc, target, channel, lun,
|
|
|
|
SCB_LIST_NULL, XS_NOERROR);
|
1996-11-22 08:28:45 +00:00
|
|
|
printf("Bus Device Reset delivered. %d SCBs aborted\n", found);
|
|
|
|
ahc_run_done_queue(ahc);
|
|
|
|
}
|
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
|
|
|
* We have a scb which has been processed by the
|
|
|
|
* adaptor, now we look to see how the operation
|
|
|
|
* went.
|
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1996-01-03 06:32:12 +00:00
|
|
|
ahc_done(ahc, scb)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-03-31 03:15:31 +00:00
|
|
|
struct scb *scb;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-03-31 03:15:31 +00:00
|
|
|
struct scsi_xfer *xs = scb->xs;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-03-31 03:15:31 +00:00
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB2, ("ahc_done\n"));
|
1997-02-25 03:05:35 +00:00
|
|
|
/*
|
|
|
|
* If the recovery SCB completes, we have to be
|
|
|
|
* out of our timeout.
|
|
|
|
*/
|
|
|
|
if (scb->flags & SCB_RECOVERY_SCB) {
|
|
|
|
ahc->in_timeout = FALSE;
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("no longer in timeout\n");
|
|
|
|
}
|
1996-03-31 03:15:31 +00:00
|
|
|
/*
|
|
|
|
* Put the results of the operation
|
|
|
|
* into the xfer and call whoever started it
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
/* Don't override the error value. */
|
|
|
|
if (xs->error == XS_NOERROR
|
|
|
|
&& (scb->flags & SCB_SENSE) != 0)
|
1994-12-31 19:31:56 +00:00
|
|
|
xs->error = XS_SENSE;
|
1997-02-19 01:00:51 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1996-03-31 03:15:31 +00:00
|
|
|
if ((xs->flags & SCSI_ERR_OK) && !(xs->error == XS_SENSE)) {
|
1994-11-17 20:22:31 +00:00
|
|
|
/* All went correctly OR errors expected */
|
1996-03-31 03:15:31 +00:00
|
|
|
xs->error = XS_NOERROR;
|
|
|
|
}
|
1996-05-30 07:19:59 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
/*
|
|
|
|
* Since NetBSD doesn't have error ignoring operation mode
|
|
|
|
* (SCSI_ERR_OK in FreeBSD), we don't have to care this case.
|
|
|
|
*/
|
|
|
|
#endif
|
1996-03-31 03:15:31 +00:00
|
|
|
xs->flags |= ITSDONE;
|
1996-04-28 19:21:20 +00:00
|
|
|
#ifdef AHC_TAGENABLE
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
1997-01-29 05:27:03 +00:00
|
|
|
* This functionality will be provided by the generic SCSI layer
|
|
|
|
* in FreeBSD 3.0.
|
1996-10-25 06:42:53 +00:00
|
|
|
*/
|
|
|
|
if (xs->cmd->opcode == INQUIRY && xs->error == XS_NOERROR) {
|
1995-02-22 01:43:25 +00:00
|
|
|
struct scsi_inquiry_data *inq_data;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int16_t mask = 0x01 << (xs->sc_link->target |
|
|
|
|
(scb->hscb->tcl & 0x08));
|
1995-02-22 01:43:25 +00:00
|
|
|
/*
|
|
|
|
* Sneak a look at the results of the SCSI Inquiry
|
|
|
|
* command and see if we can do Tagged queing. This
|
|
|
|
* should really be done by the higher level drivers.
|
|
|
|
*/
|
|
|
|
inq_data = (struct scsi_inquiry_data *)xs->data;
|
1996-10-25 06:42:53 +00:00
|
|
|
if ((inq_data->flags & SID_CmdQue)
|
|
|
|
&& !(ahc->tagenable & mask)) {
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: target %d Tagged Queuing Device\n",
|
|
|
|
ahc_name(ahc), xs->sc_link->target);
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->tagenable |= mask;
|
1996-10-28 06:10:02 +00:00
|
|
|
if (ahc->scb_data->maxhscbs >= 16
|
|
|
|
|| (ahc->flags & AHC_PAGESCBS)) {
|
1996-04-20 21:29:27 +00:00
|
|
|
/* Default to 8 tags */
|
1997-03-01 06:50:41 +00:00
|
|
|
xs->sc_link->opennings += 13;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1996-04-20 21:29:27 +00:00
|
|
|
/*
|
|
|
|
* Default to 4 tags on whimpy
|
|
|
|
* cards that don't have much SCB
|
|
|
|
* space and can't page. This prevents
|
|
|
|
* a single device from hogging all
|
|
|
|
* slots. We should really have a better
|
|
|
|
* way of providing fairness.
|
|
|
|
*/
|
|
|
|
xs->sc_link->opennings += 2;
|
|
|
|
}
|
1995-02-22 01:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
#endif /* AHC_TAGENABLE */
|
1997-01-22 18:05:31 +00:00
|
|
|
if ((scb->flags & SCB_MSGOUT_WDTR|SCB_MSGOUT_SDTR) != 0) {
|
|
|
|
/*
|
|
|
|
* Turn off the pending flags for any DTR messages
|
|
|
|
* regardless of whether they completed successfully
|
|
|
|
* or not. This ensures that we don't have lingering
|
|
|
|
* state after we abort an SCB.
|
|
|
|
*/
|
|
|
|
u_int16_t mask;
|
|
|
|
|
|
|
|
mask = (0x01 << (xs->sc_link->target
|
|
|
|
| (IS_SCSIBUS_B(ahc, xs->sc_link) ? SELBUSB : 0)));
|
|
|
|
if (scb->flags & SCB_MSGOUT_WDTR)
|
|
|
|
ahc->wdtrpending &= ~mask;
|
|
|
|
if (scb->flags & SCB_MSGOUT_SDTR)
|
|
|
|
ahc->sdtrpending &= ~mask;
|
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
untimeout(ahc_timeout, (caddr_t)scb);
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc_free_scb(ahc, scb);
|
1997-03-16 07:12:07 +00:00
|
|
|
/*
|
|
|
|
* If we're polling, we rely on the ITS_DONE flag in the xs structure
|
|
|
|
* to know that the command has completed. Unfortunately, scsi_done
|
|
|
|
* can cause the same xs to get requeued putting us in an infinite
|
|
|
|
* loop. So, we defer the scsi_done call until the poll routine exits
|
|
|
|
* its loop. I hate the way this works.
|
|
|
|
*/
|
|
|
|
if ((xs->flags & SCSI_NOMASK) == 0)
|
|
|
|
scsi_done(xs);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the board, ready for normal operation
|
|
|
|
*/
|
1995-11-05 04:50:55 +00:00
|
|
|
int
|
1996-01-03 06:32:12 +00:00
|
|
|
ahc_init(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1997-01-24 21:59:32 +00:00
|
|
|
u_int8_t scsi_conf, sblkctl, sxfrctl1, i;
|
1996-10-06 16:38:45 +00:00
|
|
|
u_int16_t ultraenable = 0;
|
1996-10-25 06:42:53 +00:00
|
|
|
int max_targ = 15;
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
1995-11-05 04:50:55 +00:00
|
|
|
* Assume we have a board at this stage and it has been reset.
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
|
|
|
|
1996-04-20 21:29:27 +00:00
|
|
|
/* Handle the SCBPAGING option */
|
|
|
|
#ifndef AHC_SCBPAGING_ENABLE
|
|
|
|
ahc->flags &= ~AHC_PAGESCBS;
|
|
|
|
#endif
|
|
|
|
|
1996-03-31 03:15:31 +00:00
|
|
|
/* Determine channel configuration and who we are on the scsi bus. */
|
1996-11-11 05:24:46 +00:00
|
|
|
switch ((sblkctl = ahc_inb(ahc, SBLKCTL) & 0x0a)) {
|
1996-10-25 06:42:53 +00:00
|
|
|
case 0:
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->our_id = (ahc_inb(ahc, SCSICONF) & HSCSIID);
|
1996-05-10 16:21:05 +00:00
|
|
|
ahc->flags &= ~AHC_CHANNEL_B_PRIMARY;
|
1996-10-28 06:10:02 +00:00
|
|
|
if ((ahc->type & AHC_39X) != 0) {
|
|
|
|
char channel = 'A';
|
|
|
|
|
|
|
|
if ((ahc->flags & (AHC_CHNLB|AHC_CHNLC)) != 0)
|
|
|
|
channel = ahc->flags & AHC_CHNLB ? 'B' : 'C';
|
|
|
|
printf("Channel %c, SCSI Id=%d, ", channel,
|
1995-09-05 23:52:03 +00:00
|
|
|
ahc->our_id);
|
1996-10-28 06:10:02 +00:00
|
|
|
} else
|
1995-09-05 23:52:03 +00:00
|
|
|
printf("Single Channel, SCSI Id=%d, ", ahc->our_id);
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SEQ_FLAGS, ahc->flags & AHC_PAGESCBS);
|
1996-03-31 03:15:31 +00:00
|
|
|
break;
|
1996-10-25 06:42:53 +00:00
|
|
|
case 2:
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->our_id = (ahc_inb(ahc, SCSICONF + 1) & HWSCSIID);
|
1996-05-10 16:21:05 +00:00
|
|
|
ahc->flags &= ~AHC_CHANNEL_B_PRIMARY;
|
1996-10-28 06:10:02 +00:00
|
|
|
if ((ahc->type & AHC_39X) != 0) {
|
|
|
|
char channel = 'A';
|
|
|
|
|
|
|
|
if ((ahc->flags & (AHC_CHNLB|AHC_CHNLC)) != 0)
|
|
|
|
channel = ahc->flags & AHC_CHNLB ? 'B' : 'C';
|
|
|
|
printf("Wide Channel %c, SCSI Id=%d, ", channel,
|
1995-09-05 23:52:03 +00:00
|
|
|
ahc->our_id);
|
1996-10-28 06:10:02 +00:00
|
|
|
} else
|
1995-09-05 23:52:03 +00:00
|
|
|
printf("Wide Channel, SCSI Id=%d, ", ahc->our_id);
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->type |= AHC_WIDE;
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SEQ_FLAGS, WIDE_BUS | (ahc->flags & AHC_PAGESCBS));
|
1996-03-31 03:15:31 +00:00
|
|
|
break;
|
1996-10-25 06:42:53 +00:00
|
|
|
case 8:
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->our_id = (ahc_inb(ahc, SCSICONF) & HSCSIID);
|
|
|
|
ahc->our_id_b = (ahc_inb(ahc, SCSICONF + 1) & HSCSIID);
|
1996-03-31 03:15:31 +00:00
|
|
|
printf("Twin Channel, A SCSI Id=%d, B SCSI Id=%d, ",
|
1995-01-13 02:24:31 +00:00
|
|
|
ahc->our_id, ahc->our_id_b);
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->type |= AHC_TWIN;
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SEQ_FLAGS, TWIN_BUS | (ahc->flags & AHC_PAGESCBS));
|
1996-03-31 03:15:31 +00:00
|
|
|
break;
|
1996-10-25 06:42:53 +00:00
|
|
|
default:
|
1996-03-31 03:15:31 +00:00
|
|
|
printf(" Unsupported adapter type. Ignoring\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Determine the number of SCBs and initialize them */
|
1996-03-31 03:15:31 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
if (ahc->scb_data->maxhscbs == 0) {
|
1996-10-25 06:42:53 +00:00
|
|
|
/* SCB 0 heads the free list */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, FREE_SCBH, 0);
|
1996-10-25 06:42:53 +00:00
|
|
|
for (i = 0; i < AHC_SCB_MAX; i++) {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, i);
|
|
|
|
ahc_outb(ahc, SCB_CONTROL, i);
|
|
|
|
if(ahc_inb(ahc, SCB_CONTROL) != i)
|
1996-04-20 21:29:27 +00:00
|
|
|
break;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, 0);
|
|
|
|
if(ahc_inb(ahc, SCB_CONTROL) != 0)
|
1996-04-20 21:29:27 +00:00
|
|
|
break;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, i);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
/* Clear the control byte. */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCB_CONTROL, 0);
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Set the next pointer */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCB_NEXT, i+1);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
/* Make the tag number invalid */
|
|
|
|
ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/* No Busy non-tagged targets yet */
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SCB_BUSYTARGETS, SCB_LIST_NULL);
|
|
|
|
ahc_outb(ahc, SCB_BUSYTARGETS + 1, SCB_LIST_NULL);
|
|
|
|
ahc_outb(ahc, SCB_BUSYTARGETS + 2, SCB_LIST_NULL);
|
|
|
|
ahc_outb(ahc, SCB_BUSYTARGETS + 3, SCB_LIST_NULL);
|
1996-03-31 03:15:31 +00:00
|
|
|
}
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Make that the last SCB terminates the free list */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, i-1);
|
|
|
|
ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-04-20 21:29:27 +00:00
|
|
|
/* Ensure we clear the 0 SCB's control byte. */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, 0);
|
|
|
|
ahc_outb(ahc, SCB_CONTROL, 0);
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->maxhscbs = i;
|
1996-03-31 03:15:31 +00:00
|
|
|
}
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
if ((ahc->scb_data->maxhscbs < AHC_SCB_MAX)
|
|
|
|
&& (ahc->flags & AHC_PAGESCBS)) {
|
1996-11-16 01:19:14 +00:00
|
|
|
u_int8_t max_scbid = 255;
|
|
|
|
|
|
|
|
/* Determine the number of valid bits in the FIFOs */
|
|
|
|
ahc_outb(ahc, QINFIFO, max_scbid);
|
|
|
|
max_scbid = ahc_inb(ahc, QINFIFO);
|
|
|
|
ahc->scb_data->maxscbs = MIN(AHC_SCB_MAX, max_scbid + 1);
|
1996-10-28 06:10:02 +00:00
|
|
|
printf("%d/%d SCBs\n", ahc->scb_data->maxhscbs,
|
|
|
|
ahc->scb_data->maxscbs);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->maxscbs = ahc->scb_data->maxhscbs;
|
1996-04-20 21:29:27 +00:00
|
|
|
ahc->flags &= ~AHC_PAGESCBS;
|
1996-10-28 06:10:02 +00:00
|
|
|
printf("%d SCBs\n", ahc->scb_data->maxhscbs);
|
1996-04-20 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
1996-01-03 06:32:12 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc_debug & AHC_SHOWMISC) {
|
|
|
|
printf("%s: hardware scb %d bytes; kernel scb %d bytes; "
|
1996-01-03 06:32:12 +00:00
|
|
|
"ahc_dma %d bytes\n",
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_name(ahc),
|
1996-10-25 06:42:53 +00:00
|
|
|
sizeof(struct hardware_scb),
|
|
|
|
sizeof(struct scb),
|
1996-01-03 06:32:12 +00:00
|
|
|
sizeof(struct ahc_dma_seg));
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1996-01-03 06:32:12 +00:00
|
|
|
#endif /* AHC_DEBUG */
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1995-10-26 23:57:18 +00:00
|
|
|
/* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_TWIN) {
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-01-22 00:48:39 +00:00
|
|
|
* The device is gated to channel B after a chip reset,
|
|
|
|
* so set those values first
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCSIID, ahc->our_id_b);
|
|
|
|
scsi_conf = ahc_inb(ahc, SCSICONF + 1);
|
1997-01-24 21:59:32 +00:00
|
|
|
sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
|
1997-01-24 21:59:32 +00:00
|
|
|
|(sxfrctl1 & STPWEN)
|
|
|
|
|ENSTIMER|ACTNEGEN);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_ULTRA)
|
1997-02-09 03:26:56 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN|FAST20);
|
1995-10-29 05:57:48 +00:00
|
|
|
else
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (scsi_conf & RESET_SCSI) {
|
1996-05-10 16:21:05 +00:00
|
|
|
/* Reset the bus */
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("%s: Resetting Channel B\n",
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_name(ahc));
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_reset_current_bus(ahc);
|
1996-05-10 16:21:05 +00:00
|
|
|
}
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1995-01-22 00:48:39 +00:00
|
|
|
/* Select Channel A */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SBLKCTL, 0);
|
1995-01-22 00:48:39 +00:00
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCSIID, ahc->our_id);
|
|
|
|
scsi_conf = ahc_inb(ahc, SCSICONF);
|
1997-01-24 21:59:32 +00:00
|
|
|
sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
|
1997-01-24 21:59:32 +00:00
|
|
|
|(sxfrctl1 & STPWEN)
|
|
|
|
|ENSTIMER|ACTNEGEN);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_ULTRA)
|
1997-02-09 03:26:56 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN|FAST20);
|
1995-10-29 05:57:48 +00:00
|
|
|
else
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (scsi_conf & RESET_SCSI) {
|
1996-05-10 16:21:05 +00:00
|
|
|
/* Reset the bus */
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1997-03-16 07:12:07 +00:00
|
|
|
printf("%s: Resetting Channel A\n", ahc_name(ahc));
|
1996-05-10 16:21:05 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_reset_current_bus(ahc);
|
1996-05-10 16:21:05 +00:00
|
|
|
}
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
1994-12-31 19:31:56 +00:00
|
|
|
* Look at the information that board initialization or
|
|
|
|
* the board bios has left us. In the lower four bits of each
|
|
|
|
* target's scratch space any value other than 0 indicates
|
1997-03-16 07:12:07 +00:00
|
|
|
* that we should initiate synchronous transfers. If it's zero,
|
|
|
|
* the user or the BIOS has decided to disable synchronous
|
1996-01-03 06:32:12 +00:00
|
|
|
* negotiation to that target so we don't activate the needsdtr
|
1994-12-31 19:31:56 +00:00
|
|
|
* flag.
|
|
|
|
*/
|
1995-01-16 16:33:47 +00:00
|
|
|
ahc->needsdtr_orig = 0;
|
|
|
|
ahc->needwdtr_orig = 0;
|
1995-07-04 21:14:45 +00:00
|
|
|
|
|
|
|
/* Grab the disconnection disable table and invert it for our needs */
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->flags & AHC_USEDEFAULTS) {
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: Host Adapter Bios disabled. Using default SCSI "
|
|
|
|
"device parameters\n", ahc_name(ahc));
|
1995-07-04 21:14:45 +00:00
|
|
|
ahc->discenable = 0xff;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
|
|
|
|
| ahc_inb(ahc, DISC_DSB));
|
1995-07-04 21:14:45 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (!(ahc->type & (AHC_WIDE|AHC_TWIN)))
|
1995-09-05 23:52:03 +00:00
|
|
|
max_targ = 7;
|
1995-03-31 13:54:41 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
for (i = 0; i <= max_targ; i++) {
|
|
|
|
u_int8_t target_settings;
|
1996-01-03 06:32:12 +00:00
|
|
|
if (ahc->flags & AHC_USEDEFAULTS) {
|
1997-01-29 05:27:03 +00:00
|
|
|
target_settings = 0; /* 10MHz/20MHz */
|
1995-07-04 21:14:45 +00:00
|
|
|
ahc->needsdtr_orig |= (0x01 << i);
|
1995-01-16 16:33:47 +00:00
|
|
|
ahc->needwdtr_orig |= (0x01 << i);
|
1997-01-29 05:27:03 +00:00
|
|
|
if (ahc->type & AHC_ULTRA)
|
|
|
|
ultraenable |= (0x01 << i);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1995-07-04 21:14:45 +00:00
|
|
|
/* Take the settings leftover in scratch RAM. */
|
1996-11-11 05:24:46 +00:00
|
|
|
target_settings = ahc_inb(ahc, TARG_SCRATCH + i);
|
1995-07-04 21:14:45 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (target_settings & 0x0f) {
|
1995-07-04 21:14:45 +00:00
|
|
|
ahc->needsdtr_orig |= (0x01 << i);
|
1997-03-16 07:12:07 +00:00
|
|
|
/*Default to a asynchronous transfers(0 offset)*/
|
1995-07-04 21:14:45 +00:00
|
|
|
target_settings &= 0xf0;
|
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
if (target_settings & 0x80) {
|
1995-07-04 21:14:45 +00:00
|
|
|
ahc->needwdtr_orig |= (0x01 << i);
|
|
|
|
/*
|
|
|
|
* We'll set the Wide flag when we
|
1996-01-03 06:32:12 +00:00
|
|
|
* are successful with Wide negotiation.
|
|
|
|
* Turn it off for now so we aren't
|
1995-07-04 21:14:45 +00:00
|
|
|
* confused.
|
|
|
|
*/
|
|
|
|
target_settings &= 0x7f;
|
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->type & AHC_ULTRA) {
|
1996-05-21 18:37:25 +00:00
|
|
|
/*
|
|
|
|
* Enable Ultra for any target that
|
|
|
|
* has a valid ultra syncrate setting.
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t rate = target_settings & 0x70;
|
|
|
|
if (rate == 0x00 || rate == 0x10 ||
|
|
|
|
rate == 0x20 || rate == 0x40) {
|
|
|
|
if (rate == 0x40) {
|
1996-05-23 15:02:18 +00:00
|
|
|
/* Treat 10MHz specially */
|
|
|
|
target_settings &= ~0x70;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else
|
1996-05-23 15:02:18 +00:00
|
|
|
ultraenable |= (0x01 << i);
|
|
|
|
}
|
1996-05-21 18:37:25 +00:00
|
|
|
}
|
1995-01-13 02:24:31 +00:00
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, TARG_SCRATCH+i,target_settings);
|
1994-12-31 19:31:56 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-02-22 01:43:25 +00:00
|
|
|
* If we are not a WIDE device, forget WDTR. This
|
|
|
|
* makes the driver work on some cards that don't
|
|
|
|
* leave these fields cleared when the BIOS is not
|
|
|
|
* installed.
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if ((ahc->type & AHC_WIDE) == 0)
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->needwdtr_orig = 0;
|
1995-03-07 08:59:28 +00:00
|
|
|
ahc->needsdtr = ahc->needsdtr_orig;
|
1995-01-16 16:33:47 +00:00
|
|
|
ahc->needwdtr = ahc->needwdtr_orig;
|
1995-02-03 17:15:12 +00:00
|
|
|
ahc->sdtrpending = 0;
|
|
|
|
ahc->wdtrpending = 0;
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->tagenable = 0;
|
1996-04-28 19:21:20 +00:00
|
|
|
ahc->orderedtag = 0;
|
1995-03-17 23:58:27 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, ULTRA_ENB, ultraenable & 0xff);
|
|
|
|
ahc_outb(ahc, ULTRA_ENB + 1, (ultraenable >> 8) & 0xff);
|
1996-05-21 18:37:25 +00:00
|
|
|
|
1996-01-03 06:32:12 +00:00
|
|
|
#ifdef AHC_DEBUG
|
|
|
|
/* How did we do? */
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc_debug & AHC_SHOWMISC)
|
1996-01-03 06:32:12 +00:00
|
|
|
printf("NEEDSDTR == 0x%x\nNEEDWDTR == 0x%x\n"
|
|
|
|
"DISCENABLE == 0x%x\n", ahc->needsdtr,
|
|
|
|
ahc->needwdtr, ahc->discenable);
|
|
|
|
#endif
|
1994-12-31 19:31:56 +00:00
|
|
|
/*
|
1997-03-16 07:12:07 +00:00
|
|
|
* Set the number of available hardware SCBs
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBCOUNT, ahc->scb_data->maxhscbs);
|
1996-01-03 06:32:12 +00:00
|
|
|
|
|
|
|
/*
|
1996-04-20 21:29:27 +00:00
|
|
|
* 2's compliment of maximum tag value
|
1996-01-03 06:32:12 +00:00
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
i = ahc->scb_data->maxscbs;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, COMP_SCBCOUNT, -i & 0xff);
|
1994-12-31 19:31:56 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Allocate enough "hardware scbs" to handle
|
|
|
|
* the maximum number of concurrent transactions
|
|
|
|
* we can have active. We have to use contigmalloc
|
|
|
|
* if this array crosses a page boundary since the
|
|
|
|
* sequencer depends on this array being physically
|
|
|
|
* contiguous.
|
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
if (ahc->scb_data->hscbs == NULL) {
|
1996-10-25 06:42:53 +00:00
|
|
|
size_t array_size;
|
|
|
|
u_int32_t hscb_physaddr;
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
array_size = ahc->scb_data->maxscbs*sizeof(struct hardware_scb);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (array_size > PAGE_SIZE) {
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->hscbs = (struct hardware_scb *)
|
1997-02-25 03:05:35 +00:00
|
|
|
contigmalloc(array_size, M_DEVBUF,
|
|
|
|
M_NOWAIT, 0ul, 0xffffffff,
|
|
|
|
PAGE_SIZE, 0x10000);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->hscbs = (struct hardware_scb *)
|
1996-10-25 06:42:53 +00:00
|
|
|
malloc(array_size, M_DEVBUF, M_NOWAIT);
|
|
|
|
}
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
if (ahc->scb_data->hscbs == NULL) {
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("%s: unable to allocate hardware SCB array. "
|
|
|
|
"Failing attach\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
1996-11-07 06:39:44 +00:00
|
|
|
/* At least the control byte of each hscb needs to be zeroed */
|
|
|
|
bzero(ahc->scb_data->hscbs, array_size);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
/* Tell the sequencer where it can find the hscb array. */
|
1996-10-28 06:10:02 +00:00
|
|
|
hscb_physaddr = vtophys(ahc->scb_data->hscbs);
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, HSCB_ADDR, hscb_physaddr & 0xFF);
|
|
|
|
ahc_outb(ahc, HSCB_ADDR + 1, (hscb_physaddr >> 8)& 0xFF);
|
|
|
|
ahc_outb(ahc, HSCB_ADDR + 2, (hscb_physaddr >> 16)& 0xFF);
|
|
|
|
ahc_outb(ahc, HSCB_ADDR + 3, (hscb_physaddr >> 24)& 0xFF);
|
1996-10-25 06:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Q-Full-Count. Some cards have more Q space
|
|
|
|
* then SCBs.
|
|
|
|
*/
|
|
|
|
if (ahc->type & AHC_AIC7770) {
|
|
|
|
ahc->qfullcount = 4;
|
|
|
|
ahc->qcntmask = 0x07;
|
|
|
|
} else if (ahc->type & AHC_AIC7850) {
|
|
|
|
ahc->qfullcount = 8;
|
|
|
|
ahc->qcntmask = 0x0f;
|
1996-10-28 06:10:02 +00:00
|
|
|
} else if (ahc->scb_data->maxhscbs == 255) {
|
1996-10-25 06:42:53 +00:00
|
|
|
/* 7870/7880 with external SRAM */
|
|
|
|
ahc->qfullcount = 255;
|
|
|
|
ahc->qcntmask = 0xff;
|
|
|
|
} else {
|
|
|
|
/* 7870/7880 */
|
|
|
|
ahc->qfullcount = 16;
|
|
|
|
ahc->qcntmask = 0x1f;
|
|
|
|
}
|
|
|
|
|
1996-03-31 03:15:31 +00:00
|
|
|
/*
|
|
|
|
* QCount mask to deal with broken aic7850s that
|
1997-03-16 07:12:07 +00:00
|
|
|
* sporadically get garbage in the upper bits of
|
1996-03-31 03:15:31 +00:00
|
|
|
* their QCount registers.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, QCNTMASK, ahc->qcntmask);
|
|
|
|
|
1995-04-27 17:47:17 +00:00
|
|
|
/* We don't have any waiting selections */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
|
1996-04-20 21:29:27 +00:00
|
|
|
|
|
|
|
/* Our disconnection list is empty too */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
|
1996-01-03 06:32:12 +00:00
|
|
|
|
|
|
|
/* Message out buffer starts empty */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, 0x00);
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1995-03-07 08:59:28 +00:00
|
|
|
/*
|
1996-01-03 06:32:12 +00:00
|
|
|
* Load the Sequencer program and Enable the adapter
|
|
|
|
* in "fast" mode.
|
1995-03-07 08:59:28 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: Downloading Sequencer Program...",
|
|
|
|
ahc_name(ahc));
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_loadseq(ahc);
|
1996-01-03 06:32:12 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (bootverbose)
|
1995-09-05 23:52:03 +00:00
|
|
|
printf("Done\n");
|
1995-03-07 08:59:28 +00:00
|
|
|
|
1996-10-06 16:38:45 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
/* Notify us when the system can handle timeouts */
|
|
|
|
timeout(ahc_first_timeout, NULL, 0);
|
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
|
|
|
* Note that we are going and return (to probe)
|
|
|
|
*/
|
1996-04-20 21:29:27 +00:00
|
|
|
ahc->flags |= AHC_INIT;
|
1994-11-17 20:22:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1994-11-17 20:22:31 +00:00
|
|
|
ahcminphys(bp)
|
1995-05-30 08:16:23 +00:00
|
|
|
struct buf *bp;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-01-13 02:24:31 +00:00
|
|
|
* Even though the card can transfer up to 16megs per command
|
1994-11-17 20:22:31 +00:00
|
|
|
* we are limited by the number of segments in the dma segment
|
|
|
|
* list that we can hold. The worst case is that all pages are
|
|
|
|
* discontinuous physically, hense the "page per segment" limit
|
|
|
|
* enforced here.
|
|
|
|
*/
|
1996-05-21 18:37:25 +00:00
|
|
|
if (bp->b_bcount > ((AHC_NSEG - 1) * PAGE_SIZE)) {
|
|
|
|
bp->b_bcount = ((AHC_NSEG - 1) * PAGE_SIZE);
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1996-05-30 07:19:59 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
minphys(bp);
|
|
|
|
#endif
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start a scsi operation given the command and
|
1995-05-30 08:16:23 +00:00
|
|
|
* the data address, target, and lun all of which
|
1994-11-17 20:22:31 +00:00
|
|
|
* are stored in the scsi_xfer struct
|
|
|
|
*/
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
static int32_t
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc_scsi_cmd(xs)
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scb *scb;
|
|
|
|
struct hardware_scb *hscb;
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int16_t mask;
|
|
|
|
int flags;
|
|
|
|
int s;
|
1995-01-13 02:24:31 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc = (struct ahc_softc *)xs->sc_link->adapter_softc;
|
1996-06-23 20:02:37 +00:00
|
|
|
mask = (0x01 << (xs->sc_link->target
|
1997-02-03 02:16:16 +00:00
|
|
|
| (IS_SCSIBUS_B(ahc, xs->sc_link) ? SELBUSB : 0)));
|
1996-06-23 20:02:37 +00:00
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB2, ("ahc_scsi_cmd\n"));
|
1996-10-25 06:42:53 +00:00
|
|
|
flags = xs->flags;
|
1997-01-29 05:27:03 +00:00
|
|
|
|
|
|
|
if (ahc->in_reset != 0) {
|
|
|
|
/*
|
|
|
|
* If we are still in a reset, send the transaction
|
|
|
|
* back indicating that it was aborted due to a
|
|
|
|
* reset.
|
|
|
|
*/
|
|
|
|
if ((IS_SCSIBUS_B(ahc, xs->sc_link)
|
|
|
|
&& (ahc->in_reset & CHANNEL_B_RESET) != 0)
|
|
|
|
|| (!IS_SCSIBUS_B(ahc, xs->sc_link)
|
|
|
|
&& (ahc->in_reset & CHANNEL_A_RESET) != 0)) {
|
|
|
|
/* Ick, but I don't want it to abort this */
|
|
|
|
xs->retries++;
|
|
|
|
xs->error = XS_BUSY;
|
|
|
|
return(COMPLETE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-06-23 20:02:37 +00:00
|
|
|
/*
|
|
|
|
* get an scb to use. If the transfer
|
|
|
|
* is from a buf (possibly from interrupt time)
|
|
|
|
* then we can't allow it to sleep
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
if ((scb = ahc_get_scb(ahc, flags)) == NULL) {
|
1996-06-23 20:02:37 +00:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
return (TRY_AGAIN_LATER);
|
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb = scb->hscb;
|
1996-06-23 20:02:37 +00:00
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("start scb(%p)\n", scb));
|
|
|
|
scb->xs = xs;
|
1996-10-25 06:42:53 +00:00
|
|
|
|
1996-06-23 20:02:37 +00:00
|
|
|
/*
|
|
|
|
* Put all the arguments for the xfer in the scb
|
|
|
|
*/
|
1997-02-03 02:16:16 +00:00
|
|
|
if (ahc->discenable & mask) {
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control |= DISCENB;
|
1997-02-03 02:16:16 +00:00
|
|
|
if (ahc->tagenable & mask)
|
1997-02-18 04:25:31 +00:00
|
|
|
hscb->control |= MSG_SIMPLE_Q_TAG;
|
1997-02-09 03:26:56 +00:00
|
|
|
if (ahc->orderedtag & mask) {
|
|
|
|
/* XXX this should be handled by the upper SCSI layer */
|
|
|
|
printf("Ordered Tag sent\n");
|
|
|
|
hscb->control |= MSG_ORDERED_Q_TAG;
|
|
|
|
ahc->orderedtag &= ~mask;
|
|
|
|
}
|
1997-02-03 02:16:16 +00:00
|
|
|
}
|
1997-02-09 03:26:56 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
if (flags & SCSI_RESET) {
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags |= SCB_DEVICE_RESET;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control |= MK_MESSAGE;
|
|
|
|
} else if ((ahc->needwdtr & mask) && !(ahc->wdtrpending & mask)) {
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->wdtrpending |= mask;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control |= MK_MESSAGE;
|
|
|
|
scb->flags |= SCB_MSGOUT_WDTR;
|
|
|
|
} else if((ahc->needsdtr & mask) && !(ahc->sdtrpending & mask)) {
|
1995-02-22 01:43:25 +00:00
|
|
|
ahc->sdtrpending |= mask;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control |= MK_MESSAGE;
|
|
|
|
scb->flags |= SCB_MSGOUT_SDTR;
|
|
|
|
}
|
1996-11-16 01:19:14 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Set the trace flag if this is the target we want to trace */
|
|
|
|
if (ahc->unit == 2 && xs->sc_link->target == 3)
|
|
|
|
hscb->control |= TRACE_SCB;
|
|
|
|
#endif
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->tcl = ((xs->sc_link->target << 4) & 0xF0)
|
|
|
|
| (IS_SCSIBUS_B(ahc,xs->sc_link)? SELBUSB : 0)
|
|
|
|
| (xs->sc_link->lun & 0x07);
|
|
|
|
hscb->cmdlen = xs->cmdlen;
|
|
|
|
hscb->cmdpointer = vtophys(xs->cmd);
|
1995-03-31 13:54:41 +00:00
|
|
|
xs->resid = 0;
|
1995-06-11 19:33:05 +00:00
|
|
|
xs->status = 0;
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
/* Only use S/G if non-zero length */
|
|
|
|
if (xs->datalen) {
|
|
|
|
int seg;
|
|
|
|
u_int32_t datalen;
|
|
|
|
vm_offset_t vaddr;
|
|
|
|
u_int32_t paddr;
|
|
|
|
u_int32_t nextpaddr;
|
|
|
|
struct ahc_dma_seg *sg;
|
|
|
|
|
1996-04-20 21:29:27 +00:00
|
|
|
seg = 0;
|
|
|
|
datalen = xs->datalen;
|
1996-10-25 06:42:53 +00:00
|
|
|
vaddr = (vm_offset_t)xs->data;
|
|
|
|
paddr = vtophys(vaddr);
|
|
|
|
sg = scb->ahc_dma;
|
|
|
|
hscb->SG_list_pointer = vtophys(sg);
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
while ((datalen > 0) && (seg < AHC_NSEG)) {
|
|
|
|
/* put in the base address and length */
|
|
|
|
sg->addr = paddr;
|
|
|
|
sg->len = 0;
|
1996-04-20 21:29:27 +00:00
|
|
|
|
|
|
|
/* do it at least once */
|
1996-10-25 06:42:53 +00:00
|
|
|
nextpaddr = paddr;
|
|
|
|
|
|
|
|
while ((datalen > 0) && (paddr == nextpaddr)) {
|
|
|
|
u_int32_t size;
|
1996-04-20 21:29:27 +00:00
|
|
|
/*
|
|
|
|
* This page is contiguous (physically)
|
|
|
|
* with the the last, just extend the
|
|
|
|
* length
|
|
|
|
*/
|
|
|
|
/* how far to the end of the page */
|
1996-10-25 06:42:53 +00:00
|
|
|
nextpaddr = (paddr & (~PAGE_MASK)) + PAGE_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the maximum size
|
|
|
|
*/
|
|
|
|
size = nextpaddr - paddr;
|
|
|
|
if (size > datalen)
|
|
|
|
size = datalen;
|
|
|
|
|
|
|
|
sg->len += size;
|
|
|
|
vaddr += size;
|
|
|
|
datalen -= size;
|
|
|
|
if (datalen > 0)
|
|
|
|
paddr = vtophys(vaddr);
|
1996-04-20 21:29:27 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* next page isn't contiguous, finish the seg
|
|
|
|
*/
|
|
|
|
seg++;
|
1996-10-25 06:42:53 +00:00
|
|
|
sg++;
|
1996-04-20 21:29:27 +00:00
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->SG_segment_count = seg;
|
1997-02-11 17:10:37 +00:00
|
|
|
scb->sg_count = hscb->SG_segment_count;
|
1995-07-04 21:14:45 +00:00
|
|
|
|
|
|
|
/* Copy the first SG into the data pointer area */
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->data = scb->ahc_dma->addr;
|
|
|
|
hscb->datalen = scb->ahc_dma->len | (SCB_LIST_NULL << 24);
|
1996-04-20 21:29:27 +00:00
|
|
|
if (datalen) {
|
1995-07-04 21:14:45 +00:00
|
|
|
/* there's still data, must have run out of segs! */
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: ahc_scsi_cmd: more than %d DMA segs\n",
|
|
|
|
ahc_name(ahc), AHC_NSEG);
|
1996-04-20 21:29:27 +00:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc_free_scb(ahc, scb);
|
1996-04-20 21:29:27 +00:00
|
|
|
return (COMPLETE);
|
|
|
|
}
|
1996-05-30 07:19:59 +00:00
|
|
|
#ifdef AHC_BROKEN_CACHE
|
|
|
|
if (ahc_broken_cache)
|
|
|
|
INVALIDATE_CACHE();
|
|
|
|
#endif
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
Fixes to the aic7xxx sequencer code and device driver from Justin Gibbs:
1) If a target initiated a sync negotiation with us and happened to chose a
value above 15, the old code inadvertantly truncated it with an "& 0x0f".
If the periferal picked something really bad like 0x32, you'd end up with
an offset of 2 which would hang the drive since it didn't expect to ever
get something so low. We now do a MIN(maxoffset, given_offset).
2) In the case of Wide cards, we were turning on sync transfers after a
sucessfull wide negotiation. Now we leave the offset alone in the per
target scratch space (which implies asyncronous transfers since we initialize
it that way) until a syncronous negotation occurs.
3) We were advertizing a max offset of 15 instead of 8 for wide devices.
4) If the upper level SCSI code sent down a "SCSI_RESET", it would hang the
system because we would end up sending a null command to the sequencer. Now
we handle SCSI_RESET correctly by having the sequencer interrupt us when it
is about to fill the message buffer so that we can fill it in ourselves.
The sequencer will also "simulate" a command complete for these "message only"
SCBs so that the kernel driver can finish up properly. The cdplay utility
will send a "SCSI_REST" to the cdplayer if you use the reset command.
5) The code that handles SCSIINTs was broken in that if more than one type
of error was true at once, we'd do outbs without the card being paused.
The else clause after the busfree case was also an accident waiting to
happen. I've now turned this into an if, else if, else type of thing, since
in most cases when we handle one type of error, it should be okay to ignore
the rest (ie if we have a SELTO, who cares if there was a parity error on
the transaction?), but the section should really be rewritten after 2.0.5.
This fix was the least obtrusive way to patch the problem.
6) Only tag either SDTR or WDTR negotiation on an SCB. The real problem is
that I don't account for the case when an SCB that is tagged to do a particular
type of negotiation completes or SELTOs (selection timeout) without the
negotiation taking place, so the accounting of sdtrpending and wdtrpending
gets screwed up. In the wide case, if we tag it to do both wdtr and sdtr,
it only performs wdtr (since wdtr must occur first and we spread out the
negotiation over two commands) so we always have sdtrpending set for that
target and we never do a real SDTR. I fill properly fix the accounting
after 2.0.5 goes out the door, but this works (as confirmed by Dan) on
wide targets.
Other stuff that is also included:
1) Don't do a bzero when recycling SCBs. The only thing that must explicitly
be set to zero is the scb control byte which is done in ahc_get_scb. We also
need to set the SG_list_pointer and SG_list_count to 0 for commands that do
not transfer data.
2) Mask the interrupt type printout for the aic7870 case. The bit we were
using to determine interrupt type is only valid for the aic7770.
Submitted by: Justin Gibbs
1995-05-17 07:06:02 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* No data xfer, use non S/G values
|
Fixes to the aic7xxx sequencer code and device driver from Justin Gibbs:
1) If a target initiated a sync negotiation with us and happened to chose a
value above 15, the old code inadvertantly truncated it with an "& 0x0f".
If the periferal picked something really bad like 0x32, you'd end up with
an offset of 2 which would hang the drive since it didn't expect to ever
get something so low. We now do a MIN(maxoffset, given_offset).
2) In the case of Wide cards, we were turning on sync transfers after a
sucessfull wide negotiation. Now we leave the offset alone in the per
target scratch space (which implies asyncronous transfers since we initialize
it that way) until a syncronous negotation occurs.
3) We were advertizing a max offset of 15 instead of 8 for wide devices.
4) If the upper level SCSI code sent down a "SCSI_RESET", it would hang the
system because we would end up sending a null command to the sequencer. Now
we handle SCSI_RESET correctly by having the sequencer interrupt us when it
is about to fill the message buffer so that we can fill it in ourselves.
The sequencer will also "simulate" a command complete for these "message only"
SCBs so that the kernel driver can finish up properly. The cdplay utility
will send a "SCSI_REST" to the cdplayer if you use the reset command.
5) The code that handles SCSIINTs was broken in that if more than one type
of error was true at once, we'd do outbs without the card being paused.
The else clause after the busfree case was also an accident waiting to
happen. I've now turned this into an if, else if, else type of thing, since
in most cases when we handle one type of error, it should be okay to ignore
the rest (ie if we have a SELTO, who cares if there was a parity error on
the transaction?), but the section should really be rewritten after 2.0.5.
This fix was the least obtrusive way to patch the problem.
6) Only tag either SDTR or WDTR negotiation on an SCB. The real problem is
that I don't account for the case when an SCB that is tagged to do a particular
type of negotiation completes or SELTOs (selection timeout) without the
negotiation taking place, so the accounting of sdtrpending and wdtrpending
gets screwed up. In the wide case, if we tag it to do both wdtr and sdtr,
it only performs wdtr (since wdtr must occur first and we spread out the
negotiation over two commands) so we always have sdtrpending set for that
target and we never do a real SDTR. I fill properly fix the accounting
after 2.0.5 goes out the door, but this works (as confirmed by Dan) on
wide targets.
Other stuff that is also included:
1) Don't do a bzero when recycling SCBs. The only thing that must explicitly
be set to zero is the scb control byte which is done in ahc_get_scb. We also
need to set the SG_list_pointer and SG_list_count to 0 for commands that do
not transfer data.
2) Mask the interrupt type printout for the aic7870 case. The bit we were
using to determine interrupt type is only valid for the aic7770.
Submitted by: Justin Gibbs
1995-05-17 07:06:02 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->SG_segment_count = 0;
|
1997-02-11 17:10:37 +00:00
|
|
|
scb->sg_count = hscb->SG_segment_count;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->SG_list_pointer = 0;
|
|
|
|
hscb->data = 0;
|
|
|
|
hscb->datalen = (SCB_LIST_NULL << 24);
|
Fixes to the aic7xxx sequencer code and device driver from Justin Gibbs:
1) If a target initiated a sync negotiation with us and happened to chose a
value above 15, the old code inadvertantly truncated it with an "& 0x0f".
If the periferal picked something really bad like 0x32, you'd end up with
an offset of 2 which would hang the drive since it didn't expect to ever
get something so low. We now do a MIN(maxoffset, given_offset).
2) In the case of Wide cards, we were turning on sync transfers after a
sucessfull wide negotiation. Now we leave the offset alone in the per
target scratch space (which implies asyncronous transfers since we initialize
it that way) until a syncronous negotation occurs.
3) We were advertizing a max offset of 15 instead of 8 for wide devices.
4) If the upper level SCSI code sent down a "SCSI_RESET", it would hang the
system because we would end up sending a null command to the sequencer. Now
we handle SCSI_RESET correctly by having the sequencer interrupt us when it
is about to fill the message buffer so that we can fill it in ourselves.
The sequencer will also "simulate" a command complete for these "message only"
SCBs so that the kernel driver can finish up properly. The cdplay utility
will send a "SCSI_REST" to the cdplayer if you use the reset command.
5) The code that handles SCSIINTs was broken in that if more than one type
of error was true at once, we'd do outbs without the card being paused.
The else clause after the busfree case was also an accident waiting to
happen. I've now turned this into an if, else if, else type of thing, since
in most cases when we handle one type of error, it should be okay to ignore
the rest (ie if we have a SELTO, who cares if there was a parity error on
the transaction?), but the section should really be rewritten after 2.0.5.
This fix was the least obtrusive way to patch the problem.
6) Only tag either SDTR or WDTR negotiation on an SCB. The real problem is
that I don't account for the case when an SCB that is tagged to do a particular
type of negotiation completes or SELTOs (selection timeout) without the
negotiation taking place, so the accounting of sdtrpending and wdtrpending
gets screwed up. In the wide case, if we tag it to do both wdtr and sdtr,
it only performs wdtr (since wdtr must occur first and we spread out the
negotiation over two commands) so we always have sdtrpending set for that
target and we never do a real SDTR. I fill properly fix the accounting
after 2.0.5 goes out the door, but this works (as confirmed by Dan) on
wide targets.
Other stuff that is also included:
1) Don't do a bzero when recycling SCBs. The only thing that must explicitly
be set to zero is the scb control byte which is done in ahc_get_scb. We also
need to set the SG_list_pointer and SG_list_count to 0 for commands that do
not transfer data.
2) Mask the interrupt type printout for the aic7870 case. The bit we were
using to determine interrupt type is only valid for the aic7770.
Submitted by: Justin Gibbs
1995-05-17 07:06:02 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1995-02-22 01:43:25 +00:00
|
|
|
#ifdef AHC_DEBUG
|
1996-10-25 06:42:53 +00:00
|
|
|
if((ahc_debug & AHC_SHOWSCBS) && (xs->sc_link->target == DEBUGTARGET))
|
1994-11-17 20:22:31 +00:00
|
|
|
ahc_print_scb(scb);
|
|
|
|
#endif
|
1996-04-20 21:29:27 +00:00
|
|
|
s = splbio();
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
STAILQ_INSERT_TAIL(&ahc->waiting_scbs, scb, links);
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags |= SCB_ACTIVE|SCB_WAITINGQ;
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
ahc_run_waiting_queue(ahc);
|
|
|
|
|
|
|
|
if ((flags & SCSI_NOMASK) == 0) {
|
|
|
|
timeout(ahc_timeout, (caddr_t)scb, (xs->timeout * hz) / 1000);
|
1996-04-20 21:29:27 +00:00
|
|
|
splx(s);
|
1996-01-29 03:17:39 +00:00
|
|
|
return (SUCCESSFULLY_QUEUED);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we can't use interrupts, poll for completion
|
|
|
|
*/
|
1996-04-20 21:29:27 +00:00
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd_poll\n"));
|
1996-01-29 03:17:39 +00:00
|
|
|
do {
|
|
|
|
if (ahc_poll(ahc, xs->timeout)) {
|
|
|
|
if (!(xs->flags & SCSI_SILENT))
|
|
|
|
printf("cmd fail\n");
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
ahc_timeout(scb);
|
|
|
|
break;
|
1996-01-29 03:17:39 +00:00
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
} while ((xs->flags & ITSDONE) == 0); /* a non command complete intr */
|
1997-03-16 07:12:07 +00:00
|
|
|
scsi_done(xs);
|
1996-01-29 03:17:39 +00:00
|
|
|
splx(s);
|
|
|
|
return (COMPLETE);
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Look for space in the QINFIFO and queue as many SCBs in the waiting
|
|
|
|
* queue as possible. Assumes that it is called at splbio().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ahc_run_waiting_queue(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
{
|
|
|
|
struct scb *scb;
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
pause_sequencer(ahc);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
while ((scb = ahc->waiting_scbs.stqh_first) != NULL) {
|
|
|
|
|
|
|
|
if (ahc->curqincnt >= ahc->qfullcount) {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc->curqincnt = ahc_inb(ahc, QINCNT) & ahc->qcntmask;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (ahc->curqincnt >= ahc->qfullcount)
|
|
|
|
/* Still no space */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE_HEAD(&ahc->waiting_scbs, links);
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags &= ~SCB_WAITINGQ;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, QINFIFO, scb->hscb->tag);
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
if ((ahc->flags & AHC_PAGESCBS) != 0)
|
|
|
|
/*
|
|
|
|
* We only care about this statistic when paging
|
|
|
|
* since it is impossible to overflow the qinfifo
|
|
|
|
* in the non-paging case.
|
|
|
|
*/
|
|
|
|
ahc->curqincnt++;
|
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
unpause_sequencer(ahc, /*Unpause always*/FALSE);
|
1996-10-25 06:42:53 +00:00
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
|
|
|
/*
|
1997-03-16 07:12:07 +00:00
|
|
|
* An scb (and hence an scb entry on the board) is put onto the
|
1994-11-17 20:22:31 +00:00
|
|
|
* free list.
|
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1996-10-25 06:42:53 +00:00
|
|
|
ahc_free_scb(ahc, scb)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scb *scb;
|
|
|
|
{
|
|
|
|
struct hardware_scb *hscb;
|
|
|
|
int opri;
|
|
|
|
|
|
|
|
hscb = scb->hscb;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1995-04-23 22:04:58 +00:00
|
|
|
opri = splbio();
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-06-23 20:02:37 +00:00
|
|
|
/* Clean up for the next user */
|
1996-04-20 21:29:27 +00:00
|
|
|
scb->flags = SCB_FREE;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->control = 0;
|
|
|
|
hscb->status = 0;
|
1996-06-23 20:02:37 +00:00
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
STAILQ_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (scb->links.stqe_next == NULL) {
|
|
|
|
/*
|
1997-03-16 07:12:07 +00:00
|
|
|
* If there were no SCBs available, wake anybody waiting
|
1996-10-25 06:42:53 +00:00
|
|
|
* for one to come free.
|
1996-04-20 21:29:27 +00:00
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
wakeup((caddr_t)&ahc->scb_data->free_scbs);
|
1996-04-20 21:29:27 +00:00
|
|
|
}
|
1996-06-23 20:02:37 +00:00
|
|
|
#ifdef AHC_DEBUG
|
|
|
|
ahc->activescbs--;
|
|
|
|
#endif
|
1995-04-23 22:04:58 +00:00
|
|
|
splx(opri);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-11-17 20:22:31 +00:00
|
|
|
/*
|
1996-04-20 21:29:27 +00:00
|
|
|
* Get a free scb, either one already assigned to a hardware slot
|
|
|
|
* on the adapter or one that will require an SCB to be paged out before
|
|
|
|
* use. If there are none, see if we can allocate a new SCB. Otherwise
|
|
|
|
* either return an error or sleep.
|
1994-11-17 20:22:31 +00:00
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static struct scb *
|
1996-01-03 06:32:12 +00:00
|
|
|
ahc_get_scb(ahc, flags)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int32_t flags;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1996-04-20 21:29:27 +00:00
|
|
|
struct scb *scbp;
|
1996-10-25 06:42:53 +00:00
|
|
|
int opri;
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1995-04-23 22:04:58 +00:00
|
|
|
opri = splbio();
|
1996-04-20 21:29:27 +00:00
|
|
|
/*
|
|
|
|
* If we can and have to, sleep waiting for one to come free
|
|
|
|
* but only if we can't allocate a new one.
|
|
|
|
*/
|
|
|
|
while (1) {
|
1996-10-28 06:10:02 +00:00
|
|
|
if ((scbp = ahc->scb_data->free_scbs.stqh_first)) {
|
|
|
|
STAILQ_REMOVE_HEAD(&ahc->scb_data->free_scbs, links);
|
|
|
|
} else if(ahc->scb_data->numscbs < ahc->scb_data->maxscbs) {
|
1996-10-25 06:42:53 +00:00
|
|
|
scbp = ahc_alloc_scb(ahc);
|
|
|
|
if (scbp == NULL)
|
|
|
|
printf("%s: Can't malloc SCB\n", ahc_name(ahc));
|
1996-10-28 06:10:02 +00:00
|
|
|
} else if ((flags & SCSI_NOSLEEP) == 0) {
|
|
|
|
tsleep((caddr_t)&ahc->scb_data->free_scbs, PRIBIO,
|
1996-10-25 06:42:53 +00:00
|
|
|
"ahcscb", 0);
|
|
|
|
continue;
|
1996-03-31 03:15:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1995-04-23 22:04:58 +00:00
|
|
|
|
|
|
|
#ifdef AHC_DEBUG
|
1996-06-23 20:02:37 +00:00
|
|
|
if (scbp) {
|
1995-04-23 22:04:58 +00:00
|
|
|
ahc->activescbs++;
|
1996-01-03 06:32:12 +00:00
|
|
|
if((ahc_debug & AHC_SHOWSCBCNT)
|
1996-10-28 06:10:02 +00:00
|
|
|
&& (ahc->activescbs == ahc->scb_data->maxhscbs))
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: Max SCBs active\n", ahc_name(ahc));
|
1996-03-31 03:15:31 +00:00
|
|
|
}
|
1996-06-23 20:02:37 +00:00
|
|
|
#endif
|
1995-04-23 22:04:58 +00:00
|
|
|
|
|
|
|
splx(opri);
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1996-03-31 03:15:31 +00:00
|
|
|
return (scbp);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
static struct scb *
|
|
|
|
ahc_alloc_scb(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
{
|
|
|
|
static struct ahc_dma_seg *next_sg_array = NULL;
|
1996-10-28 06:10:02 +00:00
|
|
|
static int sg_arrays_free = 0;
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scb *newscb;
|
|
|
|
|
|
|
|
newscb = (struct scb *) malloc(sizeof(struct scb), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (newscb != NULL) {
|
|
|
|
bzero(newscb, sizeof(struct scb));
|
|
|
|
if (next_sg_array == NULL) {
|
|
|
|
size_t alloc_size = sizeof(struct ahc_dma_seg)
|
|
|
|
* AHC_NSEG;
|
|
|
|
sg_arrays_free = PAGE_SIZE / alloc_size;
|
|
|
|
alloc_size *= sg_arrays_free;
|
|
|
|
if (alloc_size == 0)
|
|
|
|
panic("%s: SG list doesn't fit in a page",
|
|
|
|
ahc_name(ahc));
|
|
|
|
next_sg_array = (struct ahc_dma_seg *)
|
|
|
|
malloc(alloc_size, M_DEVBUF, M_NOWAIT);
|
|
|
|
}
|
|
|
|
if (next_sg_array != NULL) {
|
|
|
|
struct hardware_scb *hscb;
|
|
|
|
|
|
|
|
newscb->ahc_dma = next_sg_array;
|
|
|
|
sg_arrays_free--;
|
|
|
|
if (sg_arrays_free == 0)
|
|
|
|
next_sg_array = NULL;
|
|
|
|
else
|
|
|
|
next_sg_array = &next_sg_array[AHC_NSEG];
|
1996-10-28 06:10:02 +00:00
|
|
|
hscb = &ahc->scb_data->hscbs[ahc->scb_data->numscbs];
|
1996-10-25 06:42:53 +00:00
|
|
|
newscb->hscb = hscb;
|
|
|
|
hscb->control = 0;
|
|
|
|
hscb->status = 0;
|
1996-10-28 06:10:02 +00:00
|
|
|
hscb->tag = ahc->scb_data->numscbs;
|
1996-10-25 06:42:53 +00:00
|
|
|
hscb->residual_data_count[2] = 0;
|
|
|
|
hscb->residual_data_count[1] = 0;
|
|
|
|
hscb->residual_data_count[0] = 0;
|
|
|
|
hscb->residual_SG_segment_count = 0;
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->numscbs++;
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Place in the scbarray
|
|
|
|
* Never is removed.
|
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
ahc->scb_data->scbarray[hscb->tag] = newscb;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
|
|
|
free(newscb, M_DEVBUF);
|
|
|
|
newscb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newscb;
|
|
|
|
}
|
|
|
|
|
1997-01-22 18:05:31 +00:00
|
|
|
static void
|
|
|
|
ahc_loadseq(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1994-11-17 20:22:31 +00:00
|
|
|
{
|
1997-03-16 07:12:07 +00:00
|
|
|
int options;
|
|
|
|
struct patch *cur_patch;
|
|
|
|
int i;
|
|
|
|
int downloaded;
|
|
|
|
|
|
|
|
options = 1; /* Code for all options */
|
|
|
|
downloaded = 0;
|
|
|
|
if ((ahc->type & AHC_ULTRA) != 0)
|
|
|
|
options |= ULTRA;
|
|
|
|
if ((ahc->type & AHC_TWIN) != 0)
|
|
|
|
options |= TWIN_CHANNEL;
|
|
|
|
if (ahc->scb_data->maxscbs > ahc->scb_data->maxhscbs)
|
|
|
|
options |= SCB_PAGING;
|
|
|
|
|
|
|
|
cur_patch = patches;
|
1997-01-22 18:05:31 +00:00
|
|
|
ahc_outb(ahc, SEQCTL, PERRORDIS|LOADRAM);
|
|
|
|
ahc_outb(ahc, SEQADDR0, 0);
|
|
|
|
ahc_outb(ahc, SEQADDR1, 0);
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1997-03-16 07:12:07 +00:00
|
|
|
for(i = 0; i < sizeof(seqprog)/4; i++) {
|
|
|
|
cur_patch = ahc_next_patch(cur_patch, options, i);
|
|
|
|
|
|
|
|
if (cur_patch && cur_patch->begin <= i && cur_patch->end > i)
|
|
|
|
/* Skip this instruction for this configuration */
|
|
|
|
continue;
|
|
|
|
ahc_download_instr(ahc, options, i);
|
|
|
|
downloaded++;
|
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
|
1997-01-22 18:05:31 +00:00
|
|
|
ahc_outb(ahc, SEQCTL, FASTMODE);
|
|
|
|
ahc_outb(ahc, SEQADDR0, 0);
|
|
|
|
ahc_outb(ahc, SEQADDR1, 0);
|
1997-03-16 07:12:07 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("%s: %d instructions downloaded\n", ahc_name(ahc),
|
|
|
|
downloaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct patch *
|
|
|
|
ahc_next_patch(cur_patch, options, instrptr)
|
|
|
|
struct patch *cur_patch;
|
|
|
|
int options;
|
|
|
|
int instrptr;
|
|
|
|
{
|
|
|
|
while(cur_patch != NULL) {
|
|
|
|
if (((cur_patch->options & options) != 0
|
|
|
|
&& cur_patch->negative == FALSE)
|
|
|
|
|| ((cur_patch->options & options) == 0
|
|
|
|
&& cur_patch->negative == TRUE)
|
|
|
|
|| (instrptr >= cur_patch->end)) {
|
|
|
|
/*
|
|
|
|
* Either we want to keep this section of code,
|
|
|
|
* or we have consumed this patch. Skip to the
|
|
|
|
* next patch.
|
|
|
|
*/
|
|
|
|
cur_patch++;
|
|
|
|
if (cur_patch->options == 0)
|
|
|
|
/* Out of patches */
|
|
|
|
cur_patch = NULL;
|
|
|
|
} else
|
|
|
|
/* Found an okay patch */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (cur_patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_download_instr(ahc, options, instrptr)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int options;
|
|
|
|
int instrptr;
|
|
|
|
{
|
|
|
|
u_int8_t opcode;
|
|
|
|
struct ins_format3 *instr;
|
|
|
|
|
|
|
|
instr = (struct ins_format3 *)&seqprog[instrptr * 4];
|
|
|
|
/* Pull the opcode */
|
|
|
|
opcode = instr->opcode_addr >> 1;
|
|
|
|
switch (opcode) {
|
|
|
|
case AIC_OP_JMP:
|
|
|
|
case AIC_OP_JC:
|
|
|
|
case AIC_OP_JNC:
|
|
|
|
case AIC_OP_CALL:
|
|
|
|
case AIC_OP_JNE:
|
|
|
|
case AIC_OP_JNZ:
|
|
|
|
case AIC_OP_JE:
|
|
|
|
case AIC_OP_JZ:
|
|
|
|
{
|
|
|
|
int address_offset;
|
|
|
|
struct ins_format3 new_instr;
|
|
|
|
u_int address;
|
|
|
|
struct patch *patch;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
address_offset = 0;
|
|
|
|
new_instr = *instr; /* structure copy */
|
|
|
|
address = new_instr.address;
|
|
|
|
address |= (new_instr.opcode_addr & ADDR_HIGH_BIT) << 8;
|
|
|
|
for (i = 0; i < sizeof(patches)/sizeof(patches[0]); i++) {
|
|
|
|
patch = &patches[i];
|
|
|
|
if (((patch->options & options) == 0
|
|
|
|
&& patch->negative == FALSE)
|
|
|
|
|| ((patch->options & options) != 0
|
|
|
|
&& patch->negative == TRUE)) {
|
|
|
|
if (address >= patch->end)
|
|
|
|
address_offset +=
|
|
|
|
patch->end - patch->begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
address -= address_offset;
|
|
|
|
new_instr.address = address & 0xFF;
|
|
|
|
new_instr.opcode_addr &= ~ADDR_HIGH_BIT;
|
|
|
|
new_instr.opcode_addr |= (address >> 8) & ADDR_HIGH_BIT;
|
|
|
|
ahc_outsb(ahc, SEQRAM, &new_instr.immediate, 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AIC_OP_OR:
|
|
|
|
case AIC_OP_AND:
|
|
|
|
case AIC_OP_XOR:
|
|
|
|
case AIC_OP_ADD:
|
|
|
|
case AIC_OP_ADC:
|
|
|
|
case AIC_OP_ROL:
|
|
|
|
ahc_outsb(ahc, SEQRAM, &instr->immediate, 4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Unknown opcode encountered in seq program");
|
|
|
|
break;
|
|
|
|
}
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1996-01-29 03:17:39 +00:00
|
|
|
/*
|
|
|
|
* Function to poll for command completion when
|
|
|
|
* interrupts are disabled (crash dumps)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ahc_poll(ahc, wait)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-01-29 03:17:39 +00:00
|
|
|
int wait; /* in msec */
|
|
|
|
{
|
|
|
|
while (--wait) {
|
|
|
|
DELAY(1000);
|
1996-11-11 05:24:46 +00:00
|
|
|
if (ahc_inb(ahc, INTSTAT) & INT_PEND)
|
1996-01-29 03:17:39 +00:00
|
|
|
break;
|
|
|
|
} if (wait == 0) {
|
1996-05-30 07:19:59 +00:00
|
|
|
printf("%s: board is not responding\n", ahc_name(ahc));
|
1996-01-29 03:17:39 +00:00
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
ahc_intr((void *)ahc);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
/*
|
|
|
|
* Handler to register that the system is capable of
|
|
|
|
* delivering timeouts. We register this timeout in
|
|
|
|
* ahc_init and it should go off as soon as we're through
|
|
|
|
* the boot process.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ahc_first_timeout(arg)
|
1997-02-03 02:16:16 +00:00
|
|
|
void *arg;
|
1997-01-29 05:27:03 +00:00
|
|
|
{
|
|
|
|
timeouts_work = 1;
|
|
|
|
}
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
ahc_timeout(arg)
|
|
|
|
void *arg;
|
1994-12-31 19:31:56 +00:00
|
|
|
{
|
1997-01-29 05:27:03 +00:00
|
|
|
struct scb *scb = (struct scb *)arg;
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int s, found;
|
|
|
|
u_int8_t bus_state;
|
1997-02-03 02:16:16 +00:00
|
|
|
char channel;
|
1994-12-31 19:31:56 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc = (struct ahc_softc *)scb->xs->sc_link->adapter_softc;
|
|
|
|
|
1997-02-03 02:16:16 +00:00
|
|
|
s = splbio();
|
1997-01-29 05:27:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that the card doesn't do anything
|
|
|
|
* behind our back. Also make sure that we
|
|
|
|
* didn't "just" miss an interrupt that would
|
|
|
|
* affect this timeout.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
ahc_intr(ahc);
|
|
|
|
pause_sequencer(ahc);
|
|
|
|
} while (ahc_inb(ahc, INTSTAT) & INT_PEND);
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
|
|
|
|
if (!(scb->flags & SCB_ACTIVE)) {
|
|
|
|
/* Previous timeout took care of me already */
|
1997-02-25 03:05:35 +00:00
|
|
|
printf("Timedout SCB handled by another timeout\n");
|
1997-01-29 05:27:03 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ahc->in_timeout) {
|
|
|
|
/*
|
|
|
|
* Some other SCB has started a recovery operation
|
|
|
|
* and is still working on cleaning things up.
|
|
|
|
*/
|
|
|
|
if (scb->flags & SCB_TIMEDOUT) {
|
|
|
|
/*
|
|
|
|
* This SCB has been here before and is not the
|
|
|
|
* recovery SCB. Cut our losses and panic. Its
|
|
|
|
* better to do this than trash a filesystem.
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1996-05-30 07:19:59 +00:00
|
|
|
panic("%s: Timed-out command times out "
|
1997-02-25 03:05:35 +00:00
|
|
|
"again. SCB = 0x%x\n", ahc_name(ahc),
|
|
|
|
scb->hscb->tag);
|
1997-02-18 04:25:31 +00:00
|
|
|
} else if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
/*
|
|
|
|
* This is not the SCB that started this timeout
|
|
|
|
* processing. Give this scb another lifetime so
|
|
|
|
* that it can continue once we deal with the
|
|
|
|
* timeout.
|
|
|
|
*/
|
|
|
|
scb->flags |= SCB_TIMEDOUT;
|
1997-02-25 03:05:35 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("SCB 0x%x timedout while recovery in progress\n",
|
|
|
|
scb->hscb->tag);
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
timeout(ahc_timeout, (caddr_t)scb,
|
|
|
|
(scb->xs->timeout * hz) / 1000);
|
1997-01-29 05:27:03 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ahc->in_timeout = TRUE;
|
|
|
|
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
1997-02-25 03:05:35 +00:00
|
|
|
printf("SCB 0x%x - timed out ", scb->hscb->tag);
|
1994-12-31 19:31:56 +00:00
|
|
|
/*
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
* Take a snapshot of the bus state and print out
|
|
|
|
* some information so we can track down driver bugs.
|
1994-12-31 19:31:56 +00:00
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
bus_state = ahc_inb(ahc, LASTPHASE);
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
|
1996-11-16 01:19:14 +00:00
|
|
|
switch(bus_state)
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
case P_DATAOUT:
|
|
|
|
printf("in dataout phase");
|
|
|
|
break;
|
|
|
|
case P_DATAIN:
|
|
|
|
printf("in datain phase");
|
|
|
|
break;
|
|
|
|
case P_COMMAND:
|
|
|
|
printf("in command phase");
|
|
|
|
break;
|
|
|
|
case P_MESGOUT:
|
|
|
|
printf("in message out phase");
|
|
|
|
break;
|
|
|
|
case P_STATUS:
|
|
|
|
printf("in status phase");
|
|
|
|
break;
|
|
|
|
case P_MESGIN:
|
|
|
|
printf("in message in phase");
|
|
|
|
break;
|
1996-12-03 17:06:00 +00:00
|
|
|
case P_BUSFREE:
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("while idle, LASTPHASE == 0x%x",
|
|
|
|
bus_state);
|
1996-12-03 17:06:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* We aren't in a valid phase, so assume we're
|
|
|
|
* idle.
|
|
|
|
*/
|
1996-12-03 17:06:00 +00:00
|
|
|
printf("invalid phase, LASTPHASE == 0x%x",
|
|
|
|
bus_state);
|
1996-10-25 06:42:53 +00:00
|
|
|
break;
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
printf(", SCSISIGI == 0x%x\n", ahc_inb(ahc, SCSISIGI));
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
printf("SEQADDR == 0x%x\n", ahc_inb(ahc, SEQADDR0)
|
|
|
|
| (ahc_inb(ahc, SEQADDR1) << 8));
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
/* Decide our course of action */
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
channel = (scb->hscb->tcl & SELBUSB) ? 'B': 'A';
|
1997-02-19 01:00:51 +00:00
|
|
|
if (scb->flags & SCB_ABORT) {
|
1994-12-31 19:31:56 +00:00
|
|
|
/*
|
1995-07-31 08:25:36 +00:00
|
|
|
* Been down this road before.
|
|
|
|
* Do a full bus reset.
|
1994-12-31 19:31:56 +00:00
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
bus_reset:
|
|
|
|
scb->flags |= SCB_RECOVERY_SCB;
|
1997-01-29 05:27:03 +00:00
|
|
|
found = ahc_reset_channel(ahc, channel, XS_TIMEOUT,
|
|
|
|
/*Initiate Reset*/TRUE);
|
1996-10-25 06:42:53 +00:00
|
|
|
printf("%s: Issued Channel %c Bus Reset. "
|
1996-05-30 07:19:59 +00:00
|
|
|
"%d SCBs aborted\n", ahc_name(ahc), channel, found);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else if ((scb->hscb->control & TAG_ENB) != 0
|
|
|
|
&& (scb->flags & SCB_SENTORDEREDTAG) == 0) {
|
1996-04-28 19:21:20 +00:00
|
|
|
/*
|
|
|
|
* We could be starving this command
|
|
|
|
* try sending an ordered tag command
|
|
|
|
* to the target we come from.
|
|
|
|
*/
|
1997-02-09 03:26:56 +00:00
|
|
|
u_int16_t mask;
|
|
|
|
|
|
|
|
mask = (0x01 << (scb->xs->sc_link->target
|
|
|
|
| (IS_SCSIBUS_B(ahc, scb->xs->sc_link) ?
|
|
|
|
SELBUSB : 0)));
|
1997-02-18 04:25:31 +00:00
|
|
|
scb->flags |= SCB_SENTORDEREDTAG|SCB_RECOVERY_SCB;
|
1997-02-09 03:26:56 +00:00
|
|
|
ahc->orderedtag |= mask;
|
|
|
|
timeout(ahc_timeout, (caddr_t)scb, (1 * hz));
|
1997-01-29 05:27:03 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1996-04-28 19:21:20 +00:00
|
|
|
printf("Ordered Tag queued\n");
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1996-10-25 06:42:53 +00:00
|
|
|
* Send an Abort Message:
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
* The target that is holding up the bus may not
|
|
|
|
* be the same as the one that triggered this timeout
|
|
|
|
* (different commands have different timeout lengths).
|
1996-10-25 06:42:53 +00:00
|
|
|
* Our strategy here is to queue an abort message
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
* to the timed out target if it is disconnected.
|
|
|
|
* Otherwise, if we have an active target we stuff the
|
1996-10-25 06:42:53 +00:00
|
|
|
* message buffer with an abort message and assert ATN
|
|
|
|
* in the hopes that the target will let go of the bus
|
|
|
|
* and go to the mesgout phase. If this fails, we'll
|
|
|
|
* get another timeout 2 seconds later which will attempt
|
|
|
|
* a bus reset.
|
1994-12-31 19:31:56 +00:00
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t saved_scbptr;
|
|
|
|
u_int8_t active_scb_index;
|
|
|
|
struct scb *active_scb;
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
saved_scbptr = ahc_inb(ahc, SCBPTR);
|
|
|
|
active_scb_index = ahc_inb(ahc, SCB_TAG);
|
1996-10-28 06:10:02 +00:00
|
|
|
active_scb = ahc->scb_data->scbarray[active_scb_index];
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
if (bus_state != P_BUSFREE) {
|
1997-03-16 07:12:07 +00:00
|
|
|
if (active_scb_index >= ahc->scb_data->numscbs) {
|
|
|
|
/* Go "immediatly" to the bus reset */
|
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("SCB %d: Yucky Immediate reset. "
|
|
|
|
"Flags = 0x%x\n", scb->hscb->tag,
|
|
|
|
scb->flags);
|
|
|
|
goto bus_reset;
|
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Send the abort to the active SCB */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, 1);
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT,
|
1996-10-25 06:42:53 +00:00
|
|
|
(active_scb->hscb->control & TAG_ENB) == 0 ?
|
|
|
|
MSG_ABORT : MSG_ABORT_TAG);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCSISIGO, bus_state|ATNO);
|
1996-10-25 06:42:53 +00:00
|
|
|
sc_print_addr(active_scb->xs->sc_link);
|
|
|
|
printf("abort message in message buffer\n");
|
1997-02-18 04:25:31 +00:00
|
|
|
active_scb->flags |= SCB_ABORT|SCB_RECOVERY_SCB;
|
1996-10-25 06:42:53 +00:00
|
|
|
if (active_scb != scb) {
|
|
|
|
untimeout(ahc_timeout,
|
|
|
|
(caddr_t)active_scb);
|
|
|
|
/* Give scb a new lease on life */
|
|
|
|
timeout(ahc_timeout, (caddr_t)scb,
|
|
|
|
(scb->xs->timeout * hz) / 1000);
|
|
|
|
}
|
1997-01-29 05:27:03 +00:00
|
|
|
timeout(ahc_timeout, (caddr_t)active_scb,
|
1997-02-18 04:25:31 +00:00
|
|
|
(200 * hz) / 1000);
|
1997-01-29 05:27:03 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/TRUE);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
|
|
|
int disconnected;
|
1997-02-25 03:05:35 +00:00
|
|
|
u_int8_t hscb_index;
|
1996-04-20 21:29:27 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
disconnected = FALSE;
|
1997-02-25 03:05:35 +00:00
|
|
|
hscb_index = ahc_find_scb(ahc, scb);
|
1997-02-03 16:29:07 +00:00
|
|
|
if (hscb_index == SCB_LIST_NULL) {
|
1996-10-25 06:42:53 +00:00
|
|
|
disconnected = TRUE;
|
1997-02-03 16:29:07 +00:00
|
|
|
} else {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, hscb_index);
|
|
|
|
if (ahc_inb(ahc, SCB_CONTROL) & DISCONNECTED)
|
1996-10-25 06:42:53 +00:00
|
|
|
disconnected = TRUE;
|
1996-04-20 21:29:27 +00:00
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
if (disconnected) {
|
|
|
|
/* Simply set the ABORT_SCB control bit */
|
1997-01-29 05:27:03 +00:00
|
|
|
scb->hscb->control |= ABORT_SCB|MK_MESSAGE;
|
1997-03-16 07:12:07 +00:00
|
|
|
if ((ahc->flags & AHC_PAGESCBS) == 0)
|
|
|
|
scb->hscb->control &= ~DISCONNECTED;
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags |= SCB_QUEUED_ABORT
|
|
|
|
| SCB_ABORT|SCB_RECOVERY_SCB;
|
1997-01-29 05:27:03 +00:00
|
|
|
if (hscb_index != SCB_LIST_NULL) {
|
|
|
|
u_int8_t scb_control;
|
|
|
|
|
|
|
|
scb_control = ahc_inb(ahc, SCB_CONTROL);
|
|
|
|
ahc_outb(ahc, SCB_CONTROL,
|
1997-03-16 07:12:07 +00:00
|
|
|
scb_control | MK_MESSAGE
|
|
|
|
| ABORT_SCB);
|
1997-01-29 05:27:03 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Actually re-queue this SCB in case we can
|
1997-02-03 02:16:16 +00:00
|
|
|
* select the device before it reconnects. If
|
|
|
|
* the transaction we want to abort is not
|
|
|
|
* tagged, unbusy it first so that we don't
|
|
|
|
* get held back from sending the command.
|
1997-01-29 05:27:03 +00:00
|
|
|
*/
|
1997-02-03 16:29:07 +00:00
|
|
|
if ((scb->hscb->control & TAG_ENB) == 0) {
|
1997-02-25 03:05:35 +00:00
|
|
|
int target;
|
|
|
|
int lun;
|
1997-02-03 02:16:16 +00:00
|
|
|
|
|
|
|
target = scb->xs->sc_link->target;
|
1997-02-25 03:05:35 +00:00
|
|
|
lun = scb->xs->sc_link->lun;
|
1997-02-09 03:26:56 +00:00
|
|
|
ahc_search_qinfifo(ahc, target,
|
|
|
|
channel,
|
1997-02-25 03:05:35 +00:00
|
|
|
lun,
|
1997-02-09 03:26:56 +00:00
|
|
|
SCB_LIST_NULL,
|
|
|
|
0, 0,
|
|
|
|
/*requeue*/TRUE);
|
1997-02-03 02:16:16 +00:00
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("Queueing an Abort SCB\n");
|
1997-02-03 16:29:07 +00:00
|
|
|
STAILQ_INSERT_HEAD(&ahc->waiting_scbs, scb,
|
|
|
|
links);
|
1997-02-25 03:05:35 +00:00
|
|
|
scb->flags |= SCB_WAITINGQ;
|
1997-01-29 05:27:03 +00:00
|
|
|
timeout(ahc_timeout, (caddr_t)scb,
|
1997-02-19 01:00:51 +00:00
|
|
|
(200 * hz) / 1000);
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, saved_scbptr);
|
|
|
|
/* ahc_run_waiting_queue will unpause us */
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_run_waiting_queue(ahc);
|
1997-02-28 03:58:21 +00:00
|
|
|
} else {
|
1996-10-25 06:42:53 +00:00
|
|
|
/* Go "immediatly" to the bus reset */
|
1997-02-28 03:58:21 +00:00
|
|
|
sc_print_addr(scb->xs->sc_link);
|
|
|
|
printf("SCB %d: Immediate reset. "
|
|
|
|
"Flags = 0x%x\n", scb->hscb->tag,
|
|
|
|
scb->flags);
|
1997-02-25 03:05:35 +00:00
|
|
|
goto bus_reset;
|
1997-02-28 03:58:21 +00:00
|
|
|
}
|
1994-12-31 19:31:56 +00:00
|
|
|
}
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1995-10-26 23:57:18 +00:00
|
|
|
splx(s);
|
1994-11-17 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Look through the SCB array of the card and attempt to find the
|
|
|
|
* hardware SCB that corresponds to the passed in SCB. Return
|
|
|
|
* SCB_LIST_NULL if unsuccessful. This routine assumes that the
|
|
|
|
* card is already paused.
|
|
|
|
*/
|
|
|
|
static u_int8_t
|
1997-02-03 16:29:07 +00:00
|
|
|
ahc_find_scb(ahc, scb)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
struct scb *scb;
|
|
|
|
{
|
|
|
|
u_int8_t saved_scbptr;
|
|
|
|
u_int8_t curindex;
|
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
saved_scbptr = ahc_inb(ahc, SCBPTR);
|
1996-10-28 06:10:02 +00:00
|
|
|
for (curindex = 0; curindex < ahc->scb_data->maxhscbs; curindex++) {
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, curindex);
|
|
|
|
if (ahc_inb(ahc, SCB_TAG) == scb->hscb->tag)
|
1996-10-25 06:42:53 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, saved_scbptr);
|
1996-10-28 06:10:02 +00:00
|
|
|
if (curindex > ahc->scb_data->maxhscbs)
|
1996-10-25 06:42:53 +00:00
|
|
|
curindex = SCB_LIST_NULL;
|
|
|
|
|
|
|
|
return curindex;
|
|
|
|
}
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1997-02-03 16:29:07 +00:00
|
|
|
static int
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_search_qinfifo(ahc, target, channel, lun, tag, flags, xs_error, requeue)
|
1997-02-03 16:29:07 +00:00
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int target;
|
|
|
|
char channel;
|
1997-02-25 03:05:35 +00:00
|
|
|
int lun;
|
1997-02-03 16:29:07 +00:00
|
|
|
u_int8_t tag;
|
|
|
|
u_int32_t flags;
|
|
|
|
u_int32_t xs_error;
|
|
|
|
int requeue;
|
|
|
|
{
|
|
|
|
u_int8_t saved_queue[AHC_SCB_MAX];
|
1997-02-09 03:26:56 +00:00
|
|
|
int queued = ahc_inb(ahc, QINCNT) & ahc->qcntmask;
|
1997-02-03 16:29:07 +00:00
|
|
|
int i;
|
|
|
|
int found;
|
|
|
|
struct scb *scbp;
|
|
|
|
STAILQ_HEAD(, scb) removed_scbs;
|
|
|
|
|
1997-02-03 17:24:25 +00:00
|
|
|
found = 0;
|
1997-02-09 03:26:56 +00:00
|
|
|
STAILQ_INIT(&removed_scbs);
|
1997-02-03 16:29:07 +00:00
|
|
|
for (i = 0; i < (queued - found); i++) {
|
|
|
|
saved_queue[i] = ahc_inb(ahc, QINFIFO);
|
|
|
|
scbp = ahc->scb_data->scbarray[saved_queue[i]];
|
1997-02-25 03:05:35 +00:00
|
|
|
if (ahc_match_scb(scbp, target, channel, lun, tag)) {
|
1997-02-03 16:29:07 +00:00
|
|
|
/*
|
|
|
|
* We found an scb that needs to be removed.
|
|
|
|
*/
|
|
|
|
if (requeue) {
|
1997-02-25 03:05:35 +00:00
|
|
|
STAILQ_INSERT_HEAD(&removed_scbs, scbp, links);
|
1997-02-03 16:29:07 +00:00
|
|
|
} else {
|
1997-02-19 01:00:51 +00:00
|
|
|
scbp->flags |= flags;
|
|
|
|
scbp->flags &= ~SCB_ACTIVE;
|
1997-02-03 16:29:07 +00:00
|
|
|
scbp->xs->error = xs_error;
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Now put the saved scbs back. */
|
|
|
|
for (queued = 0; queued < i; queued++)
|
|
|
|
ahc_outb(ahc, QINFIFO, saved_queue[queued]);
|
|
|
|
|
|
|
|
if (requeue) {
|
|
|
|
while ((scbp = removed_scbs.stqh_first) != NULL) {
|
|
|
|
STAILQ_REMOVE_HEAD(&removed_scbs, links);
|
|
|
|
STAILQ_INSERT_HEAD(&ahc->waiting_scbs, scbp, links);
|
1997-02-25 03:05:35 +00:00
|
|
|
scbp->flags |= SCB_WAITINGQ;
|
1997-02-03 16:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* The device at the given target/channel has been reset. Abort
|
|
|
|
* all active and queued scbs for that target/channel.
|
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static int
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_reset_device(ahc, target, channel, lun, tag, xs_error)
|
1997-01-29 05:27:03 +00:00
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int target;
|
|
|
|
char channel;
|
1997-02-25 03:05:35 +00:00
|
|
|
int lun;
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int8_t tag;
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
u_int32_t xs_error;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
|
|
|
struct scb *scbp;
|
|
|
|
u_char active_scb;
|
|
|
|
int i = 0;
|
1997-02-03 16:29:07 +00:00
|
|
|
int found;
|
1995-07-31 08:25:36 +00:00
|
|
|
|
|
|
|
/* restore this when we're done */
|
1996-11-11 05:24:46 +00:00
|
|
|
active_scb = ahc_inb(ahc, SCBPTR);
|
1995-07-31 08:25:36 +00:00
|
|
|
|
|
|
|
/*
|
1997-02-03 16:29:07 +00:00
|
|
|
* Remove any entries from the Queue-In FIFO.
|
1995-07-31 08:25:36 +00:00
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
found = ahc_search_qinfifo(ahc, target, channel, lun, tag,
|
1997-02-09 03:26:56 +00:00
|
|
|
SCB_ABORTED|SCB_QUEUED_FOR_DONE, xs_error,
|
|
|
|
/*requeue*/FALSE);
|
1995-07-31 08:25:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Search waiting for selection list.
|
|
|
|
*/
|
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t next, prev;
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
|
1995-07-31 08:25:36 +00:00
|
|
|
prev = SCB_LIST_NULL;
|
|
|
|
|
|
|
|
while (next != SCB_LIST_NULL) {
|
1997-02-19 01:00:51 +00:00
|
|
|
u_int8_t scb_index;
|
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, next);
|
1997-02-19 01:00:51 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
|
|
|
if (scb_index >= ahc->scb_data->numscbs) {
|
|
|
|
panic("Waiting List inconsistency. "
|
1997-02-25 03:05:35 +00:00
|
|
|
"SCB index == %d, yet numscbs == %d.",
|
1997-02-19 01:00:51 +00:00
|
|
|
scb_index, ahc->scb_data->numscbs);
|
|
|
|
}
|
|
|
|
scbp = ahc->scb_data->scbarray[scb_index];
|
1997-02-25 03:05:35 +00:00
|
|
|
if (ahc_match_scb(scbp, target, channel, lun, tag)) {
|
|
|
|
u_int8_t linked_next;
|
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
next = ahc_abort_wscb(ahc, scbp, next, prev,
|
1997-01-29 05:27:03 +00:00
|
|
|
xs_error);
|
1997-02-25 03:05:35 +00:00
|
|
|
linked_next = ahc_inb(ahc, SCB_LINKED_NEXT);
|
|
|
|
if (linked_next != SCB_LIST_NULL) {
|
|
|
|
struct scb *next_scb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-queue the waiting SCB via the
|
|
|
|
* waiting list.
|
|
|
|
*/
|
|
|
|
next_scb =
|
|
|
|
ahc->scb_data->scbarray[linked_next];
|
|
|
|
if (!ahc_match_scb(next_scb, target,
|
|
|
|
channel, lun, tag)) {
|
|
|
|
STAILQ_INSERT_HEAD(&ahc->waiting_scbs,
|
|
|
|
next_scb,
|
|
|
|
links);
|
|
|
|
next_scb->flags |= SCB_WAITINGQ;
|
|
|
|
}
|
|
|
|
}
|
1995-07-31 08:25:36 +00:00
|
|
|
found++;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1995-07-31 08:25:36 +00:00
|
|
|
prev = next;
|
1996-11-11 05:24:46 +00:00
|
|
|
next = ahc_inb(ahc, SCB_NEXT);
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Go through the entire SCB array now and look for
|
|
|
|
* commands for this target that are active. These
|
|
|
|
* are other (most likely tagged) commands that
|
|
|
|
* were disconnected when the reset occured.
|
|
|
|
*/
|
1996-10-28 06:10:02 +00:00
|
|
|
for (i = 0; i < ahc->scb_data->numscbs; i++) {
|
|
|
|
scbp = ahc->scb_data->scbarray[i];
|
1996-10-25 06:42:53 +00:00
|
|
|
if ((scbp->flags & SCB_ACTIVE)
|
1997-02-25 03:05:35 +00:00
|
|
|
&& ahc_match_scb(scbp, target, channel, lun, tag)) {
|
|
|
|
u_int8_t busy_scbid;
|
|
|
|
|
1997-02-19 01:00:51 +00:00
|
|
|
scbp->flags |= SCB_ABORTED|SCB_QUEUED_FOR_DONE;
|
|
|
|
scbp->flags &= ~SCB_ACTIVE;
|
1997-02-03 02:16:16 +00:00
|
|
|
scbp->xs->error = xs_error;
|
1995-07-31 08:25:36 +00:00
|
|
|
found++;
|
1997-02-25 03:05:35 +00:00
|
|
|
|
|
|
|
if ((scbp->flags & SCB_WAITINGQ) != 0) {
|
|
|
|
STAILQ_REMOVE(&ahc->waiting_scbs, scbp, scb,
|
|
|
|
links);
|
|
|
|
scbp->flags &= ~SCB_WAITINGQ;
|
|
|
|
}
|
|
|
|
/* Ensure the target is "free" */
|
|
|
|
busy_scbid = ahc_index_busy_target(ahc, target,
|
|
|
|
(scbp->hscb->tcl & SELBUSB) ?
|
|
|
|
'B' : 'A', /*unbusy*/FALSE);
|
|
|
|
if (busy_scbid != SCB_LIST_NULL) {
|
|
|
|
struct scb *busy_scb;
|
|
|
|
struct scb *next_scb;
|
|
|
|
u_int8_t next_scbid;
|
|
|
|
|
|
|
|
busy_scb = ahc->scb_data->scbarray[busy_scbid];
|
|
|
|
|
|
|
|
if (!ahc_match_scb(busy_scb, target,
|
|
|
|
channel, lun, tag))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ahc_index_busy_target(ahc, target,
|
|
|
|
(scbp->hscb->tcl & SELBUSB) ?
|
|
|
|
'B' : 'A', /*unbusy*/TRUE);
|
|
|
|
|
|
|
|
next_scbid = busy_scb->hscb->datalen >> 24;
|
|
|
|
|
|
|
|
if (next_scbid == SCB_LIST_NULL) {
|
|
|
|
busy_scbid = ahc_find_scb(ahc, busy_scb);
|
|
|
|
|
|
|
|
if (busy_scbid == SCB_LIST_NULL)
|
|
|
|
panic("Couldn't find busy SCB");
|
|
|
|
|
|
|
|
ahc_outb(ahc, SCBPTR, busy_scbid);
|
|
|
|
next_scbid = ahc_inb(ahc,
|
|
|
|
SCB_LINKED_NEXT);
|
|
|
|
|
|
|
|
if (next_scbid == SCB_LIST_NULL)
|
|
|
|
panic("Couldn't find next SCB");
|
|
|
|
}
|
|
|
|
|
|
|
|
next_scb = ahc->scb_data->scbarray[next_scbid];
|
|
|
|
if (!ahc_match_scb(next_scb, target,
|
|
|
|
channel, lun, tag)) {
|
|
|
|
STAILQ_INSERT_HEAD(&ahc->waiting_scbs,
|
|
|
|
next_scb, links);
|
|
|
|
next_scb->flags |= SCB_WAITINGQ;
|
|
|
|
}
|
|
|
|
}
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1997-01-29 05:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through the disconnected list and remove any entries we
|
|
|
|
* have queued for completion, 0'ing their control byte too.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
u_int8_t next, prev;
|
|
|
|
|
|
|
|
next = ahc_inb(ahc, DISCONNECTED_SCBH);
|
|
|
|
prev = SCB_LIST_NULL;
|
|
|
|
|
|
|
|
while (next != SCB_LIST_NULL) {
|
1997-02-19 01:00:51 +00:00
|
|
|
u_int8_t scb_index;
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, next);
|
1997-02-19 01:00:51 +00:00
|
|
|
scb_index = ahc_inb(ahc, SCB_TAG);
|
|
|
|
if (scb_index >= ahc->scb_data->numscbs) {
|
|
|
|
panic("Disconnected List inconsistency. "
|
1997-02-25 03:05:35 +00:00
|
|
|
"SCB index == %d, yet numscbs == %d.",
|
1997-02-19 01:00:51 +00:00
|
|
|
scb_index, ahc->scb_data->numscbs);
|
|
|
|
}
|
1997-02-25 03:05:35 +00:00
|
|
|
scbp = ahc->scb_data->scbarray[scb_index];
|
|
|
|
if (ahc_match_scb(scbp, target, channel, lun, tag)) {
|
|
|
|
next = ahc_rem_scb_from_disc_list(ahc, next);
|
1997-01-29 05:27:03 +00:00
|
|
|
} else {
|
|
|
|
prev = next;
|
|
|
|
next = ahc_inb(ahc, SCB_NEXT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, active_scb);
|
1995-07-31 08:25:36 +00:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
static u_int8_t
|
|
|
|
ahc_rem_scb_from_disc_list(ahc, scbptr)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
u_int8_t scbptr;
|
|
|
|
{
|
|
|
|
u_int8_t next;
|
|
|
|
u_int8_t prev;
|
|
|
|
|
|
|
|
ahc_outb(ahc, SCBPTR, scbptr);
|
|
|
|
next = ahc_inb(ahc, SCB_NEXT);
|
|
|
|
prev = ahc_inb(ahc, SCB_PREV);
|
|
|
|
|
|
|
|
ahc_outb(ahc, SCB_CONTROL, 0);
|
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_add_curscb_to_free_list(ahc);
|
1997-02-25 03:05:35 +00:00
|
|
|
|
|
|
|
if (prev != SCB_LIST_NULL) {
|
|
|
|
ahc_outb(ahc, SCBPTR, prev);
|
|
|
|
ahc_outb(ahc, SCB_NEXT, next);
|
|
|
|
} else
|
|
|
|
ahc_outb(ahc, DISCONNECTED_SCBH, next);
|
|
|
|
|
|
|
|
if (next != SCB_LIST_NULL) {
|
|
|
|
ahc_outb(ahc, SCBPTR, next);
|
|
|
|
ahc_outb(ahc, SCB_PREV, prev);
|
|
|
|
}
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
static void
|
|
|
|
ahc_add_curscb_to_free_list(ahc)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
{
|
|
|
|
/* Invalidate the tag so that ahc_find_scb doesn't think it's active */
|
|
|
|
ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
|
|
|
|
|
|
|
|
ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
|
|
|
|
ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
|
|
|
|
}
|
|
|
|
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* Manipulate the waiting for selection list and return the
|
|
|
|
* scb that follows the one that we remove.
|
|
|
|
*/
|
1995-10-31 18:41:49 +00:00
|
|
|
static u_char
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_abort_wscb (ahc, scbp, scbpos, prev, xs_error)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
|
|
|
struct scb *scbp;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t scbpos;
|
|
|
|
u_int8_t prev;
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
u_int32_t xs_error;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t curscb, next;
|
|
|
|
int target = ((scbp->hscb->tcl >> 4) & 0x0f);
|
|
|
|
char channel = (scbp->hscb->tcl & SELBUSB) ? 'B' : 'A';
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* Select the SCB we want to abort and
|
|
|
|
* pull the next pointer out of it.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
curscb = ahc_inb(ahc, SCBPTR);
|
|
|
|
ahc_outb(ahc, SCBPTR, scbpos);
|
|
|
|
next = ahc_inb(ahc, SCB_NEXT);
|
1995-07-31 08:25:36 +00:00
|
|
|
|
|
|
|
/* Clear the necessary fields */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCB_CONTROL, 0);
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_index_busy_target(ahc, target, channel, /*unbusy*/TRUE);
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_add_curscb_to_free_list(ahc);
|
1997-01-29 05:27:03 +00:00
|
|
|
|
1995-07-31 08:25:36 +00:00
|
|
|
/* update the waiting list */
|
1996-10-25 06:42:53 +00:00
|
|
|
if (prev == SCB_LIST_NULL)
|
1995-07-31 08:25:36 +00:00
|
|
|
/* First in the list */
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, WAITING_SCBH, next);
|
1995-07-31 08:25:36 +00:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Select the scb that pointed to us
|
|
|
|
* and update its next pointer.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, prev);
|
|
|
|
ahc_outb(ahc, SCB_NEXT, next);
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1997-01-29 05:27:03 +00:00
|
|
|
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* Point us back at the original scb position
|
|
|
|
* and inform the SCSI system that the command
|
|
|
|
* has been aborted.
|
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, curscb);
|
1997-02-19 01:00:51 +00:00
|
|
|
scbp->flags |= SCB_ABORTED|SCB_QUEUED_FOR_DONE;
|
|
|
|
scbp->flags &= ~SCB_ACTIVE;
|
1997-02-18 04:25:31 +00:00
|
|
|
scbp->xs->error = xs_error;
|
1995-07-31 08:25:36 +00:00
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
static u_int8_t
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_index_busy_target(ahc, target, channel, unbusy)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
int target;
|
|
|
|
char channel;
|
1997-02-25 03:05:35 +00:00
|
|
|
int unbusy;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t active_scb;
|
|
|
|
u_int8_t info_scb;
|
1996-10-28 06:10:02 +00:00
|
|
|
u_int8_t busy_scbid;
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int32_t scb_offset;
|
1996-05-30 07:19:59 +00:00
|
|
|
|
1996-10-25 06:42:53 +00:00
|
|
|
info_scb = target / 4;
|
|
|
|
if (channel == 'B')
|
|
|
|
info_scb += 2;
|
1996-11-11 05:24:46 +00:00
|
|
|
active_scb = ahc_inb(ahc, SCBPTR);
|
|
|
|
ahc_outb(ahc, SCBPTR, info_scb);
|
1997-03-16 07:12:07 +00:00
|
|
|
scb_offset = SCB_BUSYTARGETS + (target & 0x03);
|
1996-11-11 05:24:46 +00:00
|
|
|
busy_scbid = ahc_inb(ahc, scb_offset);
|
1997-02-25 03:05:35 +00:00
|
|
|
if (unbusy)
|
|
|
|
ahc_outb(ahc, scb_offset, SCB_LIST_NULL);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SCBPTR, active_scb);
|
1996-10-28 06:10:02 +00:00
|
|
|
return busy_scbid;
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
1997-03-01 06:50:41 +00:00
|
|
|
static void
|
|
|
|
ahc_busy_target(ahc, target, channel, scbid)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int target;
|
|
|
|
char channel;
|
|
|
|
u_int8_t scbid;
|
|
|
|
{
|
|
|
|
u_int8_t active_scb;
|
|
|
|
u_int8_t info_scb;
|
|
|
|
u_int8_t busy_scbid;
|
|
|
|
u_int32_t scb_offset;
|
|
|
|
|
|
|
|
info_scb = target / 4;
|
|
|
|
if (channel == 'B')
|
|
|
|
info_scb += 2;
|
|
|
|
active_scb = ahc_inb(ahc, SCBPTR);
|
|
|
|
ahc_outb(ahc, SCBPTR, info_scb);
|
1997-03-16 07:12:07 +00:00
|
|
|
scb_offset = SCB_BUSYTARGETS + (target & 0x03);
|
1997-03-01 06:50:41 +00:00
|
|
|
ahc_outb(ahc, scb_offset, scbid);
|
|
|
|
ahc_outb(ahc, SCBPTR, active_scb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
static void
|
|
|
|
ahc_clear_intstat(ahc)
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
{
|
|
|
|
/* Clear any interrupt conditions this may have caused */
|
|
|
|
ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
|
|
|
|
ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
|
|
|
|
|CLRBUSFREE|CLRSCSIPERR|CLRPHASECHG|
|
|
|
|
CLRREQINIT);
|
|
|
|
ahc_outb(ahc, CLRINT, CLRSCSIINT);
|
|
|
|
}
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static void
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_reset_current_bus(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int8_t scsiseq;
|
|
|
|
u_int8_t sblkctl;
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
|
1997-01-29 05:27:03 +00:00
|
|
|
scsiseq = ahc_inb(ahc, SCSISEQ);
|
|
|
|
ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
|
|
|
|
if (timeouts_work != 0) {
|
|
|
|
struct ahc_busreset_args *args;
|
|
|
|
|
|
|
|
sblkctl = ahc_inb(ahc, SBLKCTL);
|
|
|
|
args = (sblkctl & SELBUSB) ? &ahc->busreset_args_b
|
|
|
|
: &ahc->busreset_args;
|
|
|
|
ahc->in_reset |= (args->bus == 'A' ? CHANNEL_A_RESET
|
|
|
|
: CHANNEL_B_RESET);
|
|
|
|
timeout(ahc_busreset_complete, args,
|
|
|
|
MAX((AHC_BUSRESET_DELAY * hz) / 1000000, 1));
|
|
|
|
} else {
|
|
|
|
DELAY(AHC_BUSRESET_DELAY);
|
|
|
|
/* Turn off the bus reset */
|
|
|
|
ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
|
1997-02-25 03:05:35 +00:00
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_clear_intstat(ahc);
|
1997-02-25 03:05:35 +00:00
|
|
|
|
|
|
|
/* Re-enable reset interrupts */
|
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
/* Wait a minimal bus settle delay */
|
|
|
|
DELAY(AHC_BUSSETTLE_DELAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_busreset_complete(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ahc_busreset_args *args;
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int s;
|
|
|
|
u_int8_t scsiseq;
|
|
|
|
u_int8_t sblkctl;
|
|
|
|
|
|
|
|
args = (struct ahc_busreset_args *)arg;
|
|
|
|
ahc = (struct ahc_softc *)args->ahc;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
pause_sequencer(ahc);
|
|
|
|
|
|
|
|
/* Save the current block control state */
|
|
|
|
sblkctl = ahc_inb(ahc, SBLKCTL);
|
|
|
|
|
|
|
|
/* Switch to the right bus */
|
|
|
|
if (args->bus == 'A')
|
|
|
|
ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
|
|
|
|
else
|
|
|
|
ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
|
|
|
|
|
|
|
|
/* Turn off the bus reset */
|
|
|
|
printf("Clearing bus reset\n");
|
|
|
|
scsiseq = ahc_inb(ahc, SCSISEQ);
|
|
|
|
ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
|
|
|
|
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_clear_intstat(ahc);
|
1997-02-25 03:05:35 +00:00
|
|
|
|
|
|
|
/* Re-enable reset interrupts */
|
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
|
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
/*
|
|
|
|
* Set a 100ms timeout to clear our in_reset flag.
|
|
|
|
* It will be *at-least* that long before any targets
|
|
|
|
* respond to real commands on the bus.
|
|
|
|
*/
|
|
|
|
timeout(ahc_busreset_settle_complete, args,
|
|
|
|
(AHC_BUSSETTLE_DELAY * hz) / 1000000);
|
|
|
|
|
|
|
|
/* Restore the original channel */
|
|
|
|
ahc_outb(ahc, SBLKCTL, sblkctl);
|
|
|
|
unpause_sequencer(ahc, /*unpause_always*/FALSE);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_busreset_settle_complete(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ahc_busreset_args *args;
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
args = (struct ahc_busreset_args *)arg;
|
|
|
|
ahc = (struct ahc_softc *)args->ahc;
|
|
|
|
/* Clear the reset flag */
|
|
|
|
s = splbio();
|
|
|
|
printf("Clearing 'in-reset' flag\n");
|
|
|
|
ahc->in_reset &= (args->bus == 'A' ? ~CHANNEL_A_RESET
|
|
|
|
: ~CHANNEL_B_RESET);
|
|
|
|
splx(s);
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static int
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_reset_channel(ahc, channel, xs_error, initiate_reset)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-25 06:42:53 +00:00
|
|
|
char channel;
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
u_int32_t xs_error;
|
1996-10-25 06:42:53 +00:00
|
|
|
int initiate_reset;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int32_t offset, offset_max;
|
1997-01-29 05:27:03 +00:00
|
|
|
int found;
|
|
|
|
int target;
|
|
|
|
u_int8_t sblkctl;
|
|
|
|
char cur_channel;
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
pause_sequencer(ahc);
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* Clean up all the state information for the
|
|
|
|
* pending transactions on this bus.
|
|
|
|
*/
|
1997-02-25 03:05:35 +00:00
|
|
|
found = ahc_reset_device(ahc, ALL_TARGETS, channel, ALL_LUNS,
|
|
|
|
SCB_LIST_NULL, xs_error);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (channel == 'B') {
|
1995-07-31 08:25:36 +00:00
|
|
|
ahc->needsdtr |= (ahc->needsdtr_orig & 0xff00);
|
|
|
|
ahc->sdtrpending &= 0x00ff;
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc->orderedtag &= 0x00ff;
|
1996-05-30 07:19:59 +00:00
|
|
|
offset = TARG_SCRATCH + 8;
|
|
|
|
offset_max = TARG_SCRATCH + 16;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else if (ahc->type & AHC_WIDE){
|
1995-07-31 08:25:36 +00:00
|
|
|
ahc->needsdtr = ahc->needsdtr_orig;
|
|
|
|
ahc->needwdtr = ahc->needwdtr_orig;
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc->orderedtag = 0;
|
1995-07-31 08:25:36 +00:00
|
|
|
ahc->sdtrpending = 0;
|
|
|
|
ahc->wdtrpending = 0;
|
1996-05-30 07:19:59 +00:00
|
|
|
offset = TARG_SCRATCH;
|
|
|
|
offset_max = TARG_SCRATCH + 16;
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
1995-07-31 08:25:36 +00:00
|
|
|
ahc->needsdtr |= (ahc->needsdtr_orig & 0x00ff);
|
|
|
|
ahc->sdtrpending &= 0xff00;
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc->orderedtag &= 0xff00;
|
1996-05-30 07:19:59 +00:00
|
|
|
offset = TARG_SCRATCH;
|
|
|
|
offset_max = TARG_SCRATCH + 8;
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
for (; offset < offset_max; offset++) {
|
1995-07-31 08:25:36 +00:00
|
|
|
/*
|
|
|
|
* Revert to async/narrow transfers
|
|
|
|
* until we renegotiate.
|
|
|
|
*/
|
1996-10-25 06:42:53 +00:00
|
|
|
u_int8_t targ_scratch;
|
1996-05-30 07:19:59 +00:00
|
|
|
|
1996-11-11 05:24:46 +00:00
|
|
|
targ_scratch = ahc_inb(ahc, offset);
|
1995-07-31 08:25:36 +00:00
|
|
|
targ_scratch &= SXFR;
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, offset, targ_scratch);
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
* Reset the bus if we are initiating this reset and
|
|
|
|
* restart/unpause the sequencer
|
1995-07-31 08:25:36 +00:00
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
sblkctl = ahc_inb(ahc, SBLKCTL);
|
1995-07-31 08:25:36 +00:00
|
|
|
cur_channel = (sblkctl & SELBUSB) ? 'B' : 'A';
|
1996-10-25 06:42:53 +00:00
|
|
|
if (cur_channel != channel) {
|
|
|
|
/* Case 1: Command for another bus is active
|
|
|
|
* Stealthily reset the other bus without
|
|
|
|
* upsetting the current bus.
|
1995-07-31 08:25:36 +00:00
|
|
|
*/
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (initiate_reset)
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_reset_current_bus(ahc);
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SCSISEQ, 0);
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_clear_intstat(ahc);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, SBLKCTL, sblkctl);
|
1997-02-28 03:58:21 +00:00
|
|
|
unpause_sequencer(ahc, /*unpause_always*/FALSE);
|
1996-10-25 06:42:53 +00:00
|
|
|
} else {
|
|
|
|
/* Case 2: A command from this bus is active or we're idle */
|
1997-01-29 05:27:03 +00:00
|
|
|
ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
|
1996-10-25 06:42:53 +00:00
|
|
|
if (initiate_reset)
|
1996-05-30 07:19:59 +00:00
|
|
|
ahc_reset_current_bus(ahc);
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, SCSISEQ, 0);
|
1997-02-28 03:58:21 +00:00
|
|
|
ahc_clear_intstat(ahc);
|
1996-10-06 16:38:45 +00:00
|
|
|
restart_sequencer(ahc);
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
ahc_run_done_queue(ahc);
|
1995-07-31 08:25:36 +00:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
void
|
|
|
|
ahc_run_done_queue(ahc)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct scb *scbp;
|
|
|
|
|
1996-10-28 06:10:02 +00:00
|
|
|
for (i = 0; i < ahc->scb_data->numscbs; i++) {
|
|
|
|
scbp = ahc->scb_data->scbarray[i];
|
1996-10-25 06:42:53 +00:00
|
|
|
if (scbp->flags & SCB_QUEUED_FOR_DONE)
|
bt.c, aic7xxx.c:
Cleanse the SCSI subsystem of its internally defined types
u_int32, u_int16, u_int8, int32, int16, int8.
Use the system defined *_t types instead.
aic7xxx.c:
Fix the reset code.
Instead of queing up all of the SCBs that timeout during timeout
processing, we take the first and have it champion the effort.
Any other scbs that timeout during timeout handling are given
another lifetime to complete in the hopes that once timeout
handing is finished, they will complete normally. If one of
these SCBs times out a second time, we panic and Justin tries
again.
The other major change is to queue flag aborted SCBs during timeout
handling, and "ahc_done" them all at once as soon as we have the
controller back into a sane state. Calling ahc_done any earlier
will cause the SCSI subsystem to toss the command right back at
us and the attempt to queue the command will conflict with what
the timeout routine is trying to accomplish.
The aic7xxx driver will now respond to bus resets initiated by
other devices.
1996-03-10 07:11:45 +00:00
|
|
|
ahc_done(ahc, scbp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-31 18:41:49 +00:00
|
|
|
static int
|
1997-02-25 03:05:35 +00:00
|
|
|
ahc_match_scb (scb, target, channel, lun, tag)
|
1997-01-29 05:27:03 +00:00
|
|
|
struct scb *scb;
|
|
|
|
int target;
|
|
|
|
char channel;
|
1997-02-25 03:05:35 +00:00
|
|
|
int lun;
|
1997-01-29 05:27:03 +00:00
|
|
|
u_int8_t tag;
|
1995-07-31 08:25:36 +00:00
|
|
|
{
|
1997-02-03 02:16:16 +00:00
|
|
|
int targ = (scb->hscb->tcl >> 4) & 0x0f;
|
|
|
|
char chan = (scb->hscb->tcl & SELBUSB) ? 'B' : 'A';
|
1997-02-25 03:05:35 +00:00
|
|
|
int slun = scb->hscb->tcl & 0x07;
|
1997-01-29 05:27:03 +00:00
|
|
|
int match;
|
1995-07-31 08:25:36 +00:00
|
|
|
|
1997-01-29 05:27:03 +00:00
|
|
|
match = ((chan == channel) || (channel == ALL_CHANNELS));
|
|
|
|
if (match != 0)
|
|
|
|
match = ((targ == target) || (target == ALL_TARGETS));
|
1997-02-25 03:05:35 +00:00
|
|
|
if (match != 0)
|
|
|
|
match = ((lun == slun) || (lun == ALL_LUNS));
|
1997-01-29 05:27:03 +00:00
|
|
|
if (match != 0)
|
|
|
|
match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
|
|
|
|
|
|
|
|
return match;
|
1995-07-31 08:25:36 +00:00
|
|
|
}
|
1996-10-06 16:38:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_construct_sdtr(ahc, start_byte, period, offset)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
int start_byte;
|
|
|
|
u_int8_t period;
|
|
|
|
u_int8_t offset;
|
|
|
|
{
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT + start_byte, MSG_EXTENDED);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 1 + start_byte, MSG_EXT_SDTR_LEN);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 2 + start_byte, MSG_EXT_SDTR);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 3 + start_byte, period);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 4 + start_byte, offset);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, start_byte + 5);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_construct_wdtr(ahc, start_byte, bus_width)
|
1996-10-28 06:10:02 +00:00
|
|
|
struct ahc_softc *ahc;
|
1996-10-06 16:38:45 +00:00
|
|
|
int start_byte;
|
|
|
|
u_int8_t bus_width;
|
|
|
|
{
|
1997-03-16 07:12:07 +00:00
|
|
|
ahc_outb(ahc, MSG_OUT + start_byte, MSG_EXTENDED);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 1 + start_byte, MSG_EXT_WDTR_LEN);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 2 + start_byte, MSG_EXT_WDTR);
|
|
|
|
ahc_outb(ahc, MSG_OUT + 3 + start_byte, bus_width);
|
1996-11-11 05:24:46 +00:00
|
|
|
ahc_outb(ahc, MSG_LEN, start_byte + 4);
|
1996-10-06 16:38:45 +00:00
|
|
|
}
|
1996-10-25 06:42:53 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ahc_calc_residual(scb)
|
|
|
|
struct scb *scb;
|
|
|
|
{
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
struct hardware_scb *hscb;
|
|
|
|
int resid_sgs;
|
|
|
|
|
|
|
|
xs = scb->xs;
|
|
|
|
hscb = scb->hscb;
|
|
|
|
|
1997-02-25 03:05:35 +00:00
|
|
|
/*
|
|
|
|
* If the disconnected flag is still set, this is bogus
|
|
|
|
* residual information left over from a sequencer
|
|
|
|
* pagin/pageout, so ignore this case.
|
|
|
|
*/
|
|
|
|
if ((scb->hscb->control & DISCONNECTED) == 0
|
|
|
|
&& (scb->flags & SCB_SENSE) == 0) {
|
1996-10-25 06:42:53 +00:00
|
|
|
/*
|
|
|
|
* Remainder of the SG where the transfer
|
|
|
|
* stopped.
|
|
|
|
*/
|
|
|
|
xs->resid = (hscb->residual_data_count[2] <<16) |
|
|
|
|
(hscb->residual_data_count[1] <<8) |
|
|
|
|
(hscb->residual_data_count[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add up the contents of all residual
|
|
|
|
* SG segments that are after the SG where
|
|
|
|
* the transfer stopped.
|
|
|
|
*/
|
1997-02-11 17:10:37 +00:00
|
|
|
resid_sgs = scb->hscb->residual_SG_segment_count - 1;
|
1996-10-25 06:42:53 +00:00
|
|
|
while (resid_sgs > 0) {
|
|
|
|
int sg;
|
|
|
|
|
1997-02-11 17:10:37 +00:00
|
|
|
sg = scb->sg_count - resid_sgs;
|
1996-10-25 06:42:53 +00:00
|
|
|
xs->resid += scb->ahc_dma[sg].len;
|
|
|
|
resid_sgs--;
|
|
|
|
}
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
xs->flags |= SCSI_RESID_VALID;
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
/* XXX - Update to do this right */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-11-22 08:28:45 +00:00
|
|
|
* Clean out the residual information in this SCB for its
|
|
|
|
* next consumer.
|
1996-10-25 06:42:53 +00:00
|
|
|
*/
|
|
|
|
hscb->residual_data_count[2] = 0;
|
|
|
|
hscb->residual_data_count[1] = 0;
|
|
|
|
hscb->residual_data_count[0] = 0;
|
|
|
|
hscb->residual_SG_segment_count = 0;
|
|
|
|
|
|
|
|
#ifdef AHC_DEBUG
|
|
|
|
if (ahc_debug & AHC_SHOWMISC) {
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("Handled Residual of %ld bytes\n" ,xs->resid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|