MFC r249981:
Remove ADA_FLAG_PACK_INVALID flag. Since ATA disks have no concept of media
change it only duplicates CAM_PERIPH_INVALID flag, so we can use last one.

Slightly cleanup DA_FLAG_PACK_INVALID use.

(cherry picked from commit 5cdd91fa7059241efc1abaa246019b0d29963220)
MFC r253752:
Fix returning incorrect bio_resid value with failed BIO_DELETE requests.
Neither residual length reported for ATA/SCSI command nor one from another
BIO_DELETE request are in any way related to the value to be returned.

(cherry picked from commit 0d8d3361c0c23999f39ae504544b18940f2d3aa2)
MFC r254329 (by smh):
Added 4K quirks for:-
* OCZ Agility 2 SSDs
* Marvell SSDs
* Intel X25-M Series SSDs

(cherry picked from commit b5e19728de7b316946121f13e0e29413eb16f4c6)
MFC r256836:
Remove hard limit on number of BIOs handled with one ATA TRIM request.

(cherry picked from commit e80894dbb55bbb5a2c1a727b0a5f63aa558919f0)
MFC r257054:
Some microoptimizations for da and ada drivers:
 - Replace ordered_tag_count counter with single flag;
 - From da remove outstanding_cmds counter, duplicating pending_ccbs list;
 - From da_softc remove unused links field.

(cherry picked from commit dbd6a194bff45295cf0d8802dddf89ac601829c3)
MFC r249466, r249481, r250025:
Remove multilevel freezing mechanism, implemented to handle specifics of
the ATA/SATA error recovery, when post-reset recovery commands should be
allocated when queues are already full of payload requests.  Instead of
removing frozen CCBs with specified range of priorities from the queue
to provide free openings, use simple hack, allowing explicit CCBs over-
allocation for requests with priority higher (numerically lower) then
CAM_PRIORITY_OOB threshold.

Simplify CCB allocation logic by removing SIM-level allocation queue.
After that SIM-level queue manages only CCBs execution, while allocation
logic is localized within each single device.

(cherry picked from commit 8ccbee2edf83fac8f0acf8f76c6848641bd27bce)
MFC r249438:
Use full freeze while PMP does hard reset. This is only cosmetical change.

(cherry picked from commit 3bda598ca61a45abb2b4b640dd4eb9c4d8dc5267)
MFC r253958:
Change CCB queue resize logic to be able safely handle overallocations:
 - (re)allocate queue space in power of 2 chunks with 64 elements minimum
and never shrink it; with only 4/8 bytes per element size is insignificant.
 - automatically reallocate the queue to double size if it is overflowed.
 - if queue reallocation failed, store extra CCBs in unsorted TAILQ,
fetching them back as soon as some queue element is freed.

To free space in CCB for TAILQ linking, change highpowerq from keeping
high-power CCBs to keeping devices frozen due to high-power CCBs.

This encloses all pieces of queue resize logic inside of cam_queue.[ch],
removing some not obvious duties from xpt_release_ccb().

(cherry picked from commit a53cdc73b54c41ac4f73b39125b61ac7e4d1b796)
MFC r249008 (by trasz):
Fix panic in the error path caused by recursive acquisition of XPT topology
lock.

(cherry picked from commit f67a506d663c8c8fa456d0e1e5f2c95ef51d37d0)
MFC r255126:
Add debug trace points for freeze/release device queue.

(cherry picked from commit fc66273e37874bedb476e767ae8ab93d6b6865ce)
MFC r254058:
Remove droping topology mutex after iterating 100 periphs in CAMGETPASSTHRU.
That is not so slow and so often operation to handle unneeded otherwise
xsoftc.xpt_generation and respective locking complications.

(cherry picked from commit 551f97b8c54b1f63b457ff3274ac6984f61e1965)
MFC r256895:
Fix memory and references leak due to unfreed path.

(cherry picked from commit d4677a01d7137b77d99587879c1301bb269e962d)
MFC r253323:
When printing opcode description, map T_NODEVICE to Direct Access Device to
handle REPORT LUNS, etc.

(cherry picked from commit 32ca544e3e78da45551af2b1bd8d225d07ffd011)
MFC r254970 (by ken):
If a drive returns ASC/ASCQ 0x04,0x11 "Logical unit not ready,
notify (enable spinup) required", instead of doing the normal
retries, poll for a change in status.

We will poll every half second for a minute for the status to
change.

Hitachi drives (and likely other SAS drives) return that ASC/ASCQ
when they are waiting to spin up.  What it means is that they are
waiting for the SAS expander to send them the SAS
NOTIFY (ENABLE SPINUP) primitive.

That primitive is the mechanism expanders/enclosures use to
sequence drive spinup to avoid overloading power supplies.

(cherry picked from commit 3857b0c8aaf567cd56c38e78f841a889998e4b6b)
MFC r250208:
Tune support for removable media in da driver:
 - remove DA_FLAG_SAW_MEDIA flag, almost opposite to DA_FLAG_PACK_INVALID,
using the last instead.
 - allow opening device with no media present, reporting zero media size
and non-zero sector size, as geom/notes suggests.  That allow to read
device attributes and potentially do other things, not related to media.

(cherry picked from commit 3463601f88bcf4d5913be73c7acd12edf4e9f5e2)
MFC r255307 (by bryanv):
Add camcontrol support for the SCSI sanitize command

(cherry picked from commit 8df04f51851223ab1517a115474676f287a955ef)
MFC r255119:
Fix SES_ENABLE_PASSTHROUGH kernel option, unexpectedly broken during driver
overhaul.

(cherry picked from commit d9c28379c5ee75e2c35c93e362197a4c97fe3740)
MFC r255304:
Fix kernel panic if cache->nelms is zero.

(cherry picked from commit 09d6aad1e5f411bff3b8fc33370e76a61c2c6ce4)
MFC r255309:
Make SES driver adequately react on simple enclosure devices -- read Short
Enclosure status to enclosure status field, clear previous state and exit.

(cherry picked from commit a3c529c7b904fab4b36c99f821586ee86e7720d5)
MFC r255118:
Fix targbh crash on XPT_IMMED_NOTIFY error during attach.

(cherry picked from commit 39b96f9ededb5716cf2fdfded375ad7fec9b4baa)