History log of /freebsd-current/sys/dev/mpt/mpt_cam.c
Revision Date Author Comments
# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# de992eed 21-May-2021 Edward Tomasz Napierala <trasz@FreeBSD.org>

mpt: clear CCBs allocated on the stack

Reviewed By: imp
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D30302


# 0f29396e 17-Apr-2021 Alexander Motin <mav@FreeBSD.org>

mpt(4): Remove incorrect S/G segments limits.

First, two of those four checks are unreachable.
Second, I don't believe there should be ">=" instead of ">".
Third, bus_dma(9) already returns the same EFBIG if ">".

This fixes false I/O errors in worst S/G cases with maxphys >= 2MB.

MFC after: 1 week


# 0bd9a5da 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

mpt: clean up empty lines in .c and .h files


# 5773ac11 10-Dec-2019 John Baldwin <jhb@FreeBSD.org>

Use callout_func_t instead of the deprecated timeout_t.

Reviewed by: kib, imp
Differential Revision: https://reviews.freebsd.org/D22752


# ac2fffa4 21-Jan-2018 Pedro F. Giffuni <pfg@FreeBSD.org>

Revert r327828, r327949, r327953, r328016-r328026, r328041:
Uses of mallocarray(9).

The use of mallocarray(9) has rocketed the required swap to build FreeBSD.
This is likely caused by the allocation size attributes which put extra pressure
on the compiler.

Given that most of these checks are superfluous we have to choose better
where to use mallocarray(9). We still have more uses of mallocarray(9) but
hopefully this is enough to bring swap usage to a reasonable level.

Reported by: wosch
PR: 225197


# 26c1d774 13-Jan-2018 Pedro F. Giffuni <pfg@FreeBSD.org>

dev: make some use of mallocarray(9).

Focus on code where we are doing multiplications within malloc(9). None of
these is likely to overflow, however the change is still useful as some
static checkers can benefit from the allocation attributes we use for
mallocarray.

This initial sweep only covers malloc(9) calls with M_NOWAIT. No good
reason but I started doing the changes before r327796 and at that time it
was convenient to make sure the sorrounding code could handle NULL values.


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 67445003 11-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Partially fix target task management requests handling.

- XPT_NOTIFY_ACKNOWLEDGE was not handled, causing stuck requests.
- XPT_ABORT was not even trying to abort active ATIOs/INOTs.
- Initiator's tag was not stored and not used where needed.
- List of TM request types needed update.
- mpt_scsi_tgt_status() missed some useful debugging.

After this change global TM requests, such as reset, should work properly.
ABORT TASK (ABTS) requests are still not passes to CTL, that is not good
and should be fixed.

MFC after: 2 weeks


# ead3ad6b 10-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Add PIM_EXTLUNS support to mpt(4).

Target mode is still limited to 256 LUNs due to the way driver is written,
but initiator can now use full 8 byte LUN space.

MFC after: 2 weeks


# 501b1685 10-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Improve residuals reporting in target mode.

MFC after: 2 weeks


# 4461a4a5 10-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Fix panic on wildcard target LUN disable.

MFC after: 2 weeks


# 93612a52 10-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Fix FC target mode in mpt(4), broken in multiple ways.

- Not set BufferLength caused receive of empty ATIOs.
- CDB length guessing was broken at least for RC16.
- mpt_req_untimeout() was called with wrong req parameter.
- Sense data reporting was broken in several ways.

With this change my LSI7204EP-LC can pass at least basic tests as target.
The code is still far from perfect, but finally I found second hw/driver
after isp(4) that really can work in CAM target mode.

MFC after: 2 weeks


# 471f963d 09-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Report some more data in XPT_PATH_INQ.

I am not sure they are used anywhere, but why not.

MFC after: 2 weeks


# 555dbebf 09-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Add support for XPT_GET_SIM_KNOB in FC mode.

MFC after: 2 weeks


# 4f38902f 09-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Report FC link speed.

MFC after: 2 weeks


# 4195c7de 04-Jan-2017 Alan Somers <asomers@FreeBSD.org>

Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)

The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".

This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.

PR: 215474
Reported by: Coverity
CID: 1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID: 1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID: 1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID: 1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID: 1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID: 1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID: 1010035 1010036 1010042 1010041 1010040 1010039
Reviewed by: imp, sephe, slm
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D9037
Differential Revision: https://reviews.freebsd.org/D9038


# 85c9dd9d 21-Nov-2014 Steven Hartland <smh@FreeBSD.org>

Prevent overflow issues in timeout processing

Previously, any timeout value for which (timeout * hz) will overflow the
signed integer, will give weird results, since callout(9) routines will
convert negative values of ticks to '1'. For unsigned integer overflow we
will get sufficiently smaller timeout values than expected.

Switch from callout_reset, which requires conversion to int based ticks
to callout_reset_sbt to avoid this.

Also correct isci to correctly resolve ccb timeout.

This was based on the original work done by Eygene Ryabinkin
<rea@freebsd.org> back in 5 Aug 2011 which used a macro to help avoid
the overlow.

Differential Revision: https://reviews.freebsd.org/D1157
Reviewed by: mav, davide
MFC after: 1 month
Sponsored by: Multiplay


# a2e4bd70 20-Jun-2014 Hiren Panchasara <hiren@FreeBSD.org>

Hide a harmless "QUEUE FULL EVENT" message behind bootverbose.

Requested by: A bunch of users on mailing-lists
Suggested by: scottl
MFC after: 1 week
Sponsored by: Yahoo! inc.


# e6ebfc7c 29-Dec-2013 Marius Strobl <marius@FreeBSD.org>

- 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.

MFC after: 1 week


# 7a22215c 30-Nov-2013 Eitan Adler <eadler@FreeBSD.org>

Fix undefined behavior: (1 << 31) is not defined as 1 is an int and this
shifts into the sign bit. Instead use (1U << 31) which gets the
expected result.

This fix is not ideal as it assumes a 32 bit int, but does fix the issue
for most cases.

A similar change was made in OpenBSD.

Discussed with: -arch, rdivacky
Reviewed by: cperciva


# 123055f0 30-Oct-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Adjust various SCSI drivers to handle either a 32-bit or 64-bit lun_id_t,
mostly by adjustments to debugging printf() format specifiers. For high
numbered LUNs, also switch to printing them in hex as per SAM-5.

MFC after: 2 weeks


# 5e63cdb4 21-Oct-2013 Alexander Motin <mav@FreeBSD.org>

Partial MFproject/camlock r256671:
Fix several target mode SIMs to not blindly clear ccb_h.flags field of
ATIO CCBs. Not all CCB flags there belong to them.


# f3385610 24-Jun-2013 Marius Strobl <marius@FreeBSD.org>

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

MFC after: 3 days


# e5dfa058 14-Apr-2013 Alexander Motin <mav@FreeBSD.org>

MFprojects/camlock r248982:
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.


# dd0b4fb6 12-Feb-2013 Konstantin Belousov <kib@FreeBSD.org>

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.

The cam changes unify the bus_dmamap_load* handling in cam drivers.

The arm and mips implementations are updated to track virtual
addresses for sync(). Previously this was done in a type specific
way. Now it is done in a generic way by recording the list of
virtuals in the map.

Submitted by: jeff (sponsored by EMC/Isilon)
Reviewed by: kan (previous version), scottl,
mjacob (isp(4), no objections for target mode changes)
Discussed with: ian (arm changes)
Tested by: marius (sparc64), mips (jmallet), isci(4) on x86 (jharris),
amd64 (Fabian Keil <freebsd-listen@fabiankeil.de>)


# ab42d234 22-Oct-2012 Marius Strobl <marius@FreeBSD.org>

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

MFC after: 1 week


# 4b847ffa 22-Oct-2012 Marius Strobl <marius@FreeBSD.org>

After r241858, remove the remainder of FreeBSD ~4 support from mpt(4).

MFC after: 1 week


# b79dc8a8 26-Jun-2012 Kenneth D. Merry <ken@FreeBSD.org>

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.

MFC after: 3 days


# c61325d0 24-Jun-2012 Kevin Lo <kevlo@FreeBSD.org>

Correct sizeof usage

Obtained from: DragonFly


# 04016bcf 10-Feb-2012 Marius Strobl <marius@FreeBSD.org>

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)


# 4349d278 08-Feb-2012 Marius Strobl <marius@FreeBSD.org>

Remove extra newlines from panic messages.


# 50e66535 07-Oct-2011 Marius Strobl <marius@FreeBSD.org>

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


# 1cc052e8 03-Oct-2011 Kenneth D. Merry <ken@FreeBSD.org>

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.

MFC after: 3 days
Sponsored by: Spectra Logic Corporation


# 1bf5a6cf 10-Aug-2011 Marius Strobl <marius@FreeBSD.org>

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


# ec3e6e77 29-Jul-2011 Marius Strobl <marius@FreeBSD.org>

- 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


# 87e255ac 29-Jul-2011 Marius Strobl <marius@FreeBSD.org>

- 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)


# 5ab13afc 22-Apr-2011 Marius Strobl <marius@FreeBSD.org>

Correct spelling.

Submitted by: brucec


# 6c5276c8 05-Mar-2011 Marius Strobl <marius@FreeBSD.org>

- 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


# 8929ea6f 05-Jan-2011 Marius Strobl <marius@FreeBSD.org>

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

MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 4201341f 29-Jun-2010 Kenneth D. Merry <ken@FreeBSD.org>

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


# 40a7bbab 07-Jun-2010 Matt Jacob <mjacob@FreeBSD.org>

MFC of 198262

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.

Approved by: re (kib)


# 2322c157 10-May-2010 Marius Strobl <marius@FreeBSD.org>

MFC: r207286

Replace a magic value with the appropriate macro.


# 5eb6cd02 02-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Print IR_RESYNC updates informatively.

Obtained from: pluknet
MFC after: 1 week


# 230a6155 29-Apr-2010 Matt Jacob <mjacob@FreeBSD.org>

This is an MFC of 205932.
nit: xpt_bus_deregister has to be called with the sim lock held.


# a8217f5c 27-Apr-2010 Marius Strobl <marius@FreeBSD.org>

Replace a magic value with the appropriate macro.


# f0b41ca4 30-Mar-2010 Matt Jacob <mjacob@FreeBSD.org>

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

MFC after: 1 month


# 66a894f3 13-Feb-2010 Alexander Motin <mav@FreeBSD.org>

MFC r203484:
Do not release device, when changing number of openings.


# e28a47de 04-Feb-2010 Alexander Motin <mav@FreeBSD.org>

Do not release device, when changing number of openings.


# 363b8ed7 19-Oct-2009 Alexander Kabaev <kan@FreeBSD.org>

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


# c4f739ec 01-Jul-2009 Xin LI <delphij@FreeBSD.org>

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


# 1635f049 01-Jul-2009 Xin LI <delphij@FreeBSD.org>

Change explicit maximium numbers to the defined macro MPT_MAX_LUNS.

Approved by: re (kensmith)


# 23f7f783 24-Jun-2009 Marius Strobl <marius@FreeBSD.org>

- 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


# 7ee37807 07-Jan-2009 Marius Strobl <marius@FreeBSD.org>

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


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# a41aabe2 02-May-2008 Jung-uk Kim <jkim@FreeBSD.org>

Restore multi-release tradition of the driver.

Reviewed by: mjacob


# 3745c395 20-Oct-2007 Julian Elischer <julian@FreeBSD.org>

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.


# 42f31cf9 12-Oct-2007 Scott Long <scottl@FreeBSD.org>

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


# 9adc3a2d 14-Aug-2007 Scott Long <scottl@FreeBSD.org>

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

Approved by: re
Found by: kan


# d38f7b62 18-Jun-2007 Scott Long <scottl@FreeBSD.org>

Fix some debugging code that crept in accidentally.


# b50569b7 16-Jun-2007 Scott Long <scottl@FreeBSD.org>

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.


# a54876ea 03-Jun-2007 Scott Long <scottl@FreeBSD.org>

Free the portinfo object on unload.


# 1d558d6a 03-Jun-2007 Scott Long <scottl@FreeBSD.org>

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).


# d0a68c27 05-May-2007 Matt Jacob <mjacob@FreeBSD.org>

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


# 8008a935 17-Apr-2007 Scott Long <scottl@FreeBSD.org>

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


# 2b83592f 15-Apr-2007 Scott Long <scottl@FreeBSD.org>

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.


# 7b88fb86 07-Apr-2007 Matt Jacob <mjacob@FreeBSD.org>

Hide bus reset announcements within bootverbose.

MFC after: 3 days


# fa80feee 10-Mar-2007 Matt Jacob <mjacob@FreeBSD.org>

feedback from RELENG_5 port


# ffcf6651 22-Feb-2007 Matt Jacob <mjacob@FreeBSD.org>

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


# 325bba15 25-Jan-2007 Matt Jacob <mjacob@FreeBSD.org>

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


# a2baed97 05-Jan-2007 Matt Jacob <mjacob@FreeBSD.org>

(commented out) multipath fault injection code.

Some code to make diffs with RELENG_6 easier.


# 05b2985d 05-Jan-2007 Matt Jacob <mjacob@FreeBSD.org>

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


# c3b65db8 16-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 5bac03f9 09-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Make mpt_pci depend on pci and mpt_cam depend on CAM.

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


# 0e0521a1 07-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# a841a816 05-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

use xpt_print function


# c5da377e 03-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# a54067cc 02-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 21167708 19-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 52c00853 16-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 757cabc3 16-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 3f970273 15-Nov-2006 John Birrell <jb@FreeBSD.org>

Add big endian support.

Submitted by: scottl
Reviewed by: mjacob


# 162eef1f 02-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# bd3fd815 01-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

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

Reviewed by multitudes.


# fa9ed865 30-Oct-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 4542a379 21-Sep-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# a7303be1 07-Sep-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# b2d24734 05-Sep-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 1dad8bb0 24-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 970043d7 16-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

Add sysctl information about things like WWNN/WWPN.

MFC after: 2 weeks


# 6621d786 15-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 73651fd1 15-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# b4c618c0 12-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 8ca01246 25-Jun-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 9fe6d254 24-Jun-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 672e707a 09-Jun-2006 Jung-uk Kim <jkim@FreeBSD.org>

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

Reviewed by: mjacob (initial version)


# fcd9a16b 05-Jun-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 5580ce96 02-Jun-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# ec5fe39d 29-May-2006 Matt Jacob <mjacob@FreeBSD.org>

Add acknowledgements to LSI-Logic for support


# 800d362b 29-May-2006 Matt Jacob <mjacob@FreeBSD.org>

+ 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.


# 1d79ca0e 27-May-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# a3116b5a 25-May-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# f6914962 03-May-2006 Matt Jacob <mjacob@FreeBSD.org>

Remove MPT_PRT_INVARIANT- it was a silly idea.


# 54302f8e 21-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

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

Found by Coverity.


# 2901a7b7 18-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

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).


# 5089bd63 11-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 5e073106 01-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# c87e3f83 25-Mar-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# a4ca1e0b 16-Mar-2006 Matt Jacob <mjacob@FreeBSD.org>

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


# 7a49a0d1 07-Mar-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 29ae59ed 28-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

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).


# 6a9fa015 26-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 8b14319c 26-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 0b80d21b 25-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# 696e0ce4 21-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

Remove commented out qualifier to dumping a message.


# 444dd2b6 10-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

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.


# f4e98881 03-Dec-2005 Ruslan Ermilov <ru@FreeBSD.org>

Fix -Wundef.


# 286e947f 03-Aug-2005 Justin T. Gibbs <gibbs@FreeBSD.org>

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


# b0a2fdee 10-Jul-2005 Scott Long <scottl@FreeBSD.org>

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