freebsd-skq/sys/dev/mpr
ken 4a13a1ae21 Changes to make mps(4) and mpr(4) handle reinit with reallocation.
When the mps(4) and mpr(4) drivers need to reinitialize the
firmware, they sometimes need to reallocate all of the memory
allocated by the driver.  The reallocation happens whenever the IOC
Facts change.  That should only happen after a firmware upgrade.

If the reinitialization happens as a result of a timed out command
sent to the card, the command that timed out and triggered the
reinit may have been freed if iocfacts_allocate() reallocated all
memory.  If the caller attempts to access the command after that,
the kernel will panic because the caller will be dereferencing
freed memory.

The solution is to set a flag in the softc when we reallocate,
and avoid dereferencing the command strucure if we've reallocated.

The changes are largely the same in both drivers, since mpr(4) is a
derivative of mps(4).

 o In iocfacts_allocate(), if the IOC Facts have changed and we
   need to reallocate, set the REALLOCATED flag in the softc.

 o Change wait_command() to take a struct mps_command ** instead of
   a struct mps_command *.  This allows us to NULL out the caller's
   command pointer if we have to reinit the controller and the data
   structures get reallocated.  (The REALLOCATED flag will be set
   in the softc if that has happened.)

 o In every place that calls wait_command(), make sure we handle
   the case where the command is NULL after the call.

 o The mpr(4) driver has mpr_request_polled() which can also
   reinitialize the card.  Also check for reallocation there.

Reviewed by:	scottl, slm
MFC after:	1 week
Sponsored by:	Spectra Logic
2017-08-10 14:59:17 +00:00
..
mpi Add tri-mode support (SAS/SATA/PCIe). 2017-05-17 21:33:37 +00:00
mpr_config.c Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00
mpr_ioctl.h Several style changes and add copyrights for 2016. 2016-05-09 16:16:00 +00:00
mpr_mapping.c Fix several problems with mapping code. 2017-05-25 19:20:06 +00:00
mpr_mapping.h Add tri-mode support (SAS/SATA/PCIe). 2017-05-17 21:33:37 +00:00
mpr_pci.c Fix a logic bug in the split PCI interrupt code that slipped through 2017-07-31 16:55:56 +00:00
mpr_sas_lsi.c Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00
mpr_sas.c Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00
mpr_sas.h Add tri-mode support (SAS/SATA/PCIe). 2017-05-17 21:33:37 +00:00
mpr_table.c Change from using underbar function names to normal function names for 2017-07-30 22:34:24 +00:00
mpr_table.h Change from using underbar function names to normal function names for 2017-07-30 22:34:24 +00:00
mpr_user.c Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00
mpr.c Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00
mprvar.h Changes to make mps(4) and mpr(4) handle reinit with reallocation. 2017-08-10 14:59:17 +00:00