History log of /freebsd-9.3-release/sys/dev/mpt/mpt_cam.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 264950 25-Apr-2014 marius

MFC: r260058

- Remove a redundant variable in mpt_pci_attach().
- #if 0 the currently unused paired port linking and unlinking of dual
adapters.
- Simplify MSI/MSI-X allocation and release. For a single one, we don't need
to fiddle with the MSI/MSI-X count and pci_release_msi(9) is smart enough
to just do nothing in case of INTx.
- Canonicalize actions taken on attach failure and detach.
- Remove the remainder of incomplete support for older FreeBSD versions.


# 253037 08-Jul-2013 mav

MFC r249468:
Stop abusing xpt_periph in random plases that really have no periph related
to CCB, for example, bus scanning. NULL value is fine in such cases and it
is correctly logged in debug messages as "noperiph". If at some point we
need some real XPT periphs (alike to pmpX now), quite likely they will be
per-bus, and not a single global instance as xpt_periph now.


# 252301 27-Jun-2013 marius

MFC: r252180

Flag mpt(4) as supporting unmapped I/O; all necessary conversion actually
already has been done as part of r246713 (MFCed to stable/9 in r251874)
except for a comment update.


# 251874 17-Jun-2013 scottl

Big MFC of the physbio changes necessary for unmapped I/O. These changes
have been in production at Netflix for several months with significant
success.

MFC r246713:

Reform the busdma API so that new types may be added without modifying
every architecture's busdma_machdep.c. It is done by unifying the
bus_dmamap_load_buffer() routines so that they may be called from MI
code. The MD busdma is then given a chance to do any final processing
in the complete() callback.

MFC r249538:
Some compilers issue a warning when wider integer is casted to narrow
pointer. Supposedly shut down the warning by casting through
uintptr_t.

MFC r251479:
Simplify the checking of flags for cam_periph_mapmem(). This gets rid of
a lot of code redundancy and grossness at very minor expense.

MFC r251837:
MFC r251842:
Add infrastructure for doing compatibility shims, as has been sorely
needed for the last 10 years. Far too much of the internal API is
exposed, and every small adjustment causes applications to stop working.
To kick this off, bump the API version to 0x17 as should have been done
with r246713, but add shims to compensate. Thanks to the shims, there
should be no visible change in application behavior.

Submitted by: kib, jeffr
Approved by: kib
Obtained from: Netflix


# 245986 27-Jan-2013 marius

MFC: r241875

Remove support for using Giant for locking within mpt(4). Finer grained
locking has been working fine for ~5.5 years by now.


# 245983 27-Jan-2013 marius

MFC: r241874

After r241858 (MFC'ed to stable/9 in r242286), remove the remainder of
FreeBSD ~4 support from mpt(4).


# 238013 02-Jul-2012 marius

MFC: r237546

Correct sizeof usage

Obtained from: DragonFly


# 237825 29-Jun-2012 ken

MFC r237601:
r237601 | ken | 2012-06-26 08:51:35 -0600 (Tue, 26 Jun 2012) | 38 lines

Fix an issue that caused the kernel to panic inside CTL when trying
to attach to target capable HBAs that implement the old immediate
notify (XPT_IMMED_NOTIFY) and notify acknowledge (XPT_NOTIFY_ACK)
CCBs. The new API has been in place since SVN change 196008 in
2009.

The solution is two-fold: fix CTL to handle the responses from the
HBAs, and convert the HBA drivers in question to use the new API.

These drivers have not been tested with CTL, so how well they will
interoperate with CTL is unknown.

scsi_target.c:Update the userland target example code to use the
new immediate notify API.

scsi_ctl.c: Detect when an immediate notify CCB is returned
with CAM_REQ_INVALID or CAM_PROVIDE_FAIL status,
and just free it.

Fix a duplicate assignment.

aic79xx.c,
aic79xx_osm.c:Update the aic79xx driver to use the new API.
Target mode is not enabled on for this driver, so
the changes will have no practical effect.

aic7xxx.c,
aic7xxx_osm.c:Update the aic7xxx driver to use the new API.

sbp_targ.c: Update the firewire target code to work with the
new API.

mpt_cam.c: Update the mpt(4) driver to work with the new API.
Target mode is only enabled for Fibre Channel
mpt(4) devices.


# 231629 13-Feb-2012 marius

MFC: r231228

Remove extra newlines from panic messages.


# 231626 13-Feb-2012 marius

Forced commit to denote that the commit message of r231623 actually
should have read:
MFC: r231518

Flesh out support for SAS1078 and SAS1078DE (which are said to actually
be the same chip):
- The I/O port resource may not be available with these. However, given
that we actually only need this resource for some controllers that
require their firmware to be up- and downloaded (which excludes the
SAS1078{,DE}) just handle failure to allocate this resource gracefully
when possible. While at it, generally put non-fatal resource allocation
failures under bootverbose.
- SAS1078{,DE} use a different hard reset protocol.
- Add workarounds for the 36GB physical address limitation of scatter/
gather elements of these controllers.

Tested by: Slawa Olhovchenkov

PR: 149220 (remaining part)


# 231623 13-Feb-2012 marius

MFC: r231518

Remove extra newlines from panic messages.


# 226303 12-Oct-2011 marius

MFC r226118:

Sync with ahc(4)/ahd(4)/sym(4) etc:
Zero any sense not transferred by the device as the SCSI specification
mandates that any untransferred data should be assumed to be zero.

Reviewed by: ken
Approved by: re (kib)


# 226067 06-Oct-2011 ken

MFC r225950:

Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.

Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.

This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.

This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.

camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().

Use scsi_get_sks() instead of accessing sense key specific
data directly.

scsi_modes: Update the control mode page to the latest version (SPC-4).

scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.

ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.

cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.

cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.

scsi_all.h: Lots of updated SCSI sense data and other structures.

Add function prototypes for the new sense data functions.

Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.

Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data

scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.

Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.

Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).

In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.

Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.

Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.

Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.

Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.

Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.

Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.

Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.

Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.

Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.

Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.

mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.

sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.

sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().

ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.

mps_sas.c,
mpt_cam.c: Set the sense residual properly.

iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.

iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.

umass.c: Use scsi_set_sense_data() to build sense data.

Grab the sense key using scsi_get_sense_key().

Calculate the sense residual properly.

isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.

Calculate and set the sense residual.

Approved by: re (kib)
Sponsored by: Spectra Logic Corporation


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 224761 10-Aug-2011 marius

o Improve 224494:
- Ignore some more internal SAS device status change events.
- Correct inverted Bus and TargetID arguments in a warning.
o Add a warning for MPI_EVENT_SAS_DISCOVERY_ERROR events, which can help
identifying broken disks.

Submitted by: Andrew Boyer
Approved by: re (kib)
Committed from: Chaos Communication Camp 2011


# 224494 29-Jul-2011 marius

- Send the RELSIM_ADJUST_OPENINGS in response to a MPI_EVENT_QUEUE_FULL using
the right SIM in case the HBA is RAID-capable but the target in question is
not a hot spare or member of a RAID volume.
- Report the loss and addition of SAS and SATA targets detected via PHY link
status changes and signalled by MPI_EVENT_SAS_DEVICE_STATUS_CHANGE to cam(4)
as lost devices and trigger rescans as appropriate. Without this it can take
quite some time until a lost device actually is no longer tried to be used,
if it ever stops. [1]
- Handle MPI_EVENT_IR2, MPI_EVENT_LOG_ENTRY_ADDED, MPI_EVENT_SAS_DISCOVERY
and MPI_EVENT_SAS_PHY_LINK_STATUS silently as these serve no additional
purpose beyond adding cryptic entries to logs.

Thanks to Hans-Joerg Sirtl for providing one of the HBAs these changes were
developed with and RIP to the mainboard that didn't survive testing them.

PR: 157534 [1]
Approved by: re (kib)
MFC after: 2 weeks


# 224493 29-Jul-2011 marius

- Staticize functions as appropriate and comment out unused ones.
- Sprinkle some const where appropriate.
- Consistently use target_id_t for the target parameter of mpt_map_physdisk()
and mpt_is_raid_volume().
- Fix some whitespace bugs.

Approved by: re (kib)


# 220945 22-Apr-2011 marius

Correct spelling.

Submitted by: brucec


# 219335 06-Mar-2011 marius

- Allocate the DMA memory shared between the host and the controller as
coherent.
- Add some missing bus_dmamap_sync() calls. This includes putting such
calls before calling reply handlers instead of calling bus_dmamap_sync()
for the request queue from individual reply handlers as these handlers
generally read back updates by the controller.

Tested on amd64 and sparc64.

MFC after: 2 weeks


# 217009 05-Jan-2011 marius

Remove a redundant variable assignment found with the clang static analyzer.

MFC after: 1 week


# 209599 29-Jun-2010 ken

Change the mpt driver to allow larger I/O sizes.

The mpt driver previously didn't report a 'maxio' size to CAM, and so the
da(4) driver limited I/O sizes to DFLTPHYS (64K) by default. The number
of scatter gather segments allowed, as reported to busdma, was
(128K / PAGE_SIZE) + 1, or 33 on architectures with 4K pages.

Change things around so that we wait until we've determined how many
segments the adapter can support before creating the busdma tag used for
buffers, so we can potentially support more S/G segments and therefore
larger I/O sizes.

Also, fix some things that were broken about the module unload path. It
still gets hung up inside CAM, though.

mpt.c: Move some busdma initialization calls in here, and call
them just after we've gotten the IOCFacts, and know how
many S/G segments this adapter can support.

mpt.h: Get rid of MPT_MAXPHYS, it is no longer used.

Add max_cam_seg_cnt, which is used to report our maximum
I/O size up to CAM.

mpt_cam.c: Use max_cam_seg_cnt to report our maximum I/O size to CAM.

Fix the locking in mpt_cam_detach().

mpt_pci.c: Pull some busdma initialization and teardown out and put
it in mpt.c. We now delay it until we know many scatter
gather segments the adapter can support, and therefore
how to setup our busdma tags.

mpt_raid.c: Make sure we wake up the right wait channel to get the
raid thread to wake up when we're trying to shut it down.

Reviewed by: gibbs, mjacob
MFC after: 2 weeks


# 207543 02-May-2010 mjacob

Print IR_RESYNC updates informatively.

Obtained from: pluknet
MFC after: 1 week


# 207286 27-Apr-2010 marius

Replace a magic value with the appropriate macro.


# 205932 30-Mar-2010 mjacob

nit: xpt_bus_deregister has to be called with the sim lock held.

MFC after: 1 month


# 203484 04-Feb-2010 mav

Do not release device, when changing number of openings.


# 198262 20-Oct-2009 kan

Use callout_init_mtx on FreeBSD versions recent enough. This closes
the race where interrupt thread can complete the request for which
timeout has fired and while mpt_timeout has blocked on mpt_lock.

Do a best effort to keep 4.x ang Giant-locked configurartions
compiling still.

Reported by: ups
Reviewed by: scottl


# 195275 01-Jul-2009 delphij

Use MPT_MAX_LUNS as maximium number of LUNs, not 7, for SAS and FC cases.
This matches Linux driver behavior.

Discussed with: scottl
Approved by: re (kensmith)
MFC after: 1 month


# 195274 01-Jul-2009 delphij

Change explicit maximium numbers to the defined macro MPT_MAX_LUNS.

Approved by: re (kensmith)


# 194903 24-Jun-2009 marius

- Remove unused variables. [1]
- Remove redundant zeroing of tmf_req which Coverity Prevent(tm) complains
about. [2]

Submitted by: Christoph Mallon [1]
Found with: Coverity Prevent(tm) [2]
CID: 2496 [2]
MFC after: 2 weeks


# 186878 07-Jan-2009 marius

Make the whole initiator mode part of mpt(4) endian-clean,
specifically SPI controllers now also work in big-endian
machines and some conversions relevant for FC and SAS
controllers as well as support for ILP32 machines which all
were omitted in previous attempts are now also implemented.
The IOCTL-interface is intentionally left (and where needed
actually changed) to be completely little-endian as otherwise
we would have to add conversion code for every possible
configuration page to mpt(4), which didn't seem the right
thing to do, neither did converting only half of the user-
interface to the native byte order.
This change was tested on amd64 (SAS+SPI), i386 (SAS) and
sparc64 (SAS+SPI). Due to lack of the necessary hardware
the target mode code is still left to be made endian-clean.

Reviewed by: scottl
MFC after: 1 month


# 178725 02-May-2008 jkim

Restore multi-release tradition of the driver.

Reviewed by: mjacob


# 172836 20-Oct-2007 julian

Rename the kthread_xxx (e.g. kthread_create()) calls
to kproc_xxx as they actually make whole processes.
Thos makes way for us to add REAL kthread_create() and friends
that actually make theads. it turns out that most of these
calls actually end up being moved back to the thread version
when it's added. but we need to make this cosmetic change first.

I'd LOVE to do this rename in 7.0 so that we can eventually MFC the
new kthread_xxx() calls.


# 172589 12-Oct-2007 scottl

For some blasted reason the SATA WC change frees a structure right in the
middle of using it.


# 171842 14-Aug-2007 scottl

Move callout initialization to the proper spot. This prevents panics during
error recovery.

Approved by: re
Found by: kan


# 170924 18-Jun-2007 scottl

Fix some debugging code that crept in accidentally.


# 170872 17-Jun-2007 scottl

Prepare for future integration between CAM and newbus. xpt_bus_register
now takes a device_t to be the parent of the bus that is being created.
Most SIMs have been updated with a reasonable argument, but a few exceptions
just pass NULL for now. This argument isn't used yet and the newbus
integration likely won't be ready until after 7.0-RELEASE.


# 170271 04-Jun-2007 scottl

Free the portinfo object on unload.


# 170252 03-Jun-2007 scottl

mpt.c:
mpt.h:
Add support for reading extended configuration pages.
mpt_cam.c:
Do a top level topology scan on the SAS controller. If any SATA
device are discovered in this scan, send a passthrough FIS to set
the write cache. This is controllable through the following
tunable at boot:

hw.mpt.enable_sata_wc:
-1 = Do not configure, use the controller default
0 = Disable the write cache
1 = Enable the write cache

The default is -1. This tunable is just a hack and may be
deprecated in the future.

Turning on the write cache alleviates the write performance problems with
SATA that many people have observed. It is not recommend for those who
value data reliability! I cannot stress this strongly enough. However,
it is useful in certain circumstances, and it brings the performence in line
with what a generic SATA controller running under the FreeBSD ATA driver
provides (and the ATA driver has had the WC enabled by default for years).


# 169293 05-May-2007 mjacob

Make this driver MP safe and still be a multi-release driver.

Obtained from: 99% of the work done by Scott Long.
MFC after: 3 days


# 168831 18-Apr-2007 scottl

Revert a driver API change to xpt_alloc_ccb that isn't necessary. Fix a
couple of associated error checks.


# 168752 15-Apr-2007 scottl

Remove Giant from CAM. Drivers (SIMs) now register a mutex that CAM will
use to synchornize and protect all data objects that are used for that
SIM. Drivers that are not yet MPSAFE register Giant and operate as
usual. RIght now, no drivers are MPSAFE, though a few will be changed
in the coming week as this work settles down.

The driver API has changed, so all CAM drivers will need to be recompiled.
The userland API has not changed, so tools like camcontrol do not need to
be recompiled.


# 168470 07-Apr-2007 mjacob

Hide bus reset announcements within bootverbose.

MFC after: 3 days


# 167426 10-Mar-2007 mjacob

feedback from RELENG_5 port


# 166897 23-Feb-2007 mjacob

Use the new xpt_rescan function to truly now have dynamic
attachment of new devices that arrive (and we notice them
via async Fibre Channel events). We've always had the
right thing (of sorts) happen when devices go away- this
is the corollary function that makes multipath failover
actually work.

MFC after: 2 weeks


# 166227 25-Jan-2007 mjacob

Whoops- #ifdef problem caused uninitialized transport. Not horribly
a problem, but caused annoying messages.


# 165814 05-Jan-2007 mjacob

(commented out) multipath fault injection code.

Some code to make diffs with RELENG_6 easier.


# 165808 05-Jan-2007 mjacob

Another (minor) CAM_NEW_TRAN backport thingie, plus a slightly
closer to __FreeBSD_version comparison for this.


# 165274 16-Dec-2006 mjacob

Make some slight reorganization (bringing back in some
non-CAM_NEW_TRAN code) to make diffs to previous FreeBSD
versions more manageable.


# 165058 09-Dec-2006 mjacob

Make mpt_pci depend on pci and mpt_cam depend on CAM.

PR: 106536
Suggested by: Norikatsu Shigemura
MFC after: 3 days


# 164990 07-Dec-2006 mjacob

MFP4: principally to reapply tagged command support to FC and SAS cards.


# 164907 05-Dec-2006 mjacob

use xpt_print function


# 164846 03-Dec-2006 mjacob

Fix a massive couple of botches here: the NVRAM settings
read wasn't flagging the SYNC mode was enabled. The temp
values for offset and sync period were uint8_t, but were
being assigned and shifted from a uint32_t value.

This didn't show up in testing because a random number
of 1030 cards set a bit that says "honor BIOS negotiation",
which means this whole code path was skipped.

This should clear up at least some of the negotation
issues that have been seen.


# 164837 02-Dec-2006 mjacob

Fix a debug message which didn't quite get it right about data direction.

Fix things to use the LSI-Logic Fusion Library mask and shift names for
offset and sync, no matter how awkward they are, in preference to just
plain numbers.


# 164415 19-Nov-2006 mjacob

If a TMF request fails to start, make sure that we pull it off the
pending list and set the state back to free prior to calling mpt_reset
so we don't panic at a later point.


# 164349 16-Nov-2006 mjacob

*smack* - forgot to do i386 compile, so last
commit broke things.


# 164348 16-Nov-2006 mjacob

Finally fix local command responses to set residual correctly.
This allows us to play nicely on SANs when we have target mode
enabled in f/w but have neither the scsi_targbh enabled or
scsi_targ with a target enabled.


# 164315 15-Nov-2006 jb

Add big endian support.

Submitted by: scottl
Reviewed by: mjacob


# 163925 02-Nov-2006 mjacob

Fix some negotiation issues (like not being able to negotiate async)


# 163896 01-Nov-2006 mjacob

2nd and final commit that moves us to CAM_NEW_TRAN_CODE
as the default.

Reviewed by multitudes.


# 163816 31-Oct-2006 mjacob

The first of 3 major steps to move the CAM layer forward to using
the CAM_NEW_TRAN_CODE that has been in the tree for some years now.

This first step consists solely of adding to or correcting
CAM_NEW_TRAN_CODE pieces in the kernel source tree such
that a both a GENERIC (at least on i386) and a LINT build
with CAM_NEW_TRAN_CODE as an option will compile correctly
and run (at least with some the h/w I have).

After a short settle time, the other pieces (making
CAM_NEW_TRAN_CODE the default and updating libcam
and camcontrol) will be brought in.

This will be an incompatible change in that the size of structures
related to XPT_PATH_INQ and XPT_{GET,SET}_TRAN_SETTINGS change
in both size and content. However, basic system operation and
basic system utilities work well enough with this change.

Reviewed by: freebsd-scsi and specific stakeholders


# 162534 21-Sep-2006 mjacob

Connect up a QUEUE FULL event with CAM and adjust openings.

Unfortunately, the QUEUE FULL event only tells you Bus && Target.
It doesn't tell you lun. In order for the XPT_REL_SIMQ action to
work, we have to have a real lun. But which one? For now, just
iterate over MPT_MAX_LUNS.

Practically speaking, this is only going to be happening for lower
quality SAS or SATA drives behind the SAS controller, which means
only lun 0, so it's not so bad.

Helpful Reminder Nagging from: John Baldwin, Fred Whiteside

MFC after: 5 days


# 162133 07-Sep-2006 mjacob

Create a 'ready' handler for each personality. The purpose of this handler
is to able to be called after *all* attach and enable events are done.

We establish a SYSINIT hook to call this handler. The current usage for it
is to add scsi target resources *after* all enables are done. There seems
to be some dependencies between different halves of a dual-port with respect
to target mode.

Put in more meaningful event messages for some events- in particular
QUEUE FULL events so we can see what the queue depth was when the
IOC sent us this message.

MFC after: 1 week


# 162059 05-Sep-2006 mjacob

The poison pill of death: adding a target mode reply handler and target
resources to a non-FC card killed us dead. Sorry for the breakage since
last July 12.


# 160649 24-Jul-2006 mjacob

When probing to attach the CAM functionality, check against
desired role configuration instead of existing role. This gets
us out of the mess where we configured a role of NONE (or were
LAN only, for example), but didn't continue to attach the CAM
module (because we had neither initiator nor target role
set). Unfortunately, the code that rewrites NVRAM to match
actual to desired role only works if the CAM module attaches.

MFC after: 2 weeks


# 160397 16-Jul-2006 mjacob

Add sysctl information about things like WWNN/WWPN.

MFC after: 2 weeks


# 160396 16-Jul-2006 mjacob

If we're in mpt_wait_req and the command times out,
mark it as timed out. Don't try and free the config
request for read_cfg_header that times out because
it's still active. Put in code for the config reply
handler that will then free up timed out requests.

Fix the FC_PRIMITIVE_SEND completion to not try
and free a command twice. Dunno how this possibly
could have been working for awhile.

MFC after: 2 weeks


# 160391 15-Jul-2006 mjacob

If the card has target mode enabled, and we hang
out ELS buffers but *don't* hang out commands,
we hang folks on the SAN because the LSI-Logic
f/w apparently sends back BUSY or QFULL or some
darn thing.

If we add command buffers, we have to respond to
them sensibly even if we don't have any upstream
listeners (scsi_targ or scsi_targ_bh), so put in
some local command reponse stuff.

MFC after: 2 weeks


# 160290 12-Jul-2006 mjacob

Fix config page writes to not strip out the attributes when you
actually go write the config page. This fixes the long standing
problem about updating NVRAM on Fibre Channel cards and seems
so far to not break SPI config page writes.

Put back role setting into mpt. That is, you can set a desired role
for mpt as a hint. On the next reboot, it'll pick that up and redo
the NVRAM settings appropriately and warn you that this won't take
effect until the next reboot. This saves people the step of having
to find a BIOS utilities disk to set target and/or initiator role
for the MPT cards.


# 159943 26-Jun-2006 mjacob

VMWare ESX reports > 16 targets for the LSI-Logic
U320 model it emulates. Then it crashes and burns
when you probe that high.


# 159919 25-Jun-2006 mjacob

Major Fixes:

Don't enable/disable I/O space except for SAS adapters.
This fixes a problem with VMware 4.5 Workstation.

Fix an egregious bug introduced to target mode so it actually
will not panic when you first enable a lun.

Minor fixes:

Take more infor from port facts and configuration pages.

MFC after: 1 week


# 159471 09-Jun-2006 jkim

Add ability to reset individual devices and fix SCSI speed negotiation.

Reviewed by: mjacob (initial version)


# 159312 05-Jun-2006 mjacob

Do some source && comment cleanup.

Clean out the abortive start to homegrown, per-mpt,
Domain Validation. This should really be done at a
higher level.

Use the PIM_SEQSCAN flag for U320- this seems to correct
cases of being unable to consistently negotiate U320 in
the cases where I'd seen this before.

Between this and other recent checkins, this driver is
pretty close to being ready for MFC.

Reviewed by: scottl, ken, scsi@
MFC after: 1 week


# 159178 02-Jun-2006 mjacob

More checkpointing on the way toward really (finally)
fixing speed negotiation.

Also fix the mpt_execute_req function to actually
match mpt_execute_req_a64. This may explain why
i386 users were having more grief.


# 159052 29-May-2006 mjacob

Add acknowledgements to LSI-Logic for support


# 159051 29-May-2006 mjacob

+ Change some debug messages to MPT_PRT_NEGOTIATE level (so we
can see the results of SPI negotiation w/o being overwhelmed
with other crap).

+ For U320 devices, check against both Settings *and* DV flags before
deciding whether we need to skip actual SPI settings for a device.

+ Go back to creating a 'physical disk' side of a raid/passthru bus that
is limited to the number of maximum physical disks. Actually, this isn't
probably *quite* right yet for one RAID volume, and if we ever end up
with finding a device that supports more than one RAID volume (not likely),
it probably won't quite be right either.

The problem here is that the creating of this 'physical' passthru sim is
just a cheap way to leverage off the CAM midlayer to do our negotiation
for us on the subentities that make up a RAID volume. It almost causes
more trouble than it is worth because we have to remember which side
we're talking to in terms of forming commands and which target ids are
real and so on. Bleah.

+ Skip trying to actually do SPI settings for the RAID volumes on the
real side of the raid/passthru bus pair- this just confuses the issue.
The underlying real physical devices will have the negotiation performed
and the Raid volume will inherit the resultant settings. At the sime time,
non-RAID devices can be on the same real bus, so *do* perform negotiations
with them.

+ At the end of doing all of the settings twiddling, *ahem*, remember to
go update the settings on the card itself (dunno how this got nuked).

At this point, negotiations *seem* to be being done (again) correctly for
both RAID volumes and their subentities. And they seem to be *mostly*
now right for other non-RAID entities on the same bus (I ended up with
3 out of 8 other disks still at narror/async- haven't the slightest
idea why yes).

Finally, negotiations on a normal bus seem to work (again).

There's still more work coming into this area, but we're in the
final stretch.


# 158982 27-May-2006 mjacob

Work in progress toward fixing IM checked in after having
lost one set to a peninsula power failure last night. After
this, I can see both submembers and the raid volumes again,
but speed negotiation is still broken.

Add a mpt_raid_free_mem function to centralize the resource
reclaim and fixed a small memory leak.

Remove restriction on number of targets for systems with IM enabled-
you can have setups that have both IM volumes as well as other devices.

Fix target id selection for passthru and nonpastrhu cases.

Move complete command dumpt to MPT_PRT_DEBUG1 level so that just
setting debug level gets mostly informative albeit less verbose
dumping.


# 158935 26-May-2006 mjacob

Get most of the way back to having Integrated Mirroring work
again- the addition of target mode support broke it massively.


# 158278 04-May-2006 mjacob

Remove MPT_PRT_INVARIANT- it was a silly idea.


# 157944 21-Apr-2006 mjacob

Change some order of the way we do some target mode ops.

Found by Coverity.


# 157853 18-Apr-2006 mjacob

In receiving a new ATIO, don't record the associated CCB in the target
state structure. This field is only for CCBs that are associated with
actions that are occurring on the HBA (i.e., XPT_CONT_IO actions).

This way we also don't get confused when the upstream listener stalls
try and look at a CCB which has already been freed (by CAM).


# 157662 11-Apr-2006 mjacob

A large set of changes:

+ Add boatloads of KASSERTs and *really* check out more locking
issues (to catch recursions when we actually go to real locking
in CAM soon). The KASSERTs also caught lots of other issues like
using commands that were put back on free lists, etc.

+ Target mode: role setting is derived directly from port capabilities.
There is no need to set a role any more. Some target mode resources
are allocated early on (ELS), but target command buffer allocation
is deferred until the first lun enable.

+ Fix some breakages I introduced with target mode in that some commands
are *repeating* commands. That is, the reply shows up but the command
isn't really done (we don't free it). We still need to take it off the
pending list because when we resubmit it, bad things then happen.

+ Fix more of the way that timed out commands and bus reset is done. The
actual TMF response code was being ignored.

+ For SPI, honor BIOS settings. This doesn't quite fix the problems we've
seen where we can't seem to (re)negotiate U320 on all drives but avoids
it instead by letting us honor the BIOS settings. I'm sure this is not
quite right and will have to change again soon.


# 157354 01-Apr-2006 mjacob

Fix some of the previus changes 'better'.

There's something strange going on with async events. They seem
to be be treated differently for different Fusion implementations.
Some will really tell you when it's okay to free the request that
started them. Some won't. Very disconcerting.

This is particularily bad when the chip (FC in this case) tells you
in the reply that it's not a continuation reply, which means you
can free the request that its associated with. However, if you do
that, I've found that additional async event replies come back for
that message context after you freed it. Very Bad Things Happen.

Put in a reply register debounce. Warn about out of range context
indices. Use more MPILIB defines where possible. Replace bzero with
memset. Add tons more KASSERTS. Do a *lot* more request free list
auditting and serial number usages. Get rid of the warning about
the short IOC Facts Reply. Go back to 16 bits of context index.

Do a lot more target state auditting as well. Make a tag out
of not only the ioindex but the request index as well and worry
less about keeping a full serial number.


# 157117 25-Mar-2006 mjacob

Some fairly major changes to this driver.

A) Fibre Channel Target Mode support mostly works
(SAS/SPI won't be too far behind). I'd say that
this probably works just about as well as isp(4)
does right now. Still, it and isp(4) and the whole
target mode stack need a bit of tightening.

B) The startup sequence has been changed so that
after all attaches are done, a set of enable functions
are called. The idea here is that the attaches do
whatever needs to be done *prior* to a port being
enabled and the enables do what need to be done for
enabling stuff for a port after it's been enabled.

This means that we also have events handled by their
proper handlers as we start up.

C) Conditional code that means that this driver goes
back all the way to RELENG_4 in terms of support.

D) Quite a lot of little nitty bug fixes- some discovered
by doing RELENG_4 support. We've been living under Giant
*waaaayyyyy* too long and it's made some of us (me) sloppy.

E) Some shutdown hook stuff that makes sure we don't blow
up during a reboot (like by the arrival of a new command
from an initiator).

There's been some testing and LINT checking, but not as
complete as would be liked. Regression testing with Fusion
RAID instances has not been possible. Caveat Emptor.

Sponsored by: LSI-Logic.


# 156797 17-Mar-2006 mjacob

If we actually succeed in the Task Management Function where we
are aborting timed out commands, pull the request off the TAILQ.


# 156400 07-Mar-2006 mjacob

Add a serial number for requests so we don't just depend on a request pointer
to try and do forensics on what has occurred.


# 156104 28-Feb-2006 mjacob

Fix mpt_reset to try mpt_hard_reset more than once, and to try
mpt_soft_reset more than once. And to wait for MPT_DB_STATE_READY
twice. I mean, this is crucial- give the IOC a chance to get
ready.

If mpt_reset is called to reinit things, and we succeed, make
sure to re-enable interrupts. This is what has mostly led to
system lockup after having to hard reset the chip. Also, if
we think that interrupts aren't function in mpt_cam_timeout,
for goodness sake, turn them on again.

In read_cfg_header, return distinguishing errnos so the caller
can decide what's an error. It's *not* an error to fail to
read a RAID page from a non-RAID capable device like the FC929X.

Some whitespace fixes (removing spaces from ends of lines).


# 156041 26-Feb-2006 mjacob

Remove the ill-considered effect of using the type definitions as
distributed by LSI-Logic. For FreeBSD, just use the posix defines
instead of trying to figure out how wide an int is. Apologies to all.


# 156022 26-Feb-2006 mjacob

Shorten the time for waiting for TMF commands to complete- let's
not hang the system for 5 seconds. If a TMF doesn't complete within,
oh, say 500ms, that's enough.

Put in a printout to catch mpt_recover_commands being activated with
no commands.


# 156000 25-Feb-2006 mjacob

Role a microrev of the MPI Library in preparation for target mode work.

Make my portions of the license clearer.

Thank Chris Ellsworth for his support in getting a bunch of this done.


# 155895 22-Feb-2006 mjacob

Remove commented out qualifier to dumping a message.


# 155521 10-Feb-2006 mjacob

Do initial cut of SAS HBA support. These controllers (106X) seem to support
automatically both SATA and SAS drives. The async SAS event handling we catch
but ignore at present (so automagic attach/detach isn't hooked up yet).

Do 64 bit PCI support- we can now work on systems with > 4GB of memory.

Do large transfer support- we now can support up to reported chain depth, or
the length of our request area. We simply allocate additional request elements
when we would run out of room for chain lists.

Tested on Ultra320, FC and SAS controllers on AMD64 and i386 platforms.
There were no RAID cards available for me to regression test.

The error recovery for this driver still is pretty bad.


# 153072 04-Dec-2005 ru

Fix -Wundef.


# 148679 03-Aug-2005 gibbs

Correct attribution in clause three to address the correct copyright
holders. The license that was approved for my changes to this driver
originally came from LSI, but the changes to the driver core are not
owned by LSI.

MFC: 1 day


# 147883 10-Jul-2005 scottl

Massive overhaul of MPT Fusion driver:

o Add timeout error recovery (from a thread context to avoid
the deferral of other critical interrupts).
o Properly recover commands across controller reset events.
o Update the driver to handle events and status codes that
have been added to the MPI spec since the driver was
originally written.
o Make the driver more modular to improve maintainability and
support dynamic "personality" registration (e.g. SCSI Initiator,
RAID, SAS, FC, etc).
o Shorten and simplify the common I/O path to improve driver
performance.
o Add RAID volume and RAID member state/settings reporting.
o Add periodic volume resynchronization status reporting.
o Add support for sysctl tunable resync rate, member write cache
enable, and volume transaction queue depth.

Sponsored by
----------------
Avid Technologies Inc:
SCSI error recovery, driver re-organization, update of MPI library
headers, portions of dynamic personality registration, and misc bug
fixes.

Wheel Open Technologies:
RAID event notification, RAID member pass-thru support, firmware
upload/download support, enhanced RAID resync speed, portions
of dynamic personality registration, and misc bug fixes.

Detailed Changes
================
mpt.c mpt_cam.c mpt_raid.c mpt_pci.c:
o Add support for personality modules. Each module exports
load, and unload module scope methods as well as probe, attach,
event, reset, shutdown, and detach per-device instance
methods

mpt.c mpt.h mpt_pci.c:
o The driver now associates a callback function (via an
index) with every transaction submitted to the controller.
This allows the main interrupt handler to absolve itself
of any knowledge of individual transaction/response types
by simply calling the callback function "registered" for
the transaction. We use a callback index instead of a
callback function pointer in each requests so we can
properly handle responses (e.g. event notifications)
that are not associated with a transaction. Personality
modules dynamically register their callbacks with the
driver core to receive the callback index to use for their
handlers.

o Move the interrupt handler into mpt.c. The ISR algorithm
is bus transport and OS independent and thus had no reason
to be in mpt_pci.c.

o Simplify configuration message reply handling by copying
reply frame data for the requester and storing completion
status in the original request structure.

o Add the mpt_complete_request_chain() helper method and use
it to implement reset handlers that must abort transactions.

o Keep track of all pending requests on the new
requests_pending_list in the softc.

o Add default handlers to mpt.c to handle generic event
notifications and controller reset activities. The event
handler code is largely the same as in the original driver.
The reset handler is new and terminates any pending transactions
with a status code indicating the controller needs to be
re-initialized.

o Add some endian support to the driver. A complete audit is
still required for this driver to have any hope of operating
in a big-endian environment.

o Use inttypes.h and __inline. Come closer to being style(9)
compliant.

o Remove extraneous use of typedefs.

o Convert request state from a strict enumeration to a series
of flags. This allows us to, for example, tag transactions
that have timed-out while retaining the state that the
transaction is still in-flight on the controller.

o Add mpt_wait_req() which allows a caller to poll or sleep
for the completion of a request. Use this to simplify
and factor code out from many initialization routines.
We also use this to sleep for task management request
completions in our CAM timeout handler.

mpt.c:
o Correct a bug in the event handler where request structures were
freed even if the request reply was marked as a continuation
reply. Continuation replies indicate that the controller still owns
the request and freeing these replies prematurely corrupted
controller state.

o Implement firmware upload and download. On controllers that do
not have dedicated NVRAM (as in the Sun v20/v40z), the firmware
image is downloaded to the controller by the system BIOS. This
image occupies precious controller RAM space until the host driver
fetches the image, reducing the number of concurrent I/Os the
controller can processes. The uploaded image is used to
re-program the controller during hard reset events since the
controller cannot fetch the firmware on its own. Implementing this
feature allows much higher queue depths when RAID volumes
are configured.

o Changed configuration page accessors to allow threads to sleep
rather than busy wait for completion.

o Removed hard coded data transfer sizes from configuration page
routines so that RAID configuration page processing is possible.

mpt_reg.h:
o Move controller register definitions into a separate file.

mpt.h:
o Re-arrange includes to allow inlined functions to be
defined in mpt.h.

o Add reply, event, and reset handler definitions.

o Add softc fields for handling timeout and controller
reset recovery.

mpt_cam.c:
o Move mpt_freebsd.c to mpt_cam.c. Move all core functionality,
such as event handling, into mpt.c leaving only CAM SCSI
support here.

o Revamp completion handler to provide correct CAM status for
all currently defined SCSI MPI message result codes.

o Register event and reset handlers with the MPT core. Modify
the event handler to notify CAM of bus reset events. The
controller reset handler will abort any transactions that
have timed out. All other pending CAM transactions are
correctly aborted by the core driver's reset handler.

o Allocate a single request up front to perform task management
operations. This guarantees that we can always perform a
TMF operation even when the controller is saturated with other
operations. The single request also serves as a perfect
mechanism of guaranteeing that only a single TMF is in flight
at a time - something that is required according to the MPT
Fusion documentation.

o Add a helper function for issuing task management requests
to the controller. This is used to abort individual requests
or perform a bus reset.

o Modify the CAM XPT_BUS_RESET ccb handler to wait for and
properly handle the status of the bus reset task management
frame used to reset the bus. The previous code assumed that
the reset request would always succeed.

o Add timeout recovery support. When a timeout occurs, the
timed-out request is added to a queue to be processed by
our recovery thread and the thread is woken up. The recovery
thread processes timed-out command serially, attempting first
to abort them and then falling back to a bus reset if an
abort fails.

o Add calls to mpt_reset() to reset the controller if any
handshake command, bus reset attempt or abort attempt
fails due to a timeout.

o Export a secondary "bus" to CAM that exposes all volume drive
members as pass-thru devices, allowing CAM to perform proper
speed negotiation to hidden devices.

o Add a CAM async event handler tracking the AC_FOUND_DEVICE event.
Use this to trigger calls to set the per-volume queue depth once
the volume is fully registered with CAM. This is required to avoid
hitting firmware limits on volume queue depth. Exceeding the
limit causes the firmware to hang.

mpt_cam.h:
o Add several helper functions for interfacing to CAM and
performing timeout recovery.

mpt_pci.c:
o Disable interrupts on the controller before registering and
enabling interrupt delivery to the OS. Otherwise we risk
receiving interrupts before the driver is ready to receive
them.

o Make use of compatibility macros that allow the driver to
be compiled under 4.x and 5.x.

mpt_raid.c:
o Add a per-controller instance RAID thread to perform settings
changes and query status (minimizes CPU busy wait loops).

o Use a shutdown handler to disable "Member Write Cache Enable"
(MWCE) setting for RAID arrays set to enable MWCE During Rebuild.

o Change reply handler function signature to allow handlers to defer
the deletion of reply frames. Use this to allow the event reply
handler to queue up events that need to be acked if no resources
are available to immediately ack an event. Queued events are
processed in mpt_free_request() where resources are freed. This
avoids a panic on resource shortage.

o Parse and print out RAID controller capabilities during driver probe.

o Define, allocate, and maintain RAID data structures for volumes,
hidden member physical disks and spare disks.

o Add dynamic sysctls for per-instance setting of the log level, array
resync rate, array member cache enable, and volume queue depth.

mpt_debug.c:
o Add mpt_lprt and mpt_lprtc for printing diagnostics conditioned on
a particular log level to aid in tracking down driver issues.

o Add mpt_decode_value() which parses the bits in an integer
value based on a parsing table (mask, value, name string, tuples).

mpilib/*:
o Update mpi library header files to latest distribution from LSI.

Submitted by: gibbs
Approved by: re