Add some more CTL_FLAG_ABORT check points.

This should allow to abort commands doing mostly disk I/O, such as VERIFY
or WRITE SAME.  Before this change CTL_FLAG_ABORT was only checked around
data moves, which for these commands may not happen for a very long time.

MFC after:	2 weeks

(cherry picked from commit 281c52cb4ab2605c738c2893bcc3cb395489dabc)
(cherry picked from commit cafabf156888ac28de751d0b6652d28e019a0fef)
Execute task management request directly in ctl_queue() context.

From one side it allows to remove CTL_FLAG_TASK_PENDING flag, handling of
which significantly complicates fine-grained locking.  From the other side
it reduces task management requests latency even below then that flag could.
As downside, it denies task management code to sleep, but that is not needed
any way now.

Discussed with:	ken

(cherry picked from commit 85412f13ad15f27a688b56995d0575b5a1063c43)
(cherry picked from commit 6bacec2c3f9600787b4f19495f44d429c8e029db)
Introduce fine-grained CTL locking to improve SMP scalability.

Split global ctl_lock, historically protecting most of CTL context:
 - remaining ctl_lock now protects lists of fronends and backends;
 - per-LUN lun_lock(s) protect LUN-specific information;
 - per-thread queue_lock(s) protect request queues.
This allows to radically reduce congestion on ctl_lock.

Create multiple worker threads, depending on number of CPUs, and assign
each LUN to one of them.  This allows to spread load between multiple CPUs,
still avoiging congestion on queues and LUNs locks.

On 40-core server, exporting 5 LUNs, each backed by gstripe of SATA SSDs,
accessed via 6 iSCSI connections, this change improves peak request rate
from 250K to 680K IOPS.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit d4f8a83dc389f588133be15ddc87f99bb4c0c448)
(cherry picked from commit 2eda9b602766060b7ae541728151e78b42c67000)
Return task management requests to queued execution, but differently.

Testing shown that both original queued design with separate task queue,
and recent direct execution design had significant flaw: If abort request
arrives just after the victim, the last one may not be in the ooa_queue
yet, and so invisible for the task management function.

Unlike original queued implementation, use same queue for all SCSI and
TASK requests from the same initiator. That avoids races between them:
task functions are always executed in proper time, relatively to other
requests.

(cherry picked from commit 3d17a2a3d2526935c300e7c4aa7ff75ef27e2d17)
(cherry picked from commit fd19571cdf1daed1aa5781195647fa7259bc593a)
Fix typo in r267873.

(cherry picked from commit 57e388ec908c0b88402d8ba6ae43b38fc2de45f4)
(cherry picked from commit d18410b601d47abb321baa4ea20ce89b8e07c12b)
Fix build on stable/9.

(cherry picked from commit 5cea952b4750c4333661cb5785fa0c942efa762d)
Lock devstat updates in block backend to make it usable.  Polish lock names.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 52ca2df2709a7a01c7947959bffdb7d10a82c926)

Conflicts:
	sys/cam/ctl/ctl_backend_block.c

(cherry picked from commit 4d712fccf84c6fb3d29fc25225a47e7193dadc73)
Add READ BUFFER and improve WRITE BUFFER SCSI commands support.

This gives some use to 512KB per-LUN buffers, allocated for Copan-specific
processor code and not used.  It allows, for example, to test transport
performance and/or correctness without accessing the media, as supported
by Linux version of sg3_utils.

MFC after:	2 weeks

(cherry picked from commit 36b6236db2d8d8fbfada389c6f96e0ca25654fdb)
(cherry picked from commit f8814a302987b6dab1aa2653bd99c4a4ee5cd023)
Allow MODE SENSE commands through Write Exclusive persistent reservation,
as required by SPC-4.

Report that fact in persistent reservation capabilities.

MFC after:	2 weeks

(cherry picked from commit 3fa0a3d2c654598d2bf79da4ab050939228972be)
(cherry picked from commit f83ce67f373475e4f044e76c3e1ed718f605f1d0)
Simplify statistics calculation.

Instead of trying to guess size of disk I/O operations (it just won't work
that way for newly added commands, and is equal to data move size for old
ones), account data move traffic.  If disk I/Os are that interesting, then
backends have to account and provide that information.

Block backend already exports the information about disk I/Os via devstat,
so having it here too is excessive.

MFC after:	2 weeks

(cherry picked from commit 3b1508e47147f9f136282646bb4b3601c7e9fd45)
(cherry picked from commit afab6c5ce12c88beacc74918467ab4ab43db8eab)
Remove odd practice of inverting error codes.

-EPERM is equal to ERESTART, returning which from ioctl() handler causes
infinite syscall restart.

MFC after:	2 weeks

(cherry picked from commit be666c404b45c8ce1578da921898d27fa32a0d61)
(cherry picked from commit 0eb15dd7d2c5e0633e39a2eeec844f266d6492d4)
Use separate memory type M_CTLIO for I/Os.

CTL allocate large amount of RAM.  This change give some more stats.

MFC after:	2 weeks

(cherry picked from commit 83d76f3c4680ca1225c7fd224c1b8ec4ab052b34)
(cherry picked from commit e265ecca26c6b4fbdd238de4e308839465c356d1)
Improve readability of XML generated by CTL_LUN_LIST.

(cherry picked from commit 1aa291ed887e10585424013a2e6ff0e16175ca01)
(cherry picked from commit bb680f3adbc1e3e02218c5c4042e3807df6ca13a)
Do not return statuses for aborted iSCSI commands.

(cherry picked from commit a19a69842c309579c66ef5fa8db053d307ae02df)
(cherry picked from commit ac7c18594b33cd494b9083531505a433f8c1a749)
Fix use-after-free on XPT_RESET_BUS.

That command is not queued, so does not use later status update.

(cherry picked from commit 6c91ce3da6785fed69c0921688da0225da95732d)
(cherry picked from commit 735a155d43a4dbb7877a2ea7d1a0f3eb28f9a4c4)
Fix build on stable/9.

(cherry picked from commit 6da4673cc093b2183c472709d7293eaaba2df8e5)
Add more formal and strict command parsing and validation.

For every supported command define CDB length and mask of bits that are
allowed to be set.  This allows to remove bunch of checks through the code
and still make the validation more strict.  To properly do it for commands
supporting multiple service actions, formalize their parsing by adding
subtables for each of such commands.

As visible effect, this change allows to add support for REPORT SUPPORTED
OPERATION CODES command, reporting to client all the data about supported
SCSI commands, except timeouts.

MFC after:	2 weeks

(cherry picked from commit 68790c55907cfefd2306c307bf84d7dc526ad163)
(cherry picked from commit b0f9e1407f0a2496e87581befb0cc6129c79ef31)
Add support for REPORT TIMESTAMP command.

MFC after:	2 weeks

(cherry picked from commit 7eb84da710650ecb94d95025618eff013d32a6f3)
(cherry picked from commit d0403d0e4f7a1e66f9f1e056d5e6dc8797647b8e)
Remove targ_enable()/targ_disable() frontend methods.

Those methods were never implemented, and I believe that their concept is
wrong, since single frontend (SCSI port) can not handle several targets.

(cherry picked from commit c9aabd0ff96f0a2797a5bf64144a2ad160e620c6)
(cherry picked from commit 08a93463845a3ca6d6a4cfeea6e62574333969eb)
Separate concepts of frontend and port.

Before iSCSI implementation CTL had no knowledge about frontend drivers,
it had only frontends, which really were ports (alike to LUNs, if comparing
to backends).  But iSCSI added there ioctl() method, which does not belong
to frontend as a port, but belongs to a frontend driver.

(cherry picked from commit 43424a09728bc2c362d6899b02a1a0587326ef29)

Conflicts:
	sys/cam/ctl/scsi_ctl.c

(cherry picked from commit d991333889b565afabc4887c6d2c0514ed199f06)