Commit Graph

234 Commits

Author SHA1 Message Date
Justin T. Gibbs
1478c71123 aic7xxx.c:
Use the target offset rather than the target Id to reference
	the untagged SCB array.  The offset and id are identical save
	in the twin channel case.  This should correct several issues
	with the 2742T.

	Set the user and goal settings prior to setting the current
	settings.  This allows the async update routine to filter out
	intermediate transfer negotiation updates that may be less
	than interesting.  The Linux OSM uses this to reduce the amount
	of stuff printed to the console.

aic7xxx.seq:
	Correct an issue with the aic7770 in twin channel mode.
	We could continually attempt to start a selection even
	though a selection was already occurring on one channel.
	This might have the side effect of hanging our selection
	or causing us to select the wrong device.

	While here, create a separate polling loop for when we
	have already started a selection.  This should reduce
	the latency of our response to a (re)selection.  The diffs
	look larger than they really are due to some code rearrangement
	to optimize out a jmp.

aic7xxx_freebsd.c:
	Use the target offset rather than the target Id to reference
	the untagged SCB array.  The offset and id are identical save
	in the twin channel case.  This should correct several issues
	with the 2742T.

aic7xxx_inline.h:
	Get back in sync with perforce revision ID.

aic7xxx_pci.c:
	Identify adapters in ARO mode as such.

	Ensure that not only the subvendor ID is correct (9005)
	but also that the controller type field is valid before
	looking at other information in the subdevice id.  Intel
	seems to have decided that their subdevice id of 8086
	is more appropriate for some of their MBs with aic7xxx
	parts than Adaptec's sanctioned scheme.

	Add an exclusion entry for SISL (AAC on MB based adapters).
	Adapters in SISL mode are owned by the RAID controller, so
	even if a driver for the RAID controller is not present,
	it isn't safe for us to touch them.
2001-02-21 20:50:36 +00:00
Mark Murray
7547eefdf3 Set the interrupt-harvesting bit for those hardware items that I
can actually test.

Nothing will happen until the sysadmin turns on intr-harvesting
on her computer.
2001-02-18 18:02:15 +00:00
Jeroen Ruigrok van der Werven
7c63796828 Preceed/preceeding are not english words. Use precede or preceding. 2001-02-18 10:25:42 +00:00
Justin T. Gibbs
077c1bae60 Limit CHANNEL_B_PRIMARY's effect to twin channel adapters where we can easily
register our sub-busses in the reversed order.  In the future, we may provide
a hint to CAM on how to order the scans for multi-function adapters that also
set this flag, but trying to do it the "twin channel" way will lead to
a panic.
2001-02-17 01:53:22 +00:00
Justin T. Gibbs
bfadd24d57 aic7xxx.c:
Style nits.

	Make sure that our selection hardware is disabled
	as soon as possible after detecting a busfree and
	even go so far as to disable the selection hardware
	in advance of an event that will cause a busfree
	(ABORT or BUS DEVICE RESET message).  The concern
	is that the selection hardware will select a target
	for which, after processing the bus free, there
	will be no commands pending.  The sequencer idle
	loop will re-enable the selection should it still be
	necessary.

	In ahc_handle_scsiint(), clear SSTAT0 events several
	PCI transactions (most notably reads) prior to clearing
	SCSIINT.  The newer chips seem to take a bit of time to
	see the change which can make the clearing of SCSIINT
	ineffective.

	Don't bother panicing at the end of ahc_handle_scsiint().
	Getting to the final else just means we lost the race
	with clearing SCSIINT.

	In ahc_free(), handle init-level 0.  This can happen when we
	fail the attach for RAID devices.  While I'm here, also kill
	the parent dma tag.

	In ahc_match_scb(), consider initiator ccbs to be any
	that are not from the target mode group.  This fixes
	a bug where an external target reset CCB was not getting
	cleaned up by the reset code.

	Don't bother freezing a ccb in any of our "abort" routines
	when the status is set to CAM_REQ_CMP.  This can happen
	for a target reset ccb.

aic7xxx.reg:
	Reserve space for a completion queue.  This will be used
	to enhance performance in the near future.

aic7xxx.seq:
	Remove an optimization for the 7890 autoflush bug that
	turned out to allow, in rare cases, some data to get
	lost.

	Implement a simpler, faster, fix for the PCI_2_1 retry
	bug that hangs the sequencer on an SCB dma for certain chips.

	Test against SAVED_SCSIID rather than SELID during target
	reselections.  This is how we always did it in the past,
	but the code was modified while trying to work around an
	issue with the 7895.  SAVED_SCSIID takes into account
	twin channel adapters such as the 2742T, whereas SELID
	does not have the channel bit.  This caused invalid
	selection warnings and other strangeness on these cards.

aic7xxx_pci.c
	Use the correct mask for checking the generic aic7892
	entry.
2001-02-10 18:04:27 +00:00
Jeroen Ruigrok van der Werven
4539e1344f Fix typo: depricated -> deprecated. 2001-02-06 10:22:22 +00:00
Poul-Henning Kamp
fc2ffbe604 Mechanical change to use <sys/queue.h> macro API instead of
fondling implementation details.

Created with: sed(1)
Reviewed by: md5(1)
2001-02-04 13:13:25 +00:00
Justin T. Gibbs
64a3876fef Update Copyright notices for new year. (should have been in last commit). 2001-01-27 20:54:24 +00:00
Justin T. Gibbs
98ba52eadc When flipping the first entry in the qinfifo with the "next queued SCB",
we must also inform the card of this change.  Otherwise the sequencer
will traverse a corrupt list of SCBS.  The side effects of this problem
were unknown SCBs completing in the qoutfifo or worse yet, panics due
to sequencer interrupts that referenced what, to the kernel, were invalid
SCB ids.
2001-01-23 22:17:03 +00:00
Justin T. Gibbs
a5847d5c27 ahc_eisa.c:
Initialize rid to 0.  This doesn't seem to make any difference
	(the driver doesn't care what rid it gets and no-one seems to
	check rid's value), but follows standard conventions.

	Pass in our device_t to ahc_alloc().  We now use device_T
	softc storage, so passing NULL results in a panic.

	Set the unit number in our softc so that the driver core
	can retrieve it.

ahc_pci.c:
	Set the unit number in our softc so that the driver core
	can retrieve it.

aic7770.c:
	Insert our softc into the list of softcs when initialization
	is successful.

aic7xxx.c:
	Remove a workaround for an aic7895 bug we will never trigger.

	Add additional diagnostic info to ahc_dump_card_state().

	Always panic the system if a sequencer assertion fails.

	AHC_SCB_BTT is a "flag" not a "feature".  Check the right
	field in the softc.

	Replace a hard coded number with a constant.

	Guard against looping forever in ahc_pause_and_flushwork().
	A hot eject or card failure may make the intstat register
	return 0xFF, so limit the number of interrupts we'll process.

	Correct the code in ahc_search_qinfifo() that guarantees that
	the sequencer will see an abort collision if the qinfifo is
	modified when a DMA is in progress.  We now do this fixup
	after modifying the queue.  This guarantees that the HSCB
	we place at the head of the queue is not the same as the
	old head.  Using "next hscb" (guaranteed not to be the
	same as the first SCB) before clearing the queue could free
	up the original head hscb to be used during a remove operation
	placing it again at the head of the qinfifo.

aic7xxx.h:
	Reduce the maximum number of outstanding commands to 253 from
	254.  To handle our output queue correctly on machines that only
	support 32bit stores, we must clear the array 4 bytes at a
	time.  To avoid colliding with a DMA write from the sequencer,
	we must be sure that 4 slots are empty when we write to clear
	the queue.  This reduces us to 253 SCBs: 1 that just completed
	and the known three additional empty slots in the queue that
	preceed it.  Yahoo was able to force this race on one of their
	systems.  Interrupts were disabled for such a time that the
	entire output queue was filled (254 entries complete without
	any processing), and our 32bit write to clear the status clobbered
	one entry.

	Add a feature tag for devices that are removable.

aic7xxx.reg:
	Never use the sequencer interrupt value of 0xF0.  We need
	to guanrantee that an INTSTAT value of 0xFF can only occur
	during card failure or a hot-eject.

	Align the busy targets table with the begining of scratch
	space.  This seems to appease a chip bug in the aic7895.

aic7xxx.seq:
	Be sure to disable select-out after a bus free event that occurs
	early in a selection.  If we don't disable select-out, we will
	believe that it is enabled even though a new selection will never
	occur.

	Move the clearing of SELDI to just before a jump.  This appeases
	another chip bug of the aic7895.

	Make the target mode command loop a bit more efficient.

	AHC_SCB_BTT is a "flag" not a "feature".  Check the right
	field in the softc.

	Properly cleanup the last SCB we tested against should we
	fail to properly find an SCB for a reselection.

	Add some additional sequencer debugging code.

aic7xxx_freebsd.c:
	Limit the driver to 253 outstanding commands per adapter.

	Guard against overflow in timeout handling.

aic7xxx_inline.h:
	AHC_SCB_BTT is a "flag" not a "feature".  Check the right
	field in the softc.

aic7xxx_pci.c:
	Set the removable feature for the apa1480 cardbus and the 29160C
	Compact PCI card.

	Don't report high byte termination information for narrow cards.

	Use a PCI read rather than a questionable delay when fetching/setting
	termination settings.
2001-01-22 21:03:48 +00:00
Justin T. Gibbs
7615058657 Index our "DMA safe" sense buffers by SCB rather than hscb.
hscbs may be traded during error recovery due to the way
we manage the qinfifo.  This has the effect of changing the
index to the sense buffer even though the request sense command
references the original buffer.  SCBs don't play this swapping
game and so serve as a more consistent reference.
2001-01-09 00:40:38 +00:00
Justin T. Gibbs
f8838555e8 aic7xxx.c:
aic7xxx.h:
	First pass at big-endian support in the Core.

	Capture state for second channel on TWIN channel adapters
	for suspend and resume.

aic7xxx_freebsd.h:
	Stubs for endian conversion functions.  These will get filled
	out once we get an official kernel api for this kind of thing
	that is something more elegant and efficient than a bunch of
	manual swaps #ifdefed by platform.

aic7xxx_pci.c
	Allow the second channel of motherboard aic7896 chips to be attached.
	It turns out that the encoding of the subdevice id differs between
	PCI cards and MB based controllers and our check to see, via
	the subvendor id, if the second channel was "stuffed" always
	turned out negative.
2001-01-05 19:15:37 +00:00
Justin T. Gibbs
56a7c4a852 ahc_eisa.c:
ahc_pci.c:
		Add detach support.

		Make use of soft allocated on our behalf by newbus.

		For PCI devices, disable the mapping type we aren't
		using for extra protection from rogue code.

	aic7xxx_93cx6.c:
	aic7xxx_93cx6.h:
		Sync perforce IDs.

	aic7xxx_freebsd.c:
		Capture the eventhandle returned by EVENTHANDER_REGISTER
		so we can kill the handler off during detach.

		Use AHC_* constants instead of hard coded numbers in a
		few more places.

		Test PPR option state when deciding to "really" negotiate
		when the CAM_NEGOTIATE flag is passed in a CCB.

		Make use of core "ahc_pause_and_flushwork" routine in our
		timeout handler rather than re-inventing this code.

		Cleanup all of our resources (really!) in ahc_platform_free().
		We should be all set to become a module now.

		Implement the core ahc_detach() routine shared by all of
		the FreeBSD front-ends.

	aic7xxx_freebsd.h:
		Softc storage for our event handler.

		Null implementation for the ahc_platform_flushwork() OSM
		callback.  FreeBSD doesn't need this as XPT callbacks are
		safe from all contexts and are done directly in ahc_done().

	aic7xxx_inline.h:
		Implement new lazy interrupt scheme.  To avoid an extra
		PCI bus read, we first check our completion queues to
		see if any work has completed.  If work is available, we
		assume that this is the source of the interrupt and skip
		reading INTSTAT.  Any remaining interrupt status will be
		cleared by a second call to the interrupt handler should
		the interrupt line still be asserted.  This drops the
		interrupt handler down to a single PCI bus read in the
		common case of I/O completion.  This is the same overhead
		as in the not so distant past, but the extra sanity of
		perforning a PCI read after clearing the command complete
		interrupt and before running the completion queue to avoid
		missing command complete interrupts added a cycle.

	aic7xxx.c:
		During initialization, be sure to initialize all scratch
		ram locations before they are read to avoid parity errors.
		In this case, we use a new function, ahc_unbusy_tcl() to
		initialize the scratch ram busy target table.

		Replace instances of ahc_index_busy_tcl() used to unbusy
		a tcl without looking at the old value with ahc_unbusy_tcl().

		Modify ahc_sent_msg so that it can find single byte messages.
		ahc_sent_msg is now used to determine if a transfer negotiation
		attempt resulted in a bus free.

		Be more careful in filtering out only the SCSI interrupts
		of interest in ahc_handle_scsiint.

		Rearrange interrupt clearing code to ensure that at least
		one PCI transaction occurrs after hitting CLRSINT1 and
		writting to CLRINT.  CLRSINT1 writes take a bit to
		take effect, and the re-arrangement provides sufficient
		delay to ensure the write to CLRINT is effective.  The
		old code might report a spurious interrupt on some "fast"
		chipsets.

		export ahc-update_target_msg_request for use by OSM code.

		If a target does not respond to our ATN request, clear
		it once we move to a non-message phase.  This avoids
		sending a MSG_NOOP in some later message out phase.

		Use max lun and max target constants instead of
		hard-coded values.

		Use softc storage built into our device_t under FreeBSD.

		Fix a bug in ahc_free() that caused us to delete
		resources that were not allocated.

		Clean up any tstate/lstate info in ahc_free().

		Clear the powerdown state in ahc_reset() so that
		registers can be accessed.

		Add a preliminary function for pausing the chip and
		processing any posted work.

		Add a preliminary suspend and resume functions.

	aic7xxx.h:
		Limit the number of supported luns to 64.  We don't
		support information unit transfers, so this is the
		maximum that makes sense for these chips.

		Add a new flag AHC_ALL_INTERRUPTS that forces the
		processing of all interrupt state in a single invokation
		of ahc_intr().  When the flag is not set, we use the
		lazy interrupt handling scheme.

		Add data structures to store controller state while
		we are suspended.

		Use constants instead of hard coded values where appropriate.

		Correct some harmless "unsigned/signed" conflicts.

	aic7xxx.seq:
		Only perform the SCSIBUSL fix on ULTRA2 or newer controllers.
		Older controllers seem to be confused by this.

		In target mode, ignore PHASEMIS during data phases.
		This bit seems to be flakey on U160 controllers acting
		in target mode.

	aic7xxx_pci.c:
		Add support for the 29160C CPCI adapter.

		Add definitions for subvendor ID information
		available for devices with the "9005" vendor id.
		We currently use this information to determine
		if a multi-function device doesn't have the second
		channel hooked up on a board.

		Add rudimentary power mode code so we can put the
		controller into the D0 state.  In the future this
		will be an OSM callback so that in FreeBSD we don't
		duplicate functionality provided by the PCI code.
		The powerstate code was added after I'd completed
		my regression tests on this code.

		Only capture "left over BIOS state" if the POWRDN
		setting is not set in HCNTRL.

		In target mode, don't bother sending incremental
		CRC data.
2000-12-20 01:11:37 +00:00
Marcel Moolenaar
75a1da1e7a Fix include directories for crossbuilding.
aicasm is run on the build machine and therefore needs to be
compiled and linked against the headers and libraries (resp)
of the build machine. Since normally the default include
directories are search after any specified on the command
line, make sure we don't accidentally pick up machine
dependent headers from the kernel compile directory by
specifying /usr/include first.

This solves the (cross) build problem for ia64.

Approved by: gibbs
2000-12-13 23:15:12 +00:00
Justin T. Gibbs
96dfd8bb97 Don't attempt to reference a NULL scb_data area during teardown events
occurring early in initialization.  This fixes attachments to the parity
engines that FreeBSD doesn't support.
2000-11-13 03:35:43 +00:00
Justin T. Gibbs
420bf58729 aic7xxx.c:
Shutdown the card when a catastrophic error occurs.  This quenches
	any interrupts stemming from the card.

aic7xxx_inline.h:
	Return instead of processing additional interrupt state
	after handling a catastrophic error.  We now shutdown the
	chip in this case in the hopes that the system can live
	without this controller.  The shutdown process invalidates any
	other interrupt state.

aic7xxx.seq:
	Only attempt to clear SCSIBUSL on Ultra2 controllers.  The
	clearing is workaround for a selection timeout bug on U2/U160
	controllers and happens to be illegal on aic7770 (EISA/VL)
	controllers.
2000-11-12 05:19:46 +00:00
Justin T. Gibbs
72df3c5621 Sync Perforce IDs, add tranceiver state change support, and correct
numerous error recovery buglets.

Many thanks to Tor Egge for his assistance in diagnosing problems with
the error recovery code.

aic7xxx.c:
	Report missed bus free events using their own sequencer interrupt
	code to avoid confusion with other "bad phase" interrupts.

	Remove a delay used in debugging.  This delay could only be hit
	in certain, very extreme, error recovery scenarios.

	Handle transceiver state changes correctly.  You can now
	plug an SE device into a hot-plug LVD bus without hanging
	the controller.

	When stepping through a critical section, panic if we step
	more than a reasonable number of times.

	After a bus reset, disable bus reset interupts until we either
	our first attempt to (re)select another device, or another device
	attemps to select us.  This removes the need to busy wait in
	kernel for the scsi reset line to fall yet still ensures we
	see any reset events that impact the state of either our initiator
	or target roles.  Before this change, we had the potential of
	servicing a "storm" of reset interrupts if the reset line was
	held for a significant amount of time.

	Indicate the current sequencer address whenever we dump the
	card's state.

aic7xxx.reg:
	Transceiver state change register definitions.

	Add the missed bussfree sequencer interrupt code.

	Re-enable the scsi reset interrupt if it has been
	disabled before every attempt to (re)select a device
	and when we have been selected as a target.

	When being (re)selected, check to see if the selection
	dissappeared just after we enabled our bus free interrupt.
	If the bus has gone free again, go back to the idle loop
	and wait for another selection.

	Note two locations where we should change our behavior
	if ATN is still raised.  If ATN is raised during the
	presentation of a command complete or disconnect message,
	we should ignore the message and expect the target to put
	us in msgout phase.  We don't currently do this as it
	requires some code re-arrangement so that critical sections
	can be properly placed around our handling of these two
	events.  Otherwise, we cannot guarantee that the check of
	ATN is atomic relative to our acking of the message in
	byte (the kernel could assert ATN).

	Only set the IDENTIFY_SEEN flag after we have settled
	on the SCB for this transaction.  The kernel looks at
	this flag before assuming that SCB_TAG is valid.  This
	avoids confusion during certain types of error recovery.

	Add a critical section around findSCB.  We cannot allow
	the kernel to remove an entry from the disconnected
	list while we are traversing it.  Ditto for get_free_or_disc_scb.

aic7xxx_freebsd.c:
	Only assume that SCB_TAG is accurate if IDENTIFY_SEEN is
	set in SEQ_FLAGS.

	Fix a typo that caused us to execute some code for the
	non-SCB paging case when paging SCBs.  This only occurred
	during error recovery.
2000-11-10 20:13:41 +00:00
Justin T. Gibbs
aaad27fdfe Sync perforce IDs. 2000-11-10 19:54:17 +00:00
Justin T. Gibbs
47c2d60f79 aic7xxx.c:
When restarting the sequencer, ensure that the SCBCNT register
	is 0.  A non-zero count will prevent the setting of the CCSCBDIR
	bit in any future dma operations.  The only time CCSCBCNT would
	be non-zero is if we happened to halt the dma during a reset,
	but even that should never happen.  Better safe than sorry.

	When a command completes before the target responds to an
	ATN for a recovery command, we now notify the kernel so that
	any recovery operation requeued in the qinfifo can be removed
	safely.  In the past, we did this in ahc_done(), but ahc_done()
	may be called without the card paused.  This also avoids a
	recursive call to ahc_search_qinifo() which could have occurred if
	ahc_search_qinififo() happened to be the routine to complete
	a recovery action.

	Fix 8bit math used for adjusting the qinfifo.  The index must
	be wrapped properly within the 256 entry array.  We rely on the
	fact that qinfifonext is a uint8_t in most cases to handle
	this wrap, but we missed a few spots where the resultant
	calculation was promoted to an int.

	Change the way that we deal with aborting the first or second
	entry from the qinfifo.  We now swap the first entry in the
	qinfifo with the "next queued scb" to force the sequencer
	to see an abort collision if we ever touch the qinififo while
	the sequencer is mid SCB dma.

aic7xxx.reg:
	Add new MKMSG_FAILED sequencer interrupt.  This displaced
	the BOGUS_TAG interrupt used in some previous sequencer code
	debugging.

aic7xxx.seq:
	Increment our position in the qinfifo only once the dma
	is complete and we have verified that the queue has not
	been changed during our DMA.  This simplifies code in the
	kernel.

	Protect against "instruction creep" when issuing a pausing
	sequencer interrupt.  On at least the 7890/91/96/97, the
	sequencer will coast after issuing the interrupt for up
	to two instructions.  In the past we delt with this by
	using carefully placed nops.  Now we call a routine to
	issue the interrupt followed by a nop and a ret.

	Tell the kernel should an SCB complete with the MK_MESSAGE
	flag still set.  This means the target ignored our ATN request.

	Clear the channel twice as we exit the data phase.  On the
	aic7890/91, the S/G preload logic may require the second
	clearing to get the last S/G out of the FIFO.

aic7xxx_freebsd.c:
	Don't bother searching the qinfifo for a doubly queued
	recovery scb in ahc_done.  This case is handled by the
	core driver now.

	Free the path used to issue async callbacks after the callback
	is complete.

aic7xxx_inline.h:
	Split the SCB queue routine into a routine that swaps
	the SCB with the "next queued SCB" and a routine that
	calls the swapping routine and notifies the card of
	the new SCB.  The swapping routine is now also used by
	ahc_search_qinfifo.
2000-11-06 20:05:38 +00:00
Justin T. Gibbs
83b9eb545c Generate bmov instructions for all move requests. The driver
converts these to an equivalent 'and' operation on chips that
don't support this opcode.
2000-10-31 18:44:32 +00:00
Justin T. Gibbs
dd1290f033 aic7xxx.c:
Filter incoming transfer negotiation requests to ensure they
	never exceed the settings specified by the user.

	In restart sequencer attempt to deal with a bug in the aic7895.
	If a third party reset occurs at just the right time, the
	stack register can lock up.  When restarting the sequencer
	after handling the SCSI reset, poke SEQADDR1 before resting
	the sequencers program counter.

	When something strange happens, dump the card's transaction
	state via ahc_dump_card_state().  This should aid in debugging.

	Handle request sense transactions via the QINFIFO instead of
	attaching them to the waiting queue directly.  The waiting
	queue consumes card SCB resources and, in the pathological case
	of every target on the bus beating our selection attemps and
	issuing a check condition, could have caused us to run out
	of SCBs.  I have never seen this happen, and only early
	cards with 3 or 4 SCBs had any real chance of ever getting
	into this state.

	Add additional sequencer interrupt codes to support firmware
	diagnostics.  The diagnostic code is enabled with the
	AHC_DEBUG_SEQUENCER kernel option.

	Make it possible to switch into and out of target mode on
	the fly.  The card comes up by default as an initiator but
	will switch into target mode as soon as an enable lun operation
	is performed.  As always, target mode behavior is gated
	by the AHC_TMODE_ENABLE kernel option so most users will
	not be affected by this change.

	In ahc_update_target_msg_request(), also issue a new
	request if the ppr_options have changed.

	Never issue a PPR as a target.  It is forbidden by the spec.

	Correct a bug in ahc_parse_msg() that prevented us from
	responding to PPR messages as a target.

	Mark SCBs that are on the untagged queue with a flag instead
	of checking several fields in the SCB to see if the SCB should
	be on the queue.  This makes it easier for things like automatic
	request sense requests to be queued without touching the
	untagged queues even though they are untagged requests.

	When dealing with ignore wide residue messages that occur
	in the middle of a transfer, reset HADDR, not SHADDR for
	non-ultra2 chips.  Although SHADDR is where the firmware
	fetches the ending transfer address for a save data pointers
	request, it is readonly. Setting HADDR has the side effect
	of also updating SHADDR.

	Cleanup the output of ahc_dump_card_state() by nulling out the
	free scb list in the non-paging case.  The free list is only
	used if we must page SCBs.

	Correct the transmission of cdbs > 12 bytes in length.  When
	swapping HSCBs prior to notifing the sequencer of the new
	transaction, the bus address pointer for the cdb must also
	be recalculated to reflect its new location.  We now defer
	the calculation of the cdb address until just before queing
	it to the card.

	When pulling transfer negotiation settings out of scratch
	ram, convert 5MHz/clock doubled settings to 10MHz.

	Add a new function ahc_qinfifo_requeue_tail() for use by
	error recovery actions and auto-request sense operations.
	These operations always occur when the sequencer is paused,
	so we can avoid the extra expense incurred in the normal
	SCB queue method.

	Use the BMOV instruction for all single byte moves on
	controllers that support it.  The bmov instruction is
	twice as fast as an AND with an immediate of 0xFF as
	is used on older controllers.

	Correct a few bugs in ahc_dump_card_state().  If we have
	hardware assisted queue registers, use them to get the
	sequencer's idea of the head of the queue.  When enumerating
	the untagged queue, it helps to use the correct index for
	the queue.

aic7xxx.h:

	Indicate via a feature flag, which controllers can take
	on both the target and the initiator role at the same time.

	Add the AHC_SEQUENCER_DEBUG flag.

	Add the SCB_CDB32_PTR flag used for dealing with cdbs
	with lengths between 13 and 32 bytes.

	Add new prototypes.

aic7xxx.reg:
	Allow the SCSIBUSL register to be written to.  This is
	required to fix a selection timeout problem on the 7892/99.

	Cleanup the sequencer interrupt codes so that all debugging
	codes are grouped at the end of the list.

	Correct the definition of the ULTRA_ENB and DISC_DSB locations
	in scratch ram.  This prevented the driver from properly honoring
	these settings when no serial eeprom was available.

	Remove an unused sequencer flag.

aic7xxx.seq:
	Just before a potential select-out, clear the SCSIBUSL
	register.  Occasionally, during a selection timeout, the
	contents of the register may be presented on the bus,
	causing much confusion.

	Add sequencer diagnostic code to detect software and or
	hardware bugs.  The code attempts to verify most list
	operations so any corruption is caught before it occurs.
	We also track information about why a particular reconnection
	request was rejected.

	Don't clobber the digital REQ/ACK filter setting in SXFRCTL0
	when clearing the channel.

	Fix a target mode bug that would cause us to return busy
	status instead of queue full in respnse to a tagged transaction.

	Cleanup the overrun case.  It turns out that by simply
	butting the chip in bitbucket mode, it will ack any
	bytes until the phase changes.  This drasticaly simplifies
	things.

	Prior to leaving the data phase, make sure that the S/G
	preload queue is empty.

	Remove code to place a request sense request on the waiting
	queue.  This is all handled by the kernel now.

	Change the semantics of "findSCB".  In the past, findSCB
	ensured that a freshly paged in SCB appeared on the disconnected
	list.  The problem with this is that there is no guarantee that
	the paged in SCB is for a disconnected transation.  We now
	defer any list manipulation to the caller who usually discards
	the SCB via the free list.

	Inline some busy target table operations.

	Add a critical section to protect adding an SCB to
	the disconnected list.

aic7xxx_freebsd.c:
	Handle changes in the transfer negotiation setting API
	to filter incoming requests.  No filtering is necessary
	for "goal" requests from the XPT.

	Set the SCB_CDB32_PTR flag when queing a transaction with
	a large cdb.

	In ahc_timeout, only take action if the active SCB is
	the timedout SCB.  This deals with the case of two
	transactions to the same device with different timeout
	values.

	Use ahc_qinfifo_requeu_tail() instead of home grown
	version.

aic7xxx_inline.h:
	Honor SCB_CDB32_PTR when queuing a new request.

aic7xxx_pci.c:
	Use the maximum data fifo threshold for all chips.
2000-10-31 18:43:29 +00:00
Poul-Henning Kamp
da936bf80a Remove unneeded <stddef.h> #includes. 2000-10-29 16:57:42 +00:00
David Malone
5417ec4db1 Add the use of M_ZERO to some malloc calls.
Submitted by:	josh@zipperup.org
Submitted by:	Robert Drehmel <robd@gmx.net>
Approved by:	gibbs
2000-10-29 15:47:16 +00:00
Justin T. Gibbs
60754d0ba3 Bring back the ability to send cdbs of length 13->32 bytes. This was lost
during the qinfifo optimization.  When swapping HSCBs, we were only copying
the first 32 bytes, the amount used in the common case of a cdb <= 12 bytes.
Larger cdbs are stored in the second 32 bytes of the cdb.

Noticed by: Marc Frajola <marc@terasolutions.com>
2000-10-12 14:36:27 +00:00
Justin T. Gibbs
70351c9a14 Store a pointer to our softc in the kernel's SCB structure. In the
past we stored this data in the CCB and attained the CCB via a pointer
in the SCB.  In ahc_timeout(), however, the timedout SCB may have already
been completed (inherent race), meaning that the CCB could have been recycled,
and the ahc pointer reset.

Clean up the logic in ahc_search_qinfifo that deals with the busy device
table.  For some reason it assumed that the only valid time to search
to see if additional lun entries should be checked was if lun 0 matched.
Now we properly itterate through the necessary luns.  The busy device
table is used to detect invalid reselections, so a device would have had
to perform an unexpected reselection for this to cause problems.  Further,
all luns are collapsed to a single entry unless we have external ram
with large SCBs (3940AU models) so the chance of this happening was
rather remote.

Clean up the logic for dealing with the untagged queues.  We now set a
flag in the SCB that indicates that it is on the untagged queue instead
of inferring this from the type and setup of the CCB pased into us by
CAM.

In ahc_timeout(), don't print the path of the SCB until the controller
is paused and we are sure that it has not completed yet.  This, in
conjunction with referencing the ahc pointer in the SCB rather than
the CCB in the SCB avoids panics in the case of a timedout scb completing
just before the timeout handler runs.  This turns out to be guaranteed
if interrupt delivery is failing, as we run our interrupt handler to
flush any "just missed events" when a timeout occurs.  Mention the
likelyhood of broken interrupts if a timedout SCB is completed by
our call to ahc_intr().
2000-10-11 23:46:34 +00:00
Justin T. Gibbs
b00aeda6f0 Close a race condition that doesn't really exist in -current. When
a resource shortage occurs, freeze our queue and then set the resource
shortage flag while the controller data structure is locked.  The old
code did these in the wrong order potentially allowing our interrupt
handler to release the queue and clear the flag before the freeze
ever occurred.
2000-10-09 19:54:54 +00:00
Justin T. Gibbs
73f1c25915 Clean up error recovery code:
aic7xxx.c:
	In target mode, reset the TQINPOS on every restart of the sequencer.
	In the past we did this only during a bus reset, but there are other
	reasons the sequencer might be reset.

	In ahc_clear_critical_section(), disable pausing chip interrupts while
	we step the sequencer out of a critical section.  This avoids the
	possibility of getting a pausing interrupt (unexpected bus free,
	bus reset, etc.) that would prevent the sequencer from stepping.

	Send the correct async notifications in the case of a BDR or bus reset.

	In ahc_loadseq(), correct the calculation of our critical sections.
	In some cases, the sections would be larger than needed.

aic7xxx.h:
	Remove an unused SCB flag.

aic7xxx.seq:
	MK_MESSAGE is cleared by the kernel, there is no need to waste
	a sequencer instruction clearing it.

aic7xxx_freebsd.c:
	Go through the host message loop instead of issuing a single
	byte message directly in the ahc_timeout() case where we
	are currently on the bus to the device.  The effect is the same,
	but this way we get a nice printf saying that an expected BDR
	was delivered instead of an unexpected bus free.

	If we are requeuing an SCB for an error recovery action, be sure
	to set the DISCONNECTED flag in the in-core version of the SCB.
	This ensures that, in the SCB-paging case, the sequencer will
	still recognize the reselection as valid even if the version
	of the SCB with this flag set was never previously paged out
	to system memory.  In the non-paging case, set the MK_MESSAGE
	flag in SCB_CONTROL directly.

aic7xxx_pci.c:
	Enable the Memeory Write and Invalidate bug workaround for
	all aic7880 chips with revs < 1.  This bug is rarely triggered
	in FreeBSD as most transfers end on cache-aligned boundaries,
	but a recheck of my references indicates that these chips
	are affected.
2000-10-09 01:46:01 +00:00
Justin T. Gibbs
039c6f3637 Correct corruption of the qinfifo in ahc_search_qinififo() for all
non-LVD controllers.  We only need to take special action on the qinfifo
if we have dectected the case of an SCB that has been removed from the
qinfifo but has not been fully DMAed to the controller.  A missing
conditional caused this code to be executed every time an SCB was
aborted from the queue

Don't attempt to print the path of an SCB that has been freed.

Clean up the traversal of the pending scb list in
ahc_update_pending_syncrates().  This has no functional change.

Correct ahc_timeout()'s requeing of a timedout SCB to effect a
recovery action.  We now use ahc_qinfifo_requeue() and a
new function ahc_qinfifo_count() instead of performing the
requeue inline.  The old code did not conform to the new qinfifo
method.

Clear the timedout SCB from the disconnected list.  This ensures
that the SCB_NEXT field is free to be used for queuing us to
the qinfifo.
2000-10-08 03:37:52 +00:00
Justin T. Gibbs
580bfdfb00 Fix single character typo in legacy transfer settings function
thereby re-enable tagged queuing.
2000-10-06 19:34:40 +00:00
Justin T. Gibbs
ff0c1daf6b Bring in a slew of fixes that were supposed to be in the last commit.
In ahc_search_qinfifo, the SEARCH_REMOVE case must also handle
an SCB that has been removed from the QINFIFO but not yet been
fully dmaed to the card.

Correct locking for ahc_get_scb() calls.

Set SCB syncrate settings in ahc_execute_scb() to avoid a race
condition that could allow a newly queued SCB to be missed
by ahc_update_pending_syncrates().

When notifying the system of transfer negotiation updates, only
set the valid bits for tagged queuing and disconnection if the
path is fully qualified.  Sync/Wide settins apply to all luns
of a target, but tagged queuing and disconnection may change
on a per-lun basis.

Add missing ahc_unlock() calls in ahc_timeout() for the target
mode case.
2000-10-06 04:01:06 +00:00
Justin T. Gibbs
b1721cfbfd Correct pedantic errors in arrays generated by the assembler (trailing
comma in array declarations).

Output a constant indicating the number of critical section entries
in the firmware.
2000-10-05 04:25:42 +00:00
Justin T. Gibbs
a49630ac82 Convert the driver to use a single DMA for fetching new commands instead
of two (one to access the circular input fifo, the other to get the SCB).
This costs us a command slot so the driver can now only queue 254
simultaneous commands.

Have the kernel driver honor critical sections in sequencer code.

When prefetching S/G segments only pull a cacheline's worth but
never less than two elements.  This reduces the impact of the
prefetch on the main data transfer when compared to the 128
byte fetches the driver used to do.

Add "bootverbose" logging for transfer negotiations.

Correct a bug in ahc_set_syncrate() that would prevent an update
of the sync parameters if only the ppr_options had changed.

Correct locking for calls to ahc_free_scb().  ahc_free_scb() is no
longer protected internally to simplify ports to other platforms.

Make sure we unfreeze our SIMQ if a resource shortage has occurred
and an SCB is been freed.

ahc_pci.c:
	Turn on cacheline streaming for all controllers that support it.

	Clarify diagnostic messages about PCI interrupts.
2000-10-05 04:24:14 +00:00
Justin T. Gibbs
155c0683c7 ahc_set_transaction_status() takes an SCB. This makes it difficult to
use this helper function to report an error when SCB allocation fails.
2000-10-01 20:56:44 +00:00
Justin T. Gibbs
1c1c47a3e9 Correct a logic mistake introduced in a recent cleanup of
ahc_build_transfer_msg() that would cause use to fail to send the
DT_REQ ppr_option in a PPR message for periods where DT transfers
are required.
2000-09-25 21:56:19 +00:00
Justin T. Gibbs
083d01f20d Add Perforce RCSIDs for easy revision correlation to my local tree.
Add support for constructing a table of critical section regions in
the firmware image.  The kernel driver will soon have support for
single stepping the sequencer outside of a critical region prior
to starting exception handling.
2000-09-22 22:19:55 +00:00
Justin T. Gibbs
c498406d58 Add Perforce RCSIDs for easy revision correlation to my local tree.
ahc_pci.c:
	Bring back the AHC_ALLOW_MEMIO option at least until the
	memory mapped I/O problem on the SuperMicro 370DR3 is
	better understood.

aic7xxx.c:
	If we see a spurious SCSI interrupt, attempt to clear it and
	continue by unpausing the sequencer.

	Change the interface to ahc_send_async().  Some async messages
	need to be broadcast to all the luns of a target or all the
	targets of a bus.  This is easier to achieve by passing explicit
	channel, target, and lun parameters instead of attempting to
	construct a device info struct to match.

	Filter the sync parameters for the PPR message in exactly the
	same way we do for an old fashioned SDTR message.

	Correct some typos and correct a panic message.

	Handle rejected PPR messages.

	In ahc_handle_msg_reject(), let ahc_build_transfer_msg() build
	any additional transfer messages instead of doing this inline.

aic7xxx.h:
	Increase the size of both msgout_buf and msgin_buf to
	better accomodate PPR messages.

aic7xxx_freebsd.c:
	Update for change in ahc_send_async() parameters.

aic7xxx_freebsd.h
	Update for change in ahc_send_async() parameters.

	Honor AHC_ALLOW_MEMIO.

aic7xxx_pci.c:
	Check the error register before going into full blown PCI
	interrupt handling.  This avoids a few costly PCI configuration
	space reads when we run our PCI interrupt handler because another
	device sharing our interrupt line is more active than we are.

	Also unpause the sequencer after processing a PCI interrupt.
2000-09-22 22:18:05 +00:00
Justin T. Gibbs
ea6487b395 Use quoted includes instead of full path references inside the aic7xxx
sequencer files.  Different platforms place the included files in different
locations and it is easier to modify the include path passed as arguments
to the assembler than adding #ifdef support to the assembler.

Remove a spurious 'nop' instruction.
2000-09-22 22:06:44 +00:00
Justin T. Gibbs
dfd86f14c0 Remove the last two uses of ahc->unit in the FreeBSD version of the driver.
ahc->unit is depricated and will be going away as soon as the Linux
driver catches up.  In the FreeBSD case, it is always initialized to 0
and this caused some strangeness in registering multiple ahc controllers
with CAM.

Noticed by:	Tor.Egge@fast.no
2000-09-20 04:46:15 +00:00
Justin T. Gibbs
f175cbb663 Today is just not my day. Really get the right file. 2000-09-16 21:55:31 +00:00
Justin T. Gibbs
ae7c64e466 Pull the correct file over to freefall. 2000-09-16 20:59:12 +00:00
Justin T. Gibbs
32da3127a3 Move aicasm to its own subdirectory. 2000-09-16 20:02:39 +00:00
Justin T. Gibbs
717d424718 Move aicasm to its own subdirectory.
Separate our platform independent hooks from core driver functionality
shared between platforms (FreeBSD and Linux at this time).

Add sequencer workarounds for several chip->chipset interactions.

Correct external SCB corruption problem on aic7895 based cards (3940AUW).

Lots of cleanups resulting from the port to another OS.
2000-09-16 20:02:28 +00:00
Doug Rabson
21c3015a24 * Completely rewrite the alpha busspace to hide the implementation from
the drivers.
* Remove legacy inx/outx support from chipset and replace with macros
  which call busspace.
* Rework pci config accesses to route through the pcib device instead of
  calling a MD function directly.

With these changes it is possible to cleanly support machines which have
more than one independantly numbered PCI busses. As a bonus, the new
busspace implementation should be measurably faster than the old one.
2000-08-28 21:48:13 +00:00
Bill Paul
8ebe5155fa *smack* #if 0, not #ifdef 0. 2000-08-04 18:17:45 +00:00
Bill Paul
624539bb38 The check_extport() function appears to have some new code in it that checks
the scratch RAM for data normally found in the SEEPROM (presumably in the
event that the SEEPROM is unavailable or can't be read). This code causes
a spontaneous reboot on monster.osd.bsdi.com, which has an embedded aic7880
controller. The problem appears to happen either when it writes to the
SCBPTR port and then reads from the SCB_CONTROL port. Somewhere during
the inb/outb operations, the system has a heart attack and restarts.

This code looks very suspicious, particularly since it has unconditionalized
debug mesages such as "Got here!" and "And it even worked!". With this
block #ifdef'ed out, the machine boots and runs properly. I stronly suggest
that it stay #ifdef'ed out until it's properly tested.
2000-08-04 18:09:56 +00:00
Justin T. Gibbs
957790c3e6 ahc_pci.c:
Disable "cache line streaming" for aic7890/91 Rev A chips.  I
	have never seen these chips fail using this feature, but
	some of Adaptec's regression tests have.

	Explicitly set "cache line streaming" to on for aic7896/97
	chips.  This was happening before, but this documents the
	fact that these chips will not function correctly without
	CACHETHEEN set.

aic7xxx.h:
	Add new bug types.

	Fix a typo in a comment.

aic7xxx.reg:
	Add a definition for the SHVALID bit in SSTAT3 for Ultra2/3
	chips.  This bit inicates whether the bottom most (current)
	element in the S/G fifo has exhausted its data count.

aic7xxx.seq:
	Be more careful in how we turn off the secondary DMA channel.
	Being less careful may hang the PCI bus arbitor that negotiates
	between the two DMA engines.

	Remove an unecessary and incorrect flag set operation in
	the overrun case.

	On Ultra2/3 controllers, clear the dma FIFO before starting
	to handle an overrun.  We don't want any residual bytes from
	the beginning of the overrun to cause the code that shuts
	down the DMA engine from hanging because the FIFO is not
	(and never will be) empty.

	If the data fifo is empty by the time we notice that a
	read transaction has completed, there is no need to
	hit the flush bit on aic7890/91 hardware that will not
	perform an auto-flush.  Skip some cycles by short circuiting
	the manual flush code in this case.

	When transitioning out of data phase, make sure that we
	have the next S/G element loaded for the following
	reconnect if there is more work to do.  The code
	would do this in most cases before, but there was
	a small window where the current S/G element could
	be exhausted before our fetch of the next S/G element
	completed.  Since the S/G fetch is already initiated
	at this point, it makes sense to just wait for the
	segment to arrive instead of incuring even more latency
	by canceling the fetch and initiating it later.

	Fast path the end of data phase handling for the last
	S/G segment.   In the general case, we might have
	worked ahead a bit by stuffing the S/G FIFO with
	additional segments.  If we stop before using them
	all, we need to fixup our location in the S/G stream.
	Since we can't work past the last S/G segment, no
	fixups are ever required if we stop somewhere in
	that final segment.

	Fix a little buglet in the target mode dma bug handler.
	We were employing the workaround in all cases instead
	of only for the chips that require it.

	Fix the cause of SCB timeouts and possible "lost data"
	during read operations on the aic7890.  When sending
	a data on any Ultra2/3 controller, the final segment
	must be marked as such so the FIFO will be flushed and
	cleaned up correctly when the transfer is ended.  We
	failed to do this for the CDB transfer and so, if
	the target immediately transfered from command to data
	phase without an intervening disconnection, the first
	segment transferred would be any residual bytes from
	the cdb transfer.  The Ultra160 controllers for some
	reason were not affected by this problem.

Many Thanks to Tor Egge for bringing the aic7890 problem
to my attention, providing analysis, as well as a mechanism
to reproduce the problem.
2000-07-27 23:17:52 +00:00
Justin T. Gibbs
f94bf02fdb Properly handle the case where the residual is 0, but, as the target
didn't bother to send a saved data pointers after the last transfer,
is not recorded in sgptr.  This was only a problem if the target
reported non-zero status as we always check the residual in that case.
2000-07-25 20:40:34 +00:00
Justin T. Gibbs
c27eebfde8 aic7xxx.c:
Correct the BUILD_TCL macro.  It was placing the target id
	in the wrong bits.  This was only an issue for adapters that
	do not perform SCB paging (aha-3940AUW for instance).

	Don't bother inlining ahc_index_busy_tcl.  It is never
	used in a performance critical path and is a bit chunky.

	Correct ahc_index_busy_tcl to deal with "busy target tables"
	embedded in the latter half of 64byte SCBs.

	Don't initialize the busy target table to its empty state
	until after we have finished extracting configuration
	information from chip SRAM.  In the common case of using
	16 bytes of chip SRAM to do untagged target lookups,
	we were trashing the last 8 targets configuration data.
	(actually only target 8 because of the bug in the
	BUILD_TCL macro).

	Cram the "bus reset delivered" message back under bootverbose.

	Fix the cleanup of the SCB busy target table when aborting
	commands.  If the lun is wildcarded, we must loop through
	all possible luns.

aic7xxx.h:
	Only bother supporting 64 luns right now.  It doesn't seem
	like either this driver or any peripherals will be doing
	information unit transfers (where the lun number is a
	32 bit integer) any time soon.

aic7xxx.seq:
	Fix support for the aic7895.  We must flush the data
	FIFO if performing a manual transfer that is not
	a multiple of 8 bytes.  We were doing this quite
	regularly for embedded cdbs.

	Manaually flush the fifo on earlier adapters when
	dealing with embedded cdbs too.  We were stuffing
	the FIFO with 16 bytes instead, but triggering
	the flush is more efficient and allows us to
	remove two instructions from the "copy_to_fifo"
	routine.
2000-07-24 22:27:40 +00:00
Justin T. Gibbs
aa6dfd9d3d o Convert to <inttypes.h> style fixed sized types to facilitate porting to
other systems.

 o Normalize copyright text.

 o Clean up probe code function interfaces by passing around a single
   structure of common arguments instead of passing "too many" args
   in each function call.

 o Add support for the AAA-131 as a SCSI adapter.

 o Add support for the AHA-4944 courtesy of "Matthew N. Dodd" <winter@jurai.net

 o Correct manual termination support for PCI cards.  The bit definitions
   for manual termination control in the SEEPROM were incorrect.

 o Add support for extracting NVRAM information from SCB 2 for BIOSen
   that use this mechanism to pass this data to OS drivers.

 o Properly set the STPWLEVEL bit in PCI config space based on the
   setting in an SEEPROM.

 o Go back to useing 32byte SCBs for all controllers.  The current
   firmware allows us to embed 12byte cdbs on all controllers in
   a 32byte SCB, and larger cdbs are rarely used, so it is a
   better use of this space to offer more SCBs (32).

 o Add support for U160 transfers.

 o Add an idle loop executed during data transfers that prefetches
   S/G segments on controllers that have a secondary DMA engine
   (aic789X).

 o Improve the performance of reselections by avoiding an extra
   one byte DMA in the case of an SCB lookup miss for the reselecting
   target.  We now keep a 16byte "untagged target" array on the card
   for dealing with untagged reselections.  If the controller has
   external SCB ram and can support 64byte SCBs, then we use an
   "untagged target/lun" array to maximize concurrency.  Without
   external SCB ram, the controller is limited to one untagged
   transaction per target, auto-request sense operations excluded.

 o Correct the setup of the STPWEN bit in SXFRCTL1.  This control
   line is tri-stated until set to one, so set it to one and then
   set it to the desired value.

 o Add tagged queuing support to our target role implementation.

 o Handle the common cases of the ignore wide residue message
   in firmware.

 o Add preliminary support for 39bit addressing.

 o Add support for assembling on big-endian machines.  Big-endian
   support is not complete in the driver.

 o Correctly remove SCBs in the waiting for selection queue when
   freezing a device queue.

 o Now that we understand more about the autoflush bug on the
   aic7890, only use the workaround on devices that need it.

 o Add a workaround for the "aic7890 hangs the system when you
   attempt to pause it" problem.  We can now pause the aic7890
   safely regardless of what instruction it is executing.
2000-07-18 20:12:14 +00:00
Alexander Langer
0cca1cc078 Fix typo (accessable --> accessible).
PR:		18588
Submitted by:	Anatoly Vorobey <mellon@pobox.com>
Reviewed by:	asmodai
2000-06-14 17:53:40 +00:00