Commit Graph

265 Commits

Author SHA1 Message Date
Justin T. Gibbs
957fea92f0 Set the ultra enable bits in the adaptor's scratch ram area only after
we finish modifying our in kernel version during seeprom configuration.
1999-02-11 07:12:16 +00:00
Justin T. Gibbs
03c4f58aa3 Ensure that the ACK from the last information transfer phase has been
de-asserted by the initiator before changing phase or releasing the bus.
Corrects a SCSI specification violation in target mode.
1999-02-11 07:10:20 +00:00
Justin T. Gibbs
922b8593e6 Correct a race condition where a target mode SCB dma could occur
before we finished setting the pending phase information.

Use the ALL_TARGETS_MASK #define instead of 0xffff for the default
ultraenb mask.
1999-02-11 07:07:27 +00:00
Peter Wemm
6b3daecd80 "fix" long standing aicasm build glitch. The problem was the
reorganization in rev 1.16 of i386/include/types.h which changed
stdlib.h's use of <machine/types.h>.  The problem was the -I. was causing
machine/types.h to come from the current kernel source, while stdlib.h was
coming from /usr/include.  /usr/include/stdlib.h is as old as the last
'make world', the machine/types.h was as new as the current source.
1999-01-17 19:56:02 +00:00
Justin T. Gibbs
2e03cdebd5 Add two missing break statements. 1999-01-15 23:24:23 +00:00
Justin T. Gibbs
863c602654 Add support for routing initiator transactions to disabled luns to the
black hole device.  The controller will now only accept selections if
the black hole device is present and some other target/lun is enabled
for target mode.

Handle the IGNORE WIDE RESIDUE message.  This support has not been tested.

Checkpoint work on handling ABORT, BUS DEVICE RESET, TERMINATE I/O PROCESS,
and CLEAR QUEUE messages as a target.

Fix a few problems with tagged command handling in target mode.

Wait until the sync offset counter falls to 0 before changing phase
after a data-in transfer completes as the DMA logic seems to indicate
transfer complete as soon as our last REQ is issued.

Simplify some of the target mode message handling code in the sequencer.
1999-01-14 06:14:15 +00:00
Justin T. Gibbs
0378c40c5c Fix a few problems with handling rejected transfer negotiation messages.
Use the host message loop for any unknown message types instead of performing
a reject message in the sequencer.  Pass reject messages to the host
message loop too which frees up a sequencer interrupt type slot.

Default to issuing a bus reset if initiator mode is enabled.  It seems
that the reset scsi bus bit is not defined in the same location for
all aic78xx BIOSes, so attempting to honor this setting will have to
wait until I get more information on how to detect it.

Nuke some unused variables.
1998-12-17 00:06:52 +00:00
Justin T. Gibbs
41faa7d374 Pull in new ccb_hdr list types. 1998-12-15 08:24:45 +00:00
Justin T. Gibbs
0ca48af774 Perform a save data pointers operation if a data transfer was performed
in target mode, but we are not completing the command.

Use a template of allowed bus arbitration phases to selectively and
dynamically enable/disable initiator or target (re)selection.

Properly handle timeouts for target role transactions - just go to the
bus free state and report the error to the peripheral driver.

Checkpoint support for the XPT_ABORT_CCB function code.  This currently
handles the accept tio and immediate notify ccb types, but does not
handle the continue target I/O or SCSI I/O ccb types.  This is enough
to handle dynamic target enable/disable events.

Clean up the SCSI reset code so that we perform at most 1 SCSI bus
reset at initialization, the reset requested by the XPT layer.
1998-12-15 08:22:42 +00:00
Matthew Dillon
35f069d08b pci_device pd_probe function changed from returning char * to returning
const char *.  Originally I was going to add casts from const char * to
    char * in some of the pci device drivers, but the reality is that the
    pci device probes return constant quoted strings.
1998-12-14 05:47:29 +00:00
Justin T. Gibbs
4dd5dcaecd Revamp the way that exceptional message handling is performed so that it
is more robust and common code can be used for both the target and iniator
roles.  The mechanism for tracking negotiation state has also been simplified.

Add support for sync/wide negotiation in target mode and fix many of
the target mode bugs running at higher speeds uncovered.  Make a first
stab at getting all of the bus skew delays correct.  Sync+Wide dataout
transfers still cause problems, but this may be an initiator problem.

Ensure that we exit BITBUCKET mode if the controller is restarted.

Add support for target mode only firmware downloads.  This has been
tested on the aic7880, but should mean that we can perform target mode
on any aic7xxx controller.  Mixed mode (initiator and target roles in
the same firmware load) is currently only supported on the aic7890, but
with optimization, may fit on chips with less instruction space.
1998-12-10 04:14:50 +00:00
Archie Cobbs
f1d19042b0 The "easy" fixes for compiling the kernel -Wunused: remove unreferenced static
and local variables, goto labels, and functions declared but not defined.
1998-12-07 21:58:50 +00:00
Archie Cobbs
2127f26023 Examine all occurrences of sprintf(), strcat(), and str[n]cpy()
for possible buffer overflow problems. Replaced most sprintf()'s
with snprintf(); for others cases, added terminating NUL bytes where
appropriate, replaced constants like "16" with sizeof(), etc.

These changes include several bug fixes, but most changes are for
maintainability's sake. Any instance where it wasn't "immediately
obvious" that a buffer overflow could not occur was made safer.

Reviewed by:	Bruce Evans <bde@zeta.org.au>
Reviewed by:	Matthew Dillon <dillon@apollo.backplane.com>
Reviewed by:	Mike Spengler <mks@networkcs.com>
1998-12-04 22:54:57 +00:00
Justin T. Gibbs
08c6fbfa40 Change the delivery mechanism for incoming target commands. We now
use a 256 entry ring buffer of descriptersfor this purpose.  This allows
the use of a simple 8bit counter in the sequencer code for tracking start
location.

Entries in the ring buffer now contain a "cmd_valid" byte at their tail.
As an entry is serviced, this byte is cleared by the kernel and set by
the sequencer during its dma of a new entry.  Since this byte is the last
portion of the command touched during a dma, the kernel can use this
byte to ensure the command it processes is completely valid.

The new command format requires a fixed sized DMA from the controller
to deliver which allowed for additional simplification of the sequencer
code.  The hack that required 1 SCB slot to be stolen for incoming
command delivery notification is also gone.
1998-11-23 01:33:47 +00:00
Justin T. Gibbs
1964f204c9 -Wunused cleanup.
Correct a problem where an external bus reset on the 'background' channel of
a Twin Channel EISA controller could put the driver into an infinite loop.

Noticed by: Twin Channel bug, Joerg Wunsch <joerg@FreeBSD.org>
Submitted by: -Wunused, Poul-Henning Kamp <phk@freebsd.org>
1998-10-15 23:49:27 +00:00
Justin T. Gibbs
bc1b1dad36 Bring back support for honoring the primary channel setting for twin channel
EISA adapters.  This could have caused the system to find the wrong root
disk.

Reviewed by:	 J Wunsch <j@ida.interface-business.de>
1998-10-15 18:21:50 +00:00
Justin T. Gibbs
e95de2a602 Pass termination information via softc flags to the core driver. The
EISA probe missed out on this change in attach->core API.
1998-10-09 17:42:28 +00:00
Justin T. Gibbs
4b3aa31c63 When 'using defaults' ensure that termination is enabled.
Removed some unused code.
1998-10-09 17:41:39 +00:00
Justin T. Gibbs
6405ed07d7 ahc_pci.c:
Disable DPARCKEN in the DSCOMMAND0 register on the aic7890/91/96/97.
	Parity checking is broken for some chip/MB combinations and this
	is the work around recommended by Adaptec.

dpt_pci.c:
	Remove a superflous '{' that prevented DPT_ALLOW_MEMIO from working.

pcireg.h:
	Add a definition for Parity Error Reponse bit in the PCI Space
	command register.
1998-10-07 03:40:51 +00:00
Justin T. Gibbs
13cfc225b9 Add a missing newline. 1998-10-07 03:34:13 +00:00
Justin T. Gibbs
0f39fbdeb5 Correct twin channel operation. 1998-09-21 16:46:13 +00:00
Justin T. Gibbs
bd6bae2166 Remove unused variables and functions.
In the rejected message handler, it was possible for us to confuse a
rejected SDTR or WDTR for a rejected tag.
1998-09-20 23:30:14 +00:00
Justin T. Gibbs
ebeec632cd Correct a bug in the timeout handler. When queuing a BDR response to
a timeout, we must remove the pending SCB from the disconnected list
or risk list corruption when our BDR request using the same SCB is placed
on the waiting list.

Eradicate some silly uses of u_int8_t that just serve to slow the code down.
1998-09-20 05:06:10 +00:00
Justin T. Gibbs
a90c881ed7 Don't interpret SCB index 254 as a target mode completion when not in
target mode.  This hack of using the normal command complete mechanism
for target cdb completion will go away soon.

Submitted by:	Tor.Egge@fast.no
1998-09-18 03:42:16 +00:00
Matt Jacob
cde5024e09 Fix compile warnings. 1998-09-16 03:26:10 +00:00
Justin T. Gibbs
4530878e33 Move to new name, convert to CAM, add support for new chips, and
correct lots of eeprom/auto-termination bugs.
1998-09-15 07:25:33 +00:00
Justin T. Gibbs
ccb21a77fb Move to new name and convert to CAM. 1998-09-15 07:24:58 +00:00
Justin T. Gibbs
3bafc9d432 Massive overhaul of the aic7xxx driver:
- Convert to CAM
 - Use a new DMA based queuing and paging scheme
 - Add preliminary target mode support
 - Add support for the aic789X chips
 - Take advantage of external SRAM on more controllers.
 - Numerous bug fixes and performance improvements.
1998-09-15 07:24:17 +00:00
Justin T. Gibbs
b66655cf37 Some revisions of the aic7880 have a problem where, if the
data fifo is full, but the PCI input latch is not empty,
HDMAEN cannot be cleared.  The fix used here is to attempt
to drain the data fifo until there is space for the input
latch to drain and HDMAEN de-asserts.

This is a 1 instruction fix, so it should have no performance
impact.
1998-06-28 02:58:57 +00:00
Justin T. Gibbs
37507c1bd2 Add support to aicasm for "downloaded constants". These are immediate
operands that are set during seqeuncer program download instead of at
assembly time.

Convert the sequencer code to use" downloaded constants" for four run time
constants that vary depending on the board type.  This frees up 4 bytes
of sequencer scratch ram space where these constants used to be stored and
also removes the additional instructions required to load their values
into the accumulator prior to using them.

Remove the REJBYTE sram variable.  The host driver can just as easly
read the accumulator to get this value.

The scratch ram savings is important as the old code used to clober the
SCSICONF register on 274X cards which sits near the top of scratch ram
space.  The SCSICONF register controls bus termination, and clobbering
it is not a good thing.  Now we have 4 bytes to spare.

This should fix the reported problems with cards that don't have devices
attached to them failing with a stream of "Somone reset bus X" messages.

Doug Ledford determined the cause of the problem, fixes by me.
1997-09-27 19:37:31 +00:00
Justin T. Gibbs
c66dbc92d4 Make the aic7xxx sequencer assembler compile in the kernel's object
directory.  Rename (via repository copy) some files so that the potential
for future conflicts is minimized.

PR: conf/4363
1997-09-03 03:44:58 +00:00
Justin T. Gibbs
083bc8b2cc Add a spin lock that prevents the sequencer from attempting to add an
entry to the QOUTFIFO when it is full.  This should eliminate the
"Timed out while idle" problems that many have reported.

In truth, this is somewhat of a hack.  Although are interrupt latency is
low enough that we should be able to always service the queue in time,
since each entry must be passed up to the higher SCSI layer for what can
be a large amount of processing (perhaps even resulting in a new command
being queued) with interrupts disabled, we need this mechanism to avoid
overflow.  In the future, these additional tasks will be offloaded to a
software interrupt handler which should make this hack unnecessary.
1997-08-13 17:02:47 +00:00
Justin T. Gibbs
f68f348b20 Modify my copyright notice to allow the sequencer to be used with GPLed
software (aka Linux).

Fix a few bugs in the sequencer assembler.

Make it easy to compiler the assembler with debugging turned on.
1997-06-27 19:38:56 +00:00
Justin T. Gibbs
cd6867d0d3 The following scenario would result in a bogus residual being reported
if SCB Paging was enabled:

    disconnect with more data to transfer
    disconnected SCB gets paged out
    target reconnects so we page SCB back in
    target completes transfer so residual is 0
    target disconnects
    SCB gets reused but not paged out since the residual is 0 (optimization)
    target reconnects so we page the SCB back in
    we report a residual because of stale residual information.

The fix for this is to set a flag that forces the SCB to be paged back
up to the host if we page in an SCB with a residual

Pointed out by: Doug Ledford <dledford@dialnet.net>
1997-04-24 16:52:18 +00:00
Justin T. Gibbs
7bde50c604 Revert some changes to the selection and reselection code that were thought
to fix a selection timeout problem.

If we can't find an SCB for the reconnecting target, issue a bus device
reset as the SCSI2 spec suggests.

Add a missing call to "add_scb_to_free_list" in the non paging case.  In
the non-paging case, the SCBs don't really need to be on the free list,
but putting them there clears the tag field which is something the recovery
code depends on.
1997-04-18 16:31:55 +00:00
Justin T. Gibbs
45b7cf8750 Re-arange the selection and reselection code to hopefully kill the
spurious selection timeouts that have been reported.
1997-04-14 02:26:59 +00:00
Justin T. Gibbs
9ff0e63881 aic7xxx.seq:
Be consistant about testing for parity errors after waiting for a
	REQ on the bus.

	Don't ack the last byte in a transaction until after we've cleared
	all target state.

aic7xxx_asm.c:
	Test the return value of getopt against -1 not EOF. (Yet another
	shameless victum of the style guide being wrong).
1997-04-10 19:13:07 +00:00
Justin T. Gibbs
1961f6e884 Instead of testing for both SELDI and SELDO in SSTAT0 in the poll for work
loop, test for them separately.  The bug report from David Malone showed that
even though we had been reselected (SELDI was true), we sat in the poll for
work loop until the selection timeout timer expired.  It may be that the
SSTAT0 register doesn't like to have more than one bit tested at a time.
I've seen stranger things than this on these parts.
1997-04-05 22:03:47 +00:00
Justin T. Gibbs
bb5d13ea1c Add missing Id that was lost when the sequencer file format changed. 1997-04-04 19:35:30 +00:00
Justin T. Gibbs
5ea0ae111d When not using SCB paging, we can always directly index the SCB of interest
either by looking it up in the array of pending, per target, untagged
transactions, or by using the tag value passed in during the identify.  The
old code only direct indexed for tagged transactions.  This makes the
"findSCB" routine only necessary when SCB paging is enabled, so appropriately
conditionalize it.  This greatly simplifies the non SCB paging code flow.
1997-04-04 04:09:29 +00:00
Justin T. Gibbs
cbc7db3bf7 CFLAGS += -I. so that building in an obj directory works. 1997-04-03 05:56:00 +00:00
Justin T. Gibbs
23e11becca Re-arrange the code to upload an SCB to ensure that there is at least
on instruction between the last load into the DFIFO and enabling the DMA.
During back to back SCB DMA, it was possible to hang the card.
1997-03-24 05:02:55 +00:00
Justin T. Gibbs
1c147cc352 aic7xxx.seq:
Stick 4 more, twin channel only, instructions behind
	.if ( TWIN_CHANNEL)

aic7xxx_asm.c:
	Add the -O options which allows the specification of which options
	to include in a program listing.  This makes it possible to easily
	determine the address of any instruction in the program across
	different hardware/option configurations.  Updated usage() as well.
1997-03-18 19:18:39 +00:00
Bruce Evans
60b161a92a Don't depend on <sys/types.h> being (bogusly) included by <stdio.h>. 1997-03-16 17:31:59 +00:00
Justin T. Gibbs
65c303b1b1 Missed one. 1997-03-16 07:28:30 +00:00
Justin T. Gibbs
c5cb388883 Makefile gram.y scan.l sequencer.h symbol.c symbol.h aic7xxx_asm.c:
New sequencer assembler for the aic7xxx adapters.  This assembler
	performs some amount of register type checking, allows bit
	manipulation of symbolic constants, and generates "patch tables"
	for conditionalized downloading of portions of the program.
	This makes it easier to take full advantage of the different
	features of the aic7xxx cards without imposing run time penalies
	or being bound to the small memory footprints of the low end
	cards for features like target mode.

aic7xxx.reg:
	New, assembler parsed, register definitions fo the aic7xxx cards.
	This was done primarily in anticipation of 7810 support which
	will have a different register layout, but should be able to use
	the same assembler.  The kernel aic7xxx driver consumes a generated
	file in the compile directory to get the definitions of the register
	locations.

aic7xxx.seq:
	Convert to the slighly different syntax of the new assembler.

	Conditionalize SCB_PAGING, ultra, and twin features which shaves
	quite a bit of space once the program is downloaded.

	Add code to leave the selection hardware enabled during reconnects
	that win bus arbitration.  This ensures that we will rearbitrate
	as soon as the bus goes free instead of delaying for a bit.

	When we expect the bus to go free, perform all of the cleanup
	associated with that event "up front" and enter a loop awaiting
	bus free.  If we see a REQ first, complain, but attempt to
	continue.  This will hopefully address, or at least help diagnose,
	the "target didn't send identify" messages that have been reported.

Spelling corrections obtained from NetBSD.
1997-03-16 07:08:19 +00:00
Justin T. Gibbs
9b2a5540ff No longer clear all interrupt status when the sequencer is reset. The only
time that we really want to do this is when a bus reset causes the sequencer
to be reset and the kernel driver now handles this case.

Remove some reordering in the select2 routine that wasn't necessary.
It was an experimental fix for a race condition I fixed elsewhere, and
confused the code flow.

Don't bother looping on a parity error in the mesgout loop since we can't
see parity errors on out phases.

Clean up the mesgin_identify code.  In the old days, we "snooped" for tag
messages and used this as an indicator of whether or not the target was
using tagged transactions.  This forced the sequencer to ack the identify
before determining if a valid SCB matched the target meaning that an abort
message to handle this case might not be seen before the target entered a
data phase.  Since we can determin the "tagged-ness" of a target by looking
it up in the array of busy targets (recently introduced), we can determine
this up front simplifying the search code as well as ensuring we can follow
the SCSI specs method for rejecting a reselection.

When an SCB is placed on the free list, set its SCB_TAG to SCB_LIST_NULL.
This makes it much easier for the kernel driver to find active SCBs on the
card during error recovery.
1997-02-28 03:51:00 +00:00
Justin T. Gibbs
9df674522b Leave reselections on all the time.
If we are aborting an SCB from findSCB, don't add it back to the free list -
	the kernel driver will do this for us.
1997-02-25 03:02:58 +00:00
Peter Wemm
6875d25465 Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not
ready for it yet.
1997-02-22 09:48:43 +00:00
Justin T. Gibbs
5154778752 Enlarge the message out buffer from 6 to 8 bytes. Now that sync and wide
negotiation messages may be tagged, we were overrunning the old buffer.
The variable that was getting squashed is updated before the message goes
out, causing corrupted SDTR or WDTR messages.  Depending on the phases
traversed before message out, this could cause the wrong offset to be
negotiated allowing data overruns to occur.  The problem is easier to
detect with wide targets on the chain since the allowed offset is smaller.

Also removed the unnecessary  clearing of SPIORDY during the message out
phase.  We don't rely on SPIORDY any more.
1997-02-18 20:22:52 +00:00
Justin T. Gibbs
499c4ce9f6 Clear the DFCNTRL register after every busfree.
When setting the HCNT registers, do so in ascending order.

When performing tagged queueing in non-paging mode, also check the
disconnected bit in the SCB as extra sanity during a reconection.

Make the labels in the DMA routine more sane.

When doing a DMA, if we see the DMADONE condition come true, we can
simply turn of the DMA enable bits in DFCNTRL without testing the FIFO
state as HDONE is true when DMADONE is true and this emplies the FIFO is
empty.

These changes clear up the data overrun error messages and seem to prevent
the "timed out in data-in phase" problems.
1997-02-11 17:07:54 +00:00
Justin T. Gibbs
de1dc306be Clear the channel after (re)selection instead of once we see the bus go
free.

When we clear SCSIRATE, also clear the FAST20 bit in SXFRCTL0.  This also
allowed me to clean up some of the ULTRA code.

ULTRAENB->FAST20 to follow the convention in the Adaptec data books.

Fix the data-overrun code to set both stcnt and hcnt otherwise, the transfer
will just hang until we get a timeout.

Add implicit support for the NOOP message.  I've never heard of the driver
issueing a reject for one, but its silly to reject NOOP and who knows how a
device might react.

In the dma routine, check SDONE before cleaing SDMAEN.  The data books mention
SDONE possibly being cleared when SDMAEN is reset.  Clients of dma now need
to check if SINDEX is cleared to know if a phasemis occured.

Fix some comments to be correct.
1997-02-09 03:23:28 +00:00
Justin T. Gibbs
1d6abdbc6f In dma_finish, don't disturb the direction bit in DFCNTRL when turning off
host DMAs.  The additional test to ensure that the DMA has stopped is also
unnecessary since we've already waited for the DMA to complete.

Update my copyright for the new year.
1997-02-03 02:02:04 +00:00
Justin T. Gibbs
8ebddd1e01 Add 1997 to my copyright.
Expand the boundaries of a pause disabled region to close of possible race
condition.

Revert a portion of the DMA code to fix false overruns.

Add a missing "add_scb_to_free_list" so we don't leak SCBs.
1997-01-29 05:19:46 +00:00
Justin T. Gibbs
ed69a71305 Change the way DMA is handled during the command phase. Only test on
SDONE, not HDONE.

In the data phase dma handler, mask off just the enable bits instead of
clearing the whole register.  Clearing the direction bit could be bad.
Also don't stop a DMA until MREQPEND goes false.  Doing this may cause
an ABORT on the PCI bus although I have yet to see this happen.

Add definitions for MREQPEND and the BRDCTL register.  The BRDCTL register
is used to handle high byte termination and automatic termination testing.
1997-01-24 21:57:47 +00:00
Justin T. Gibbs
6d14c339f6 Clear the SCSI channel after we go to busfree instead of after re/selection.
Only enable reselections once the channel and SCSIRATE have been cleared.

Add a pause block around the test busy code in the non-tagged case to simplify
error recovery in the corner case of aborting an SCB that just got started.

Simplify reselection processing by removing the call to initialize_scsiid.

Clear the scsiseq re/select control bits and setup for catching bogus
busfrees earlier in the re/select process.

Improve the automatic PIO code.  It turns out that SPIORDY is not a reliable
hardware condition bit, so use REQINIT intstead.  Don't rely on PHASEMIS
either since it can take too long to come true.  Use a brute force comparison
instead.

Remove some unnecessary overhead in the command complete processing.  It
should be nearly impossible to overflow the QOUTFIFO (worst case 9 command
have to complete with at least 6 of them requiring paging on an aic7850),
so don't take the additional PIO hit to guard against this condition.  If we
don't see our interrupt in time, the system has bigger problems elsewhere.
If this ever does happen, the timeout handler will notice and retry the
command.
1997-01-22 18:01:07 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Justin T. Gibbs
3d9ab968cd Re-enable reselections as the first thing after we see a bus free. We seem
to miss reselections from some devices and since the reselection response
timeout is only 200ns, enabling reselections too late may be the cause of our
problem.
1996-12-03 17:04:51 +00:00
Justin T. Gibbs
70f6e5521c Conditionally enable the busfree interrupt to catch unexpected busfrees.
Immediate SCBs, since they always send messages that tell the target to
transition to bus free now rely on the busfree interrupt instead of the
IMMEDDONE sequencer interrupt that was generated before.

Rearrange some code in the message out loop to give ATN a little more time
to drop before we ACK the last byte.

Use SPIORDY instead of REQINIT when snooping for a tag message on a reconnect.
This is done for the same reasons we use SPIORDY in the inb functions.

When going into BITBUCKET mode, turn off HDMAEN in the DFCNTRL register so
that we can "not care" what the value of HCNT is.  If HCNT is 0, BITBUCKET
mode won't transfer any data if HDMAEN is set.  Seeing as we don't want the
transfer to even think about touching the host, this seems more sane anyway.
Thanks to "Dan Willis" <dan@plutotech.com> for pointing out that this was
a problem.
1996-11-22 08:25:23 +00:00
Justin T. Gibbs
ad34debda8 Change the way Automatic PIO is performed in the mesgin and mesgout phases.
SPIORDY should go active on any REQ of the bus, so testing for REQINIT is
not necessary.  It also seems that testing for SPIORDY is more robust then
REQINIT since SPIORDY comes active after REQINIT and PHASEMIS seems to take
some time to come true after REQ is asserted if the phase has changed.  Of
course, none of this is documented.

This should give the code savings of my original changes, without breaking the
driver on fast peripherals.
1996-11-21 06:18:33 +00:00
Justin T. Gibbs
bde5245890 Assert that we have seen an identify or have not disconneccted since the
initial selection when entering the status phase.  This is the same assertion
we use for all the other data transfer phases.

Hopefully fix the hangs in the mesgin and mesgout phases that I introduced
last week during some code cleanup.  I need to get some of these 12MB/s
drives so I can reproduce these hangs here...

Add a pause disable in the SCB paging case around our manipulation of the
QOUTQCNT variable.  This is simply extra sanity.

Set LASTPHASE to P_BUSFREE once we see a busfree so that the kernel driver can
differentiate this from a data out phase.
1996-11-16 01:07:35 +00:00
Justin T. Gibbs
8220b8706a Fix two problems with SCB Paging.
1) get_free_or_disc_scb was not being passed its argument correctly
   in one case

2) Add protection in the form of the QOUTQCNT variable to prevent
   overflowing the QOUTFIFO.

This should make SCB Paging work.  Really, I mean it now. 8-)
1996-11-11 05:16:41 +00:00
Justin T. Gibbs
775395aaac index_untagged_scb should rely solely on the argument passed in SINDEX and
not access SCB_TCL directly.  This could have caused problems on twin channel
adapters.

2.2 Candidate.
1996-11-05 07:51:29 +00:00
Justin T. Gibbs
853925d190 In data_phase_reinit when I converted the code to use bcopy, I should have
used mvi instead of mov.  Luckily this code is most likely never executed
since it is only there for sanity should a target goes into the data phase
twice during a single selection or reselection.
1996-10-28 17:00:24 +00:00
Justin T. Gibbs
85772b6529 Fix problems dealing with non-tagged devices when SCB paging is enabled.
Mostly this involved changing the semantics of the findSCB routine so that
it could be used at times other than handling a reconnection.
1996-10-28 06:01:08 +00:00
Justin T. Gibbs
971791f48d Go back to using DMA to get SCBs down to the adapter.
SCB paging is now handled almost entirely by the sequencer and also uses
DMA.  This should make SCB paging at least an order of magnitude more
efficient and vastly simplifies the implementation.

Add a few space optimizations so this code still fits on aic7770 chips.

Update comments.
1996-10-25 06:34:59 +00:00
Justin T. Gibbs
2ea8799246 Bring aic7xxx driver bug fixes from 'SCSI' into current. 1996-10-06 16:38:45 +00:00
Justin T. Gibbs
1ffa43c082 Detect and report dataphase overruns. Put the adapter into 'Bit Bucket'
mode when this occurs and allow the target to complete the transaction.
Force a retry on overruns since they are usually caused by termination or
cable problems.
1996-06-09 17:33:18 +00:00
Justin T. Gibbs
1d40e2f2c5 Hopefully fix the parity problem and the hang on message reject for good. 1996-06-08 06:54:06 +00:00
Justin T. Gibbs
e5442bc690 Don't use the auto ATN on parity error feature. It may be the source
of our parity handling problems.
1996-05-31 06:30:15 +00:00
Justin T. Gibbs
e1ca90bc57 Fix regression. It seems that you need at least one instruction between
seeing SPIORDY and checking for PHASEMIS.  My last change turned out to
be less cosmetic then I thought.

Pointed out by: Satoshi Asami <asami@cs.berkeley.edu>,
		Faried Nawaz <fn@pain.csrv.uidaho.edu
1996-05-30 14:31:08 +00:00
Justin T. Gibbs
56981243dd Merge in changes for NetBSD/OpenBSD.
Cosmetic change to p_mesgout code so that it "looks" the same as what
is done in the inb* routines.
NetBSD/OpenBSD support Submitted by:Noriyuki Soda <soda@sra.co.jp>,
				    Pete Bentley <pete@demon.net>,
				    Charles M. Hannum <mycroft@mit.edu>,
				    Theo de Raadt <deraadt@theos.com>
1996-05-30 07:18:39 +00:00
Justin T. Gibbs
070d32b1a9 Fix a race condition in p_mesgout* and inb* code that could allow a
phasemiss to sneak by without detection.  This should fix the
Wide/Narrow boot problems that have been reported since this bug
caused the driver ignore a narrow target rejecting wide negotiation.
1996-05-27 23:16:55 +00:00
Justin T. Gibbs
087b79e649 Correct a botched commit from yesturday. It helps to bring over the
right patch file.<sigh>
1996-05-23 15:02:18 +00:00
Justin T. Gibbs
61538c3003 Enable/Disable Ultra mode on a per target basis. This allows the driver
to use the full range of settings from 3.6-20MHz on any target.
1996-05-21 18:32:23 +00:00
Justin T. Gibbs
990f21682c One more linux -> __linux__ 1996-05-10 16:28:00 +00:00
Justin T. Gibbs
c2278994ed aic7xxx.seq:
Change #ifdef linux to #ifdef __linux__

aic7xxx_reg.h:
Remove unneeded BOFF_60BCLOCKS
define CHIPRSTACK to be the same as CHIPRST
define RESET_SCSI and CHANNEL_B_PRIMARY bits
All of these aer used during the setup of adapters.
1996-05-10 16:11:03 +00:00
Justin T. Gibbs
0a44712261 Implement SCB paging. This allows up to 255 active commands on
aic7770 >= Rev E, aic7850, aic7860, aic7870, and ai7880 based controllers.

Make findSCB safer for non-tagged commands when tagged commands are
active on the controller.  The symptoms of this problem were
"Overlapped commands attempted" messages during error recovery
attempts.

Compact scratch ram usage.  This leaves 8 bytes free for future use.

Clean up some comments.

aic7xxx_reg.h:
Update my copyright.
1996-04-20 21:20:31 +00:00
Justin T. Gibbs
c2c5fd345d aic7xxx.seq:
Fix support for the aic7850 by looking only at the relavent bits of the
    QINCNT.  The 7850 puts random garbage in the high bits and all my attempts
    to determine the cause of this failed.  This approach does seem to work
    around the problem.

    Don't trust SCSIPERR to tell us when there is a parity error.  On
    some revs of the 7870 and the 7880, this bit follows the parity of
    the current byte.  Instead of using a SEQINT to tell the kernel,
    re-enable the standard parity error interrupt since it seems to pause
    the sequencer right at the time of the error which is the effect we were
    looking for anyway.

aic7xxx_reg.h:
    Remove PARITY_ERROR seqeuncer interrupt type, its no longer used.

    Define QCOUNTMASK as the SRAM location for the mask to use on the
    QINCNT register.  QCOUNTMASK is determined by the number of SCBs
    supported by the device we're working on.

aic7xxx_asm.c
    Properly check the return value of fopen, and define the arg list
    in getopt correctly.
    Submitted by: Pete Bentley <pete@demon.net>
1996-03-31 03:02:37 +00:00
Justin T. Gibbs
75f0b9d070 Reset the DMA control register whenever we reset the sequencer.
Clear LASTPHASE on busfree so the kernel driver can tell that the
   sequencer is idle.
Fix some comments to reflect reality.
1996-03-10 07:02:32 +00:00
Justin T. Gibbs
5327d59536 Performance optimizations. Unroll all bcopies. Use PIO to transfer SCBs
since setting up the DMA is too costly.  Restructure for efficiency.

Pause the sequencer when a parity error occurs so that the kernel driver
knows during which phase the error was encountered.
1996-01-29 03:12:06 +00:00
Justin T. Gibbs
d2c8692ad0 Take a different approach to the SPIORDY race condition. Simply clear
SPIORDY just before we ack on the bus so that there is no chance to
see SPIORDY for the same byte twice.

Make some small modifications so that the Linux aic7xxx driver can use
our sequencer and register definition files verbatum.
1996-01-11 06:17:49 +00:00
Justin T. Gibbs
bff79954c2 Change the inb and outb routines slightly. It seems that waiting for
SPIORDY after polling REQINIT is a bad idea.
1996-01-09 16:14:03 +00:00
Justin T. Gibbs
78aeaf6139 aic7xxx.seq:
Add the same type of safeguards we use in the mesg_in phase to the mesg_out
phase.

aic7xxx_reg.h:
Add definitions for the DSCommand register for PCI adapters.
1996-01-07 19:18:28 +00:00
Justin T. Gibbs
a27c063027 Bring back the more heavy-weight version of the mesgin inb routines. Davidg's
testing made me think that some of the checks were superfluous, but
wcarchive (and Amancio) know better.
1996-01-05 16:11:49 +00:00
Justin T. Gibbs
67e73a53fc Null terminate execl's argument list.
Submitted by: Ron Lenk <rlenk@widget.xmission.com>
1996-01-05 01:48:07 +00:00
Justin T. Gibbs
adf516474d The long awaited stability patch set for the aic7xxx driver:
1) Use cpp to preprocess the sequencer code.

2) Convert all "magic numbers" to #defines shared by the sequencer and
   kernel driver via the aic7xxx_reg.h file.  (The assembler still needs
   to be re-written in lex/yacc to allow ~|& type constructions).

3) Raise ATN on parity errors for "in" phases and send an initiator detected
   error or message-in parity error message as appropriate.

4) Turn off the reselection hardware from the time or a (re)connection to
   busfree.  It seems that some fast targets were able to reconnect before
   the sequencer was able to see busfree.

5) The message buffer is considered "in-use" when there is a positive length
   count.  The ACTIVE_MSG flag was unnecesary.

6) Properly set SCB_NEXT_WAITING to SCB_LIST_HEAD in scbs being added to
   the waiting scb list.  This is a change in how the list code works to
   facilitate some planned work in the reset code.

7) The fields in the SCB have be re-arranged to be quad-word aligned.

8) The inb code has been rewritten to catch phasemisses and be more efficient.

9) Go back to "snooping the bus" to determine if the incomming identify
   message will be followed by a simple queue message.  Its much faster than
   doing a search through the SCBs.

10) Implement better tag range checking for incomming tags.

11) Make sdtr_to_rate more accurate (use 25 instead of 24 in calculations -
    must have been asleep that night).

12) Rearrange some routines to reduce code complexity and size.

13) Update comments and formatting.

14) Fixed bugs I've forgotten about??

Reviewed by: David Greenman <davidg@FreeBSD.org>
1996-01-03 06:25:32 +00:00
Justin T. Gibbs
157b011439 Fix the long dreaded Wide bug and enable WIDEODD for reads. 1995-11-07 05:31:28 +00:00
Justin T. Gibbs
3e4756a1ce Move aic7xxx register definitions from i386/scsi/aic7xxx.c to this file.
The hope is to make the sequencer and kernel code share this file, but
some work on our sequencer assembler will be needed first.
1995-11-05 04:37:25 +00:00
Justin T. Gibbs
1fa2b6b3da Only or in CLRCHN in SXFRCTL0. All other bits in this register are
initialized by the kernel driver now.
1995-10-29 05:56:31 +00:00
Justin T. Gibbs
fca911ecf3 Set SCSIGO generically before we determine the phase instead of doing it
in each phase routine.  Saves a few instructions.

Be more careful in how we deal with SXFRCTL0.  Or in the control bits of
interest instead of using mvi.  The kernel driver will set the ULTRAEN
bit of SXFRCTL0 if we are using Ultra (20MHz) mode and we don't want to
clobber it.

In sdtr_to_rate divide by two if we are in ultra mode to get the correct
setting since its a 20MHz instead of 10MHz scale.
1995-10-26 23:54:13 +00:00
Justin T. Gibbs
1b2a3cf51a Clean up the mesgin code to make it easier to read with proceedure lables
that are based on what mesage is being processed instead of just numbers.

Order the tests for incoming message type by level of occurance.
1995-08-06 05:15:45 +00:00
Justin T. Gibbs
71fb7601c2 Total rewrite of the dataphase sections of the sequencer. This was done
to replace the very poor, original implementation of Scatter/Gather operations.

Use a bit (that was freed up with the rewrite above) in the SCB control byte
to designate commands that should allow disconnection.  The kernel driver
makes this decision now instead of the sequencer since the sequencer can't
do the indexing very efficiently.

This commit drops the sequencer from 426 instructions to 390 most likely
freeing enough space to do a target mode implementation.
1995-08-05 17:31:39 +00:00
Justin T. Gibbs
116616a829 Fix two race conditions.
The first could occur because the original code would continue to reset
the SCSIID register while waiting for a selection.  This could potentially
conflict with a reconnect since a successfull reconnect will also set the
SCSIID register.  The fix is to use a separate wait loop after starting
a selection (as was done a few revisions ago).

The second probably never happens, but it was possible for a target to
reconnect while there was a pending SCB on the waiting list and not get
noticed.  The fix was to remove a supurflous check of the scb waiting
list.
1995-08-05 06:59:17 +00:00
Justin T. Gibbs
4dc2fc9088 Pause the sequencer when message only requests complete. This allows the
kernel driver to know the exact state of the sequencer after a BUS DEVICE
RESET or ABORT completes so it can properly clean up the request.
1995-07-31 08:21:59 +00:00
Justin T. Gibbs
475791c882 Change SCB_LIST_NULL to 0xff from 0x10 to allow for 255 commands. This
is needed for 3940 support.

Have tagged commands look to see if a target is "busy" with a non tagged
command before executing.  This prevents overlapped tagged and non tagged
commands which can happen since request sense commands are not tagged.
1995-07-04 20:58:57 +00:00
Rodney W. Grimes
9b2e535452 Remove trailing whitespace. 1995-05-30 08:16:23 +00:00
David Greenman
57cb71573d 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
Justin T. Gibbs
c28447da4c Restructure the arbitration loop to allow for reselections that win out over
the adapter's selections.  Many fast periferals were getting upset when
the sequencer decided to rearbitrate after the device had already won
arbitration.  This also forced the creation of a list threaded through
the SCBs (since we don't have enough space anywhere else) of commands that
are awaiting reselection.  This list is run down before any new transactions
from the input queue are allowed.  The list is appened to whenever we begin
a selection (simple case since the selecting device is always at the head)
and by the kernel driver whenever a request sense occurs.  In the common
case, the list is only one element long, but when a reselection wins out
over a selection and that reselection generates a request sense, the
outstanding selection required for the retreval of the sense code grows
the list.  On machines with many targets, this might cause the list to grow
large, so this solution, which will allow up to the maximum number of I/O
requests capible of the card elements in the list, was chosen.  The list
manipulation is trivial and adds three sequencer instructions of overhead
to the selection phase.

This fixes the "target busy" errors from micropolis drives and the bursty
I/O problem when performing I/O between a Quantum Grand Prix and any other
device.  I anticipate that this will correct many of the problems that
have been reported with this driver.

Reviewed by: Wcarchive and David Greenman
1995-04-27 17:44:27 +00:00
Justin T. Gibbs
3cddb2a3e2 John Aycock's BSD copyrighted sequencer assembler and sequencer code. This
is identical to the older version, just the copyright has changed.  Many
thanks go to Dean Gehnert of the Linux camp who went the extra mile to make
this happen.

Other changes:

Update assembler man page to include the -v and -D options

Merge in Dean's latest changes to the assembler

Have the sequencer do a MSG_REJECT when the negotiated syncronous rate
is lower than the adapter supports.  This forces asyncronous mode which
is faster at these rates anyway.

This code will be moved shortly to the non-gpld portion of the tree.
1995-04-15 21:45:56 +00:00
Justin T. Gibbs
0b000afb3b More code optimizations. Use a slightly different approach to decide
whether a reconnecting target is a tagged device or not.
1995-04-09 06:40:16 +00:00
Justin T. Gibbs
cc865dd008 Off by one error in -MSG-START+0 was just Justin being tired -- revert to
old value.

Remove unnecessary check for active messages in setup SCB.  This same test
would also jump to p_mesgin_done which would "ACK" an extra time possibly
confusing the target.

Tell the kernel driver whenever we send an ABORT_TAG message.
1995-04-01 19:51:40 +00:00
Justin T. Gibbs
5743c01c3f Major overhaul of the aic7xxx driver:
- Report valid residual byte counts.  We actually pause the sequencer
	  when the residual is non-zero.  I thought about using DMA to do this,
	  bus sequencer program space is tight.

	- Fix embarassing off by one error in the computation of a 2's
	  compliment variable.  This was most likely the cause of the
	  many problems reported with the tagged queuing code.

	- Handle "MAX_SYNC" as a special case (ie we are the ones starting
	  the sync negotiation sequence).  This was done so that the target
	  scratch area can be initialed to 0 offset (asyncronous transfers)
	  safely.  The initialization to 0 (was 15) is necessary since in
	  some cases a Wide negotiation could run into problems if SCSIRATE
	  was set wrong and we went into data(in/out).

	- Trim the DMA routines a little by using some procedures.  Net
	  effect is more functionality with 3 less instructions after this
	  update.

	- Toggle the WIDEODD bit of the DFCNTRL whenever this is not the
	  last SG block.  It has no effect in the 8bit bus configuration,
	  but in the Wide configuration ensures that the overlap byte is
	  held in the SCSI block if the transfer is odd so it will end
	  up in the next SG (the correct behavior).
1995-03-31 14:06:02 +00:00
Justin T. Gibbs
b8d72a5ae8 Make the aic7xxx assembler take quoted strings as a single token.
Make $Id the version variable which required the quoted string "feature".
1995-03-17 23:54:17 +00:00
Justin T. Gibbs
06f0e1ceb8 Be careful to maintain the bits in SBLKCTL that are reserved. 1995-03-07 09:00:44 +00:00
Justin T. Gibbs
7325b76b7d Add tagged queueing support to the aic7xxx sequencer code. 1995-02-22 01:37:52 +00:00
Justin T. Gibbs
1bca1a0922 Have version number track CSV version number. No other change. 1995-02-03 17:18:44 +00:00
Justin T. Gibbs
c135d93bbf aic7xxx.c:
Print out the length of the compiled sequencer program.

aic7xxx.seq:
	More optimizations.  Replace generic bcopy routine with bcopy_3
and bcopy_4 (ie unroll the loops) since these are the only two cases used.
Initialize SIMODE1 and SXFRCTL1 from the kernel in ahc_init instead of
at each selection/reselection since this is expensive and only needs to
be done once.  Condense function returns into previous instruction if possible.
Reorder some sections to kill superflous jumps.  These optimizations kill
the ~150k/s penalty adding support for Twin/Wide cards was costing since
the last place in the commaon path of execution where we had to do ugly,
convoluted testing for the type of card in the sequencer has gone away.
Next stop tagged queuing and target mode.
1995-01-22 00:46:53 +00:00
Justin T. Gibbs
0d56403998 At $Ids to all files. Have the sequencer use DMA to tranfer its SCB
(SCSI control block) instead of having the host PIO it down.  Also
reimplement WDTR and SDTR optimization to remove code in the sequencer
and place the responsibility of knowing when to initiate SDTR or WDTR
on the kernel driver.  This vastly shortens the sequencer program yet
yeilds the same performance.
1995-01-16 16:31:21 +00:00
Justin T. Gibbs
20c5e65572 Full support for 294x and Wide devices. Fixed month old bug in the SCSI
sense retrieval code that messed up CDROM devices.  This code will also
responde correctly to SDTR and WDTR messages from devices that start a
negotiation sequence.
1995-01-13 02:22:11 +00:00
Justin T. Gibbs
8ff1d93efb Update the sequencer code to handle both channels of Twin channel devices.
You can now sling 14 devices off of a 274xT.  In the process of adding
twin channel support, I removed all evident restrictions on supporting
Wide channeled devices, but I do not have a Wide controller to test them
on.

aic7770_seq.h, the pre-compiled header, is no longer needed since config
handles this dependancy.
1994-12-31 19:26:54 +00:00
Justin T. Gibbs
cb0d548bf4 Merge in latest Linux sequencer code release with my changes. This should
make the sequencer code fully compatible with the aic7870 (ie 294x adaptors).
I've also added to my local mods putting the sequencer into "FASTMODE" clock.
This gives upwards of 2M/sec write preformance improvement in some scenarios.
There haven't been any reports of this causing problems, and I have been
reaping the benifits of it for more than a week now.

This also includes a new version of the pre-generated file <ugh>

Obtained from: John Aycock (aycock@cpsc.ucalgary.ca) and myself
1994-11-29 23:04:23 +00:00
Justin T. Gibbs
8d244f9e3b Previous changes to the sequencer compiler backed out. We go back to
generating the .h file, and a pregenerated file is included.
1994-11-18 09:11:35 +00:00
Jordan K. Hubbard
9cc6cb724f Make the compiler spit out a .c file instead of a .h file. 1994-11-18 08:17:20 +00:00
Justin T. Gibbs
0ef8c3017a John Aycock's aic7770 sequencer code and assembler. There is currently
a discussion going on about removing this code from the burden of the
GPL, but it won't happen before Beta, and this code should be tested
before release.

Supports 27/2842 class adaptec cards and is almost capable of supporting
aic7870 based adapters (294X series cards).  It does not support Wide
controllers or the second channel on Twin boards although I have work in
progress on getting both channels and running.

I have also added a few performance improvements to this version that give
us approximately a 25% boost over the original driver.  These patches have
been submitted to the author.

Obtained from: Linux aic7770 driver (John Aycock - aycock@cpsc.ucalgary.ca)
1994-11-17 20:19:10 +00:00