Commit Graph

2192 Commits

Author SHA1 Message Date
Warner Losh
045f8bc8e4 When we crash, we'll stop the scheduler before we call the
shutdown_post_sync event.  For adashutdown, this causes problems
because we need to poll for completion of the commands, but we're not
yet officially dumping yet, so the code from r326964 assumed we could
use the interrupt-driven commands rather than the polled ones. This
lead to a hang. Prevent this by also checking to see if the scheduler
is stopped to do the polling.

Reported by: markj@
Sponsored by: Netflix
Differential Review: https://reviews.freebsd.org/D13845
2018-01-11 03:11:41 +00:00
Scott Long
876f6a6af2 Release the held refcount on the probe periph when probing is
done, now that r327741 lets this happen.

Obtained from:	Netflix
2018-01-09 21:24:05 +00:00
Scott Long
7c1374d5f5 Hold a refcount on the periph while running the allocation
queue.  This will allow sub-transports to release their
probe pseudo-device with fewer convoluted restrictions.

Obtained from:	Netflix
2018-01-09 21:23:16 +00:00
Warner Losh
9c5a114886 Remove ccbque.h from i386/isa.
inline ccbque.h into scsi_low.h. The file isn't MD, so shouldn't live
in i386/isa. It's only used by scsi_low, so move it there so no new
clients accidentally grow. scsi_low may not even still work, and the
locking here is still SPL based. CAM should do the right thing, but
I've received no reports of these cards still working. At least it
compiles still and there's one fewer files in sys/i386/isa. While I'm
here, ansify and de-splize. CCB_MWANTED appears to be a clear-only
flag, but I've not changed that.

Differential Review: https://reviews.freebsd.org/D13672
2018-01-09 16:11:33 +00:00
Scott Long
bff0b56cdf Don't hold the periph locks during dump.
Obtained from:	Netflix
2018-01-09 00:17:15 +00:00
Scott Long
04e814aecd Don't hold the periph lock when calling into cam_periph_runccb()
from the ada and da dump routines.  This avoids difficult locking
problems from needing to be handled.  While it might seem like this
would leave the periphs unprotected during dump, they were aleady
at risk of unexpected removal due to the dump functions not
keeping refcount state across the many calls that come in during
a dump.  This is an exercise for future work.

Obtained from:	Netflix
2018-01-09 00:10:59 +00:00
Scott Long
329e7a8b51 Protect against a possible NULL deference from an accessor
function.

Obtained from:	Netflix
2018-01-09 00:00:55 +00:00
Eitan Adler
d734a3dfcd cam/da: QUIRK: Add 4K quirks for WD Red and Black MHDDs
PR:		188685
Submitted by:	Jeremy Chadwick <jdc@koitsu.org>
Reported by:	Martin Birgmeier <d8zNeCFG@aon.at>
2018-01-05 07:14:39 +00:00
Emmanuel Vadot
8e3f1dcf54 ctl: Correct comment in ctl_worker_thread
The incoming queue is handled before the RtR one.
No functional change.

MFC after:	3 days
2017-12-27 15:39:31 +00:00
Alexander Kabaev
151ba7933a Do pass removing some write-only variables from the kernel.
This reduces noise when kernel is compiled by newer GCC versions,
such as one used by external toolchain ports.

Reviewed by: kib, andrew(sys/arm and sys/arm64), emaste(partial), erj(partial)
Reviewed by: jhb (sys/dev/pci/* sys/kern/vfs_aio.c and sys/kern/kern_synch.c)
Differential Revision: https://reviews.freebsd.org/D10385
2017-12-25 04:48:39 +00:00
Warner Losh
4484c8f5d2 Return domain, bus, slot, and function for the transport settings in
PATH_INQ requests for nvme.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13546
2017-12-20 19:13:55 +00:00
Warner Losh
5cf3cd108f When doing a dump, the scheduler is normally not running, so this
changed worked to capture dumps for me. However, the test for
SCHEDULER_STOPPED() isn't right. We can also call the dump routine
from ddb, in which case the scheduler is still running. This leads to
an assertion panic that we're sleeping when we shouldn't. Instead, use
the proper test for dumping or not. This brings us in line with other
places that do special things while we're doing polled I/O like this.

Noticed by: pho@
Differential Revision: https://reviews.freebsd.org/D13531
2017-12-19 04:13:22 +00:00
Alexander Motin
4d4709520a Reduce size of several on-stack string buffers.
Submitted by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after:	2 weeks
2017-12-13 21:17:00 +00:00
Warner Losh
05972baf11 Use ataio ccb instead of general ccb to avoid excessice stack usage. 2017-12-13 07:07:27 +00:00
Warner Losh
762a7f4f5f Define xpt_path_inq.
This provides a nice wrarpper around the XPT_PATH_INQ ccb creation and
calling.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13387
2017-12-06 23:05:22 +00:00
Warner Losh
2b31251a64 Now that cam_periph_runccb() can be called from situations where the
kernel scheduler is stopped, replace the by hand calling of
xpt_polled_action() with it.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13388
2017-12-06 23:05:15 +00:00
Warner Losh
f93a843cd2 Make cam_periph_runccb be safe to call when we can only do polling.
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13388
2017-12-06 23:05:07 +00:00
Alan Somers
99ae1d3b25 cam: fix sign-extension error in adagetparams
adagetparams contains a sign-extension error that will cause the sector
count to be incorrectly calculated for ATA disks of >=1TiB that still use
CHS addressing. Disks using LBA48 addressing are unaffected.

Reported by:	Coverity
CID:		1007296
Reviewed by:	ken
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D13198
2017-12-06 17:01:25 +00:00
Warner Losh
553484ae07 Remove unused 4th argument to match the standard error routines.
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13386
2017-12-06 00:29:50 +00:00
Warner Losh
d2f3208dda Add NVME as a known device type for devstat processing.
Also, reduce the amount of cut and pasted code a little since only two
args are different in the devstat_end_transaction calls.

Sponsored by: Netflix
2017-12-06 00:29:43 +00:00
Warner Losh
b836edd8b8 Remove stray cam_periph_async call. It's called twice this way. While
currently harmless for AC_UNIT_ATTENTION event (cam_periph_async does
nothing with them), it's still in error because if it were to start in
the future, it would be done twice.

Sponsored by: Netflix
2017-12-05 23:02:31 +00:00
Pedro F. Giffuni
bec9534d1d sys/cam: 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.
2017-11-27 15:12:43 +00:00
Alan Somers
b0f662fed3 Always null-terminate CAM periph_name and dev_name
Reported by:	Coverity
CID:		1010039, 1010040, 1010041, 1010043
Reviewed by:	ken, imp
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D13194
2017-11-22 19:57:34 +00:00
Alan Somers
e7dda951a4 Fix uninitialized variable from 326034
Reported by:	Coverity
CID:		1382887
MFC after:	20 days
X-MFC-With:	326034
Sponsored by:	Spectra Logic Corp
2017-11-21 16:38:30 +00:00
Alan Somers
a4557b0509 Quirk Seagate ST8000AS0003-2HH
Like its predecessor ST8000AS0002, this is a drive-managed SMR drive, but
doesn't declare that in its ATA identify data.

MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-11-20 23:45:42 +00:00
Alan Somers
c95dc95b35 da(4): Short-circuit unnecessary BIO_FLUSH commands
sys/cam/scsi/scsi_da.c
	Complete BIO_FLUSH commands immediately if the da(4) device hasn't
	been written to since the last flush. If we haven't written to the
	device, there is no reason to send a flush.

Submitted by:	gibbs
Reviewed by:	imp
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D13106
2017-11-20 22:27:33 +00:00
Alan Somers
8a0a413e12 Fix multiple bugs in cam_strmatch
* Wrongly matches strings that are shorter than the pattern
* Fails to match negative character sets
* Fails to match character sets that aren't at the end of the pattern
* Fails to match character ranges

Reviewed by:	imp
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D13173
2017-11-20 22:01:45 +00:00
Alan Somers
1a69c11aab Add assertion in probedone() that we're holding the device lock.
Submitted by:	ken
Reviewed by:	asomers
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-11-17 20:53:52 +00:00
Alan Somers
602740b689 Fix potential NULL pointer dereference of device physical path
In scsi_dev_advinfo(), if the physical path is being stored and there is a
malloc failure (malloc(9) is called with M_NOWAIT), we could wind up in a
situation where the device's physpath_len is set to the length the user
provided, but the physpath itself is NULL.

If another context then comes in to fetch the physical path value, we would
wind up trying to memcpy a NULL pointer into the caller's buffer.

So, set the physpath_len to 0 when we free the physpath on entry into the
store case for the physical path.  Reset the length to a non-zero value only
after we've successfully malloced a buffer to hold it.

Submitted by:	ken
Reviewed by:	asomers
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-11-17 17:13:00 +00:00
Baptiste Daroussin
16f92ad234 Add some 4k quirks for Samsung pm863a SSDs
Submitted by:	Nikita Kozlov <nikita.kozlov at blade-group.com>
MFC after:	3 days
Sponsored by:	blade
Differential Revision:	https://reviews.freebsd.org/D13093
2017-11-16 10:15:17 +00:00
Alan Somers
30083240bc Remove a double free(9) in xpt_bus_register
In xpt_bus_register(), remove superfluous call to free().  This was mostly
benign since free(9) checks for NULL before doing anything, and
xpt_create_path() is nice enough to NULL out the pointer on failure.
However, it could've segfaulted if malloc(9) failed during
xpt_create_path().

Submitted by:	gibbs
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-11-15 15:52:06 +00:00
Warner Losh
5e8a39f6ab Properly decode NVMe state of the drive and print out the information
in the attach to more closely match what SCSI and ATA attached
storage provides.

Sponsored by: Netflix
2017-11-14 05:05:26 +00:00
Warner Losh
4e3b274457 Provide link speed data in XPT_GET_TRAN_SETTINGS. Provide full version
information for that and XPT_PATH_INQ. Provide macros to encode/decode
major/minor versions.  Read the link speed and lane count to compute
the base_transfer_speed for XPT_PATH_INQ.

Sponsored by: Netflix
2017-11-14 05:05:16 +00:00
Emmanuel Vadot
530fdf6771 ctl: Make max_luns and max_ports tunable variables instead of hardcoded
defines.

Reviewed by:	trasz (earlier version), bapt (earlier version), bcr (manpages)
MFC after:	2 Weeks
Sponsored by:	Gandi.net
Differential Revision:	https://reviews.freebsd.org/D12836
2017-11-07 16:59:52 +00:00
Warner Losh
50ee2e2aab Send IDLE IMMEDIATE for warm boot.
We must send either an IDLE IMMEDIATE or a STANDBY IMMEDIATE to drives
on warm boot so their SMART and other volatile data is
persisted. However, for a warm boot we don't want to send STANDBY
IMMEDIATE to some spinning drives because they will spin down. If
there's a lot of these drives on the system, that can cause a
thundering herd problem at startup time (that in extreme cases causes
timeout in device discovery).

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D12811
2017-10-30 03:25:22 +00:00
Warner Losh
712ad71996 nvd alias has caused some problems, revert it for the moment.
Sponsored by: Netflix
2017-10-27 14:57:38 +00:00
Warner Losh
c136b6ecee We should be call adaerror() instead of cam_periph_error() always.
Sponsored by: Netflix
2017-10-26 22:53:55 +00:00
Warner Losh
f902366c48 Always send STANDBY IMMEDIATE when shutting down
To save SMART data and for a drive to understand that it's been nicely
shutdown, we need to send a STANDBY IMMEDIATE. Modify adaspindown to
use a local CCB on the stack. When we're panicing, used
xpt_polled_action rather than cam_periph_runccb so that we can SEND
IMMEDIATE after we've shutdown the scheduler.

Sponsored by: Netflix
Reviewed by: scottl@, gallatin@
Differential Revision: https://reviews.freebsd.org/D12799
2017-10-26 22:53:49 +00:00
Warner Losh
6a9fbe3a70 Handle RB_POWERCYCLE in ada driver
Allow the disks to be spun down when doing a POWERCYCLE as well as
POWEROFF.

Sponsored by: Netflix
2017-10-25 15:30:48 +00:00
Warner Losh
6ca2fb6623 Treat a 'current' value of 0 as unlimited as a failsfe.
When limiting I/O, a value of 0 makes no sense as a limit. No progress
can be made. Trade the possibility that someone might be doing
something clever to achieve ultra-low I/O limits vs the damage of not
ever making progress on an I/O in favor of making progress. Now the
machine won't be useless if this accidentally gets requested.

Sponsored by: Netflix
2017-10-24 02:25:42 +00:00
Warner Losh
1f88be2d3a Zero out the ccb's alloated on the stack for the dump routines to more
closely match a ccb returned from xpt_get_ccb().

Sponsored by: Netflix
2017-10-15 23:54:04 +00:00
Warner Losh
fa271a5d09 Closer examination shows that nvme and CAM both normally zero-fill
allocations (for req and ccb, which ultimately contain the
nvme_cmd). As such, we can micro-optimize these routines. Add a
comment to this effect, and bzero the ccb used to make the requests
for the nda dump rotuine so it more closely matches a ccb allocated
with xpt_get_ccb().

Sponsored by: Netflix
2017-10-15 23:53:55 +00:00
Warner Losh
c4231018d0 Be nicer on the dump stack by allocating only a ccb_nvmeio rather than
a full ccb. This saves a few hundre bytes, which might be important
during a crash dump...

Sponsored by: Netflix
Suggested by: scottl@
2017-10-15 16:18:03 +00:00
Warner Losh
717bff5d85 Update comment to reflect actual default timeout.
Sponsored by: Netflix
2017-10-15 16:17:55 +00:00
Edward Tomasz Napierala
5b4bc31eee Fix iSCSI target panics on concurrent session teardown and display
(eg removing a target and doing "ctladm islist -v" at the same time).

Reviewed by:	manu
Tested by:	manu
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-10-04 11:35:04 +00:00
Alexander Motin
748f120f7c Add sysctl/tunable for maximal request time.
MFC after:	1 week
2017-09-30 13:17:31 +00:00
Warner Losh
78ed811e6c cam iosched: Bettar account IOPS for smoother performance
Prevent cam_iosched_iops_tick() from discarding 'unspent' ios unless
it's a new accounting interval.

Previously ios that weren't used between ticks were lost, as a result
the iops limiter could enforce a limit below the configured maximum.

Obtained from: ElectroBSD
Submitted by: Fabian Keil
PR: 221974
2017-09-22 02:36:36 +00:00
Warner Losh
f777123b83 cam iosched: Enforce iop limits below the quanta value
Previously the iops limiter would always allow at least
quanta ios per second as cam_iosched_iops_tick() never set
ios->l_value1 below 1.

Submitted by: Fabian Keil <fk@fabiankeil.de>
Obtained from: ElectroBSD
PR: 221974
2017-09-22 02:36:32 +00:00
Jung-uk Kim
8c294161aa Remove an ancient comment about the existence of READ(16) and WRITE(16).
MFC after:	3 days
2017-09-21 00:03:59 +00:00
Warner Losh
89d26636f3 cam iosched: Call cam_iosched_limiter_init() after ios->current is set to the default
Previously ios->current was set to 0 until the first
cam_iosched_cl_maybe_steer() call.

PR: 221954
Obtained from: ElectroBSD
Submitted by: Fabian Keil
Differential Revision: https://reviews.freebsd.org/D12349
2017-09-20 21:26:01 +00:00
Warner Losh
3028dd8dd5 cam iosched: Schedule cam_iosched_ticker() quanta times per second
Previously callout_reset() was called with a "ticks" value that was
off by one.  As a result cam_iosched_ticker() was called a bit too
frequently: On systems with hz=1000 a quanta value of 200 resulted in
~250 calls and a value of 100 in ~111 calls.

For the "queue_depth" and "bandwidth" limiters the difference doesn't
matter but the "iops" limiter depends on the scheduling to enforce the
correct maximum.

PR: 221956
Obtained from: ElectroBSD
Submitted by: Fabian Keil
Differential Revision: https://reviews.freebsd.org/D12350
2017-09-20 21:25:56 +00:00
Warner Losh
2d22619adc cam iosched: Add a handler for the quanta sysctl to enforce valid values
Invalid values can result in devision-by-zero panics or other
undefined behaviour so lets not allow them.

PR: 221957
Obtained from: ElectroBSD
Submitted by: Fabian Keil
Differential Revision: https://reviews.freebsd.org/D12351
2017-09-20 21:19:53 +00:00
Warner Losh
84c12dcdd0 cam iosched: Use the write queue for BIO_ZONE commands
Use the write queue for BIO_ZONE commands so they can't get executed
ahead of writes that were sent after them. More generally, since they
introduce strong ordering into the list, they need to go to the write
queue (which is the only queue that BIO_ORDERED is honored for at the
moment). In fact, fix mismatch between queueing and dequeueing code by
changing this to queue all non-reads (and non-trims) to the write
queue.

As a side effect this prevents the kernel message:
kernel: Found bio_cmd = 0x9
which cam_iosched_next_bio() emits when finding commands
other than BIO_READ in the read queue.

PR: 221973
Obtained from: ElectroBSD
Submitted by: Fabian Keil
Differential Revision: https://reviews.freebsd.org/D12353
2017-09-20 21:13:20 +00:00
Ilya Bakulin
ffa317051b Add kern.features flag for MMCCAM
kern.features.mmcam will be present and equal to 1 if the kernel has been
compiled with option MMCCAM.
This will help sdio-related userland tools to fail-fast if running on the kernel
without MMCCAM enabled.

Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D12386
2017-09-18 20:17:08 +00:00
Warner Losh
851063e16a Allow multiple TRIMs to be done for nda
Don't call cam_iosched_trim_done or cam_iosched_submit_trim for nda
since its hardware can handle almost an arbitrary number of TRIMs and
we don't have to be careful to only ever do one.

Sponsored by: Netflix
2017-09-15 20:16:06 +00:00
Warner Losh
55c770b40a Update comments on what the CAM_IOSCHED_FLAG_TRIM_ACTIVE means.
It's intended only for those situations where the periph driver
ones to limit the number of trims active to one and only one.
Also update comments on associated functions.

Sponsored by: Netflix
2017-09-15 20:15:55 +00:00
Ilya Bakulin
02c474b481 Miscellaneous fixes and improvements to MMCCAM stack
* Demote the level of several debug messages to CAM_DEBUG_TRACE
 * Add detection for SDHC cards that can do 1.8V. No voltage switch sequence
   is issued yet;
 * Don't create a separate LUN for each SDIO function. We need just one to make
   pass(4) attach;
 * Remove obsolete mmc_sdio* files. SDIO functionality will be moved into the
   separate device that will manage a new sdio(4) bus;
 * Terminate probing if got no reply to CMD0;
 * Make bcm2835 SDHCI host controller driver compile with 'option MMCCAM'.

Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D12109
2017-09-15 19:47:44 +00:00
Warner Losh
d7fa1ab02d cam iosched: Limit the quanta default to hz if it's below 200
The cam_iosched_ticker() can't be scheduled more than once per tick.
Some limiters depend on quanta matching the number of calls per second
to enforce the proper limits. Limit the quanta to no faster than 1 per
clock tick. This fixes some features when running in VMs where the
default HZ is 100.

PR: 221953
Obtained from: ElectroBSD
Differential Revision: https://reviews.freebsd.org/D12337
Submitted by: Fabian Keil
2017-09-12 23:46:33 +00:00
Alan Somers
71cd87c66c Remove spaces from CTL devices' default serial numbers
It's awkward to have spaces in CAM device serial numbers. That leads to
such things as device nodes named "/dev/diskid/MYSERIAL%20%20%201". Better
to replace the spaces with "0"s. This change only affects the default
serial numbers for users who don't provide their own.

Reviewed by:	ken, mav
MFC after:	Never
Relnotes:	Yes
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D12263
2017-09-12 19:36:24 +00:00
Conrad Meyer
b1631dfb46 cam(4): Fix some warnings
When bcopy is treated as memcpy/memmove, Clang produces warnings that the
size argument doesn't match the type of the source.  This is true, it
doesn't match; we're aliasing the source.

Explicitly cast the source pointer to the expected type to remove the
warning.

No functional change.

Sponsored by:	Dell EMC Isilon
2017-09-07 07:24:22 +00:00
Warner Losh
a3cf03a519 Add missing test for NVME CCBs for nvme passthru support.
Submitted by: Chuck Tuffli
2017-08-29 21:04:29 +00:00
Warner Losh
9f8ed7e40b Fix NVMe's use of XPT_GDEV_TYPE
This patch changes the way XPT_GDEV_TYPE works for NVMe. The current
ccb_getdev structure includes pointers to the NVMe Identify Controller
and Namespace structures, but these are kernel virtual addresses which
are not accessible from user space.

As an alternative, the patch changes the pointers into padding in
ccb_getdev and adds two new types to ccb_dev_advinfo to retrieve the
Identify Controller (CDAI_TYPE_NVME_CNTRL) and Namespace
(CDAI_TYPE_NVME_NS) data structures.

Reviewed By: rpokala, imp
Differential Revision: https://reviews.freebsd.org/D10466
Submitted by: Chuck Tuffli
2017-08-29 17:03:30 +00:00
Warner Losh
c2005bba77 Fix a few overlooked spots where the coded uses 16-bit NSIDs. Chuck
Tuffli had submitted a more thorough patch that I was unaware of when
I did my work and this brings in the bits I missed from that patch.

PR: 220267
Submitted by: Chuck Tuffli
2017-08-29 15:46:34 +00:00
Warner Losh
519772814d Add CAM/NVMe support for CAM_DATA_SG
This adds support in pass(4) for data to be described with a
scatter-gather list (sglist) to augment the existing (single) virtual
address.

Differential Revision: https://reviews.freebsd.org/D11361
Submitted by: Chuck Tuffli
Reviewed by: imp@, scottl@, kenm@
2017-08-29 15:29:57 +00:00
Warner Losh
9754579b01 Add comment about where we need to place this routine, and why.
Sponsored by: Netflix
2017-08-28 19:27:33 +00:00
Warner Losh
43effc8ca8 Add comment about where we need to place this routine, and why.
Sponsored by: Netflix
2017-08-28 19:25:49 +00:00
Warner Losh
08fc2f23b3 Expand the latency tracking array from 1.024s to 8.192s to help track
extreme outliers from dodgy drives. Adjust comments to reflect this,
and make sure that the number of latency buckets match in the two
places where it matters.
2017-08-24 22:11:10 +00:00
Warner Losh
e4c9cba71f Fix 32-bit overflow on latency measurements
o Allow I/O scheduler to gather times on 32-bit systems. We do this by shifting
  the sbintime_t over by 8 bits and truncating to 32-bits. This gives us 8.24
  time. This is sufficient both in range (256 seconds is about 128x what current
  users need) and precision (60ns easily meets the 1ms smallest bucket size
  measurements). 64-bit systems are unchanged. Centralize all the time math so
  it's easy to tweak tha range / precision tradeoffs in the future.
o While I'm here, the I/O scheduler should be using periph_data rather than
  sim_data since it is operating on behalf of the periph.

Differential Review: https://reviews.freebsd.org/D12119
2017-08-24 22:10:58 +00:00
Ed Maste
0b4060b073 cam iosched: fix typos in comments
PR:		220947
Submitted by:	Fabian Keil
Obtained from:	ElectroBSD
2017-08-18 16:38:33 +00:00
Alexander Motin
c901a9b1f1 Do not loose CCB flags after r320493.
There is at least CAM_UNLOCKED that should be kept.

MFC after:	3 days
2017-08-09 09:13:15 +00:00
Warner Losh
d45e16744f Add nvd alias to nda ndoes.
All ndaX and ndaXpY nodes will appear as nvdX and nvdXpY as well
(through symlinks in devfs via the normal disk aliasing mechanism in
GEOM).

Differential Revision: https://reviews.freebsd.org/D11873
2017-08-07 21:12:43 +00:00
Alexander Motin
1d9aaa862b adaasync(): Set ADA_STATE_WCACHE based on ADA_FLAG_CAN_WCACHE
The attached patch lets adaasync() set ADA_STATE_WCACHE based on
ADA_FLAG_CAN_WCACHE instead of ADA_FLAG_CAN_RAHEAD.

This fixes a regression introduced in r300207 which changed
the flag names.

PR:		220948
Submitted by:	Fabian Keil <fk@fabiankeil.de>
Obtained from:	ElectroBSD
MFC after:	1 week
2017-07-27 07:28:29 +00:00
Warner Losh
df4245150a This adds CAM pass(4) support for NVMe IO's. Applications indicate
the IO type (Admin or NVM) using XPT op-codes XPT_NVME_ADMIN or
XPT_NVME_IO.

Submitted by:   Chuck Tuffli <chuck@tuffli.net>
Differential Revision:  https://reviews.freebsd.org/D10247
2017-07-14 14:52:20 +00:00
Sean Bruno
d03ae351ed Add 4k and NCQ_TRIM_BROKEN quirks for Samsung 845 SSDs.
Submitted by:	 hannula@gmail.com
Differential Revision:	https://reviews.freebsd.org/D7967
2017-07-13 16:56:26 +00:00
Sean Bruno
989e632aa7 Add 4K quirks for Samsung 750 EVO SSD
Submitted by:	lev
Reviewed by:	mav
Differential Revision:	https://reviews.freebsd.org/D9478
2017-07-13 15:33:08 +00:00
Warner Losh
9f74b6d90a Move mmc_parmas to the end of the structure for better compatability. 2017-07-10 21:55:19 +00:00
Warner Losh
4fccee4f22 Kill some unnecessary noise. 2017-07-10 21:38:26 +00:00
Warner Losh
4e38d89520 Include opt files in the kernel with "" instead of <>. 2017-07-10 05:08:01 +00:00
Warner Losh
6df06cd671 Opt files are included with single quotes. 2017-07-10 03:38:12 +00:00
Warner Losh
a94a63f0a6 An MMC/SD/SDIO stack using CAM
Implement the MMC/SD/SDIO protocol within a CAM framework. CAM's
flexible queueing will make it easier to write non-storage drivers
than the legacy stack. SDIO drivers from both the kernel and as
userland daemons are possible, though much of that functionality will
come later.

Some of the CAM integration isn't complete (there are sleeps in the
device probe state machine, for example), but those minor issues can
be improved in-tree more easily than out of tree and shouldn't gate
progress on other fronts. Appologies to reviews if specific items
have been overlooked.

Submitted by: Ilya Bakulin
Reviewed by: emaste, imp, mav, adrian, ian
Differential Review: https://reviews.freebsd.org/D4761

merge with first commit, various compile hacks.
2017-07-09 16:57:24 +00:00
Ed Maste
8fadf6a637 cam: EOL whitespace cleanup and line wrapping changes
NFC. This cleanup simplifies diffs for review of the MMC-CAM work.

Submitted by:	kibab
2017-07-04 18:48:08 +00:00
Alexander Motin
e8583acf9a Allow status aggregation for ramdisk reads. 2017-06-30 07:48:08 +00:00
Alexander Motin
86ce2be65a Unify INOT/ATIO setup. 2017-06-30 06:34:49 +00:00
Kenneth D. Merry
59fe76647c Fix a panic in camperiphfree().
If a peripheral driver (e.g. da, sa, cd) is added or removed from the
peripheral driver list while an unrelated peripheral driver instance (e.g.
da0, sa5, cd2) is going away and is inside camperiphfree(), we could
dereference an invalid pointer.

When peripheral drivers are added or removed (see periphdriver_register()
and periphdriver_unregister()), the peripheral driver array is resized
and existing entries are moved.

Although we hold the topology lock while we traverse the peripheral driver
list, we retain a pointer to the location of the peripheral driver pointer
and then drop the topology lock.  So we are still vulnerable to the list
getting moved around while the lock is dropped.

To solve the problem, cache a copy of the peripheral driver pointer.  If
its storage location in the list changes while we have the lock dropped, it
won't have any effect.

This doesn't solve the issue that peripheral drivers ("da", "cd", as opposed
to individual instances like "da0", "cd0") are not generally part of a
reference counting scheme to guard against deregistering them while there
are instances active.  The caller (generally the person unloading a module)
has to be aware of active drivers and not unload something that is in use.

sys/cam/cam_periph.c:
	In camperiphfree(), cache a pointer to the peripheral driver
	instance to avoid holding a pointer to an invalid memory location
	in the event that the peripheral driver list changes while we have
	the topology lock dropped.

PR:		kern/219701
Submitted by:	avg
MFC after:	3 days
Sponsored by:	Spectra Logic
2017-06-27 19:26:02 +00:00
Kenneth D. Merry
89763b3f8e In scsi_zbc_in(), fill in the length in the ZBC IN CDB.
Without the allocation length set, the target will either reject
the command or complete it without transferring any data.

This fixes the REPORT ZONES command for SCSI ZBC protocol devices,
as well as ATA ZAC protocol devices that are behind a SCSI to ATA
translation layer.  (LSI/Broadcom's 12Gb SAS adapters translate ZBC
commands to ZAC commands.)  Those are Host Aware and Host Managed SMR
drives.

This will fix REPORT ZONE commands sent to the da(4) driver via the
GEOM bio interface and zonectl, and REPORT ZONE commands sent from
camcontrol(8).

Note that in the case of camcontrol(8), we currently only send
SCSI ZBC commands to native SCSI protocol devices, not ATA devices
behind a SAT layer.

sys/cam/scsi/scsi_da.c:
	Fill in the length field in scsi_zbc_in().

MFC after:	3 days
Sponsored by:	Spectra Logic
2017-06-27 17:55:25 +00:00
Warner Losh
1d6e811063 Namespace is 32-bits, don't cast it to 16 here 2017-06-27 16:48:05 +00:00
Mark Johnston
b3db6c0140 Fix a memory leak in ses_get_elm_devnames().
After r307132 the sbuf buffer is malloc()ed, but corresponding
sbuf_delete() call was missing.

Fix a nearby whitespace bug.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-06-26 19:41:14 +00:00
Kenneth D. Merry
6f579fdb17 Fix a potential sleep while holding a mutex in the sa(4) driver.
If the user issues a MTIOCEXTGET ioctl, and the tape drive in question has
a serial number that is longer than 80 characters, we malloc a buffer in
saextget() to hold the output of cam_strvis().

Since a mutex is held in that codepath, doing a M_WAITOK malloc could lead
to sleeping while holding a mutex.  Change it to a M_NOWAIT malloc and bail
out if we fail to allocate the memory.  Devices with serial numbers longer
than 80 bytes are very rare (I don't recall seeing one), so this
should be a very unusual case to hit.  But it is a bug that should be fixed.

sys/cam/scsi/scsi_sa.c:
	In saextget(), if we need to malloc a buffer to hold the output of
	cam_strvis(), don't wait for the memory.  Fail and return an error
	if we can't allocate the memory immediately.

PR:		kern/220094
Submitted by:	Jia-Ju Bai <baijiaju1990@163.com>
MFC after:	3 days
Sponsored by:	Spectra Logic
2017-06-19 20:48:00 +00:00
Gleb Smirnoff
779f106aa1 Listening sockets improvements.
o Separate fields of struct socket that belong to listening from
  fields that belong to normal dataflow, and unionize them.  This
  shrinks the structure a bit.
  - Take out selinfo's from the socket buffers into the socket. The
    first reason is to support braindamaged scenario when a socket is
    added to kevent(2) and then listen(2) is cast on it. The second
    reason is that there is future plan to make socket buffers pluggable,
    so that for a dataflow socket a socket buffer can be changed, and
    in this case we also want to keep same selinfos through the lifetime
    of a socket.
  - Remove struct struct so_accf. Since now listening stuff no longer
    affects struct socket size, just move its fields into listening part
    of the union.
  - Provide sol_upcall field and enforce that so_upcall_set() may be called
    only on a dataflow socket, which has buffers, and for listening sockets
    provide solisten_upcall_set().

o Remove ACCEPT_LOCK() global.
  - Add a mutex to socket, to be used instead of socket buffer lock to lock
    fields of struct socket that don't belong to a socket buffer.
  - Allow to acquire two socket locks, but the first one must belong to a
    listening socket.
  - Make soref()/sorele() to use atomic(9).  This allows in some situations
    to do soref() without owning socket lock.  There is place for improvement
    here, it is possible to make sorele() also to lock optionally.
  - Most protocols aren't touched by this change, except UNIX local sockets.
    See below for more information.

o Reduce copy-and-paste in kernel modules that accept connections from
  listening sockets: provide function solisten_dequeue(), and use it in
  the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
  infiniband, rpc.

o UNIX local sockets.
  - Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
    local sockets.  Most races exist around spawning a new socket, when we
    are connecting to a local listening socket.  To cover them, we need to
    hold locks on both PCBs when spawning a third one.  This means holding
    them across sonewconn().  This creates a LOR between pcb locks and
    unp_list_lock.
  - To fix the new LOR, abandon the global unp_list_lock in favor of global
    unp_link_lock.  Indeed, separating these two locks didn't provide us any
    extra parralelism in the UNIX sockets.
  - Now call into uipc_attach() may happen with unp_link_lock hold if, we
    are accepting, or without unp_link_lock in case if we are just creating
    a socket.
  - Another problem in UNIX sockets is that uipc_close() basicly did nothing
    for a listening socket.  The vnode remained opened for connections.  This
    is fixed by removing vnode in uipc_close().  Maybe the right way would be
    to do it for all sockets (not only listening), simply move the vnode
    teardown from uipc_detach() to uipc_close()?

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D9770
2017-06-08 21:30:34 +00:00
Wojciech Macek
631f8f40d3 Introduce Genesys GL3224 quirks
The Genesys chip is failing when issueing READ_CAP(16) command.
Force a quirk to disable it and use READ_CAP(10) instead.

Also, depending on used firmware, GL3224 can be recognized
either as 'storage device' or 'mass storage class' -
enable both variants in scsi_quirk_table.

Submitted by:    Wojciech Macek <wma@semihalf.com>
                 Konrad Adamczyk <ka@semihalf.com>
Obtained from:   Semihalf
Sponsored by:    Stormshield
Reviewed by:     mav
Differential revision: https://reviews.freebsd.org/D10902
2017-05-29 09:22:53 +00:00
Andriy Gapon
b5617df55b Allow PROBE_SPINUP to fail in CAM ATA transport
The motivation for this is two-fold.

1. Some old WD SATA disks may appear as if they need to be spun up
when they are already spinning.  Those disks would respond with
an error to the spin-up request.

2. Even if we really fail to spin up the disk, we still can try to
proceed to the subsequent phases.  If we fail later on, then no
difference.  Otherwise we get a chance to communicate with the
disk which is better than completely ignoring it, because a user
can try to recover the disk.

Reviewed by:	mav
MFC after:	3 weeks
Differential Revision: https://reviews.freebsd.org/D10896
2017-05-26 17:44:47 +00:00
Kenneth D. Merry
64409eeee7 Add basic programmable early warning error injection to the sa(4) driver.
This will help application developers simulate end of tape conditions.

To inject an error in sa0:

sysctl kern.cam.sa.0.inject_eom=1

This will return the next read or write request queued with 0 bytes
written.  Any subsequent writes or reads will go along as usual.

This will also cause the early warning position flag to get set
for the next position query.  So, 'mt status' will show the BPEW
(Beyond Programmable Early Warning) flag on the first query after
an error injection.  After that, the position flags will be as they
are in the underlying tape drive.

Also, update the sa(4) man page to describe tape parameters,
which can be set via 'mt param'.

sys/cam/scsi/scsi_sa.c:
	In saregister(), create the inject_eom sysctl variable.

	In sastart(), check to see whether inject_eom is set.  If
	so, return the read or write with 0 bytes written to
	indicate EOM.  Set the set_pews_status flag so that we
	fake PEWS status in the next position call for reads, and the
	next 3 calls for writes.  This allows the user to see the BPEW
	flag one time via 'mt status'.

	In sagetpos(), check the set_pews_status flag and fake
	PEWS status and decrement the counter if it is set.

share/man/man4/sa.4:
	Document the inject_eom sysctl variable.

	Document all of the parameters currently supported via
	'mt param'.

usr.bin/mt/mt.1:
	Point the user to the sa(4) man page for more details on
	supported parameters.

MFC after:	3 days
Sponsored by:	Spectra Logic
2017-05-05 20:00:53 +00:00
Kenneth D. Merry
6da3b2f7f0 Add the SCSI Solid State Media Log page (0x11) definition.
sys/cam/scsi/scsi_all.h:
	Add the SCSI Solid State Media log page (0x11) structure
	definition.  This gives the percentage used (in terms of
	lifetime flash wear) of an SSD.

MFC after:	3 days
Sponsored by:	Spectra Logic
2017-05-04 17:23:39 +00:00
Kenneth D. Merry
6953d22b15 Fix error recovery behavior in the pass(4) driver.
After FreeBSD SVN revision 236814, the pass(4) driver changed from
only doing error recovery when the CAM_PASS_ERR_RECOVER flag was
set on a CCB to sometimes doing error recovery if the passed in
retry count was non-zero.

Error recovery would happen if two conditions were met:

1.  The error recovery action was simply a retry.  (Which is most
    cases.)
2.  The retry_count is non-zero. (Which happened a lot because of
    cut-and-pasted code.)

This explains a bug I noticed in with camcontrol:

# camcontrol tur da34 -v
Unit is ready
# camcontrol reset da34
Reset of 1:172:0 was successful

At this point, there should be a Unit Attention:

# camcontrol tur da34 -v
Unit is ready

No Unit Attention.

Try it again:

# camcontrol reset da34
Reset of 1:172:0 was successful

Now set the retry_count to 0 for the TUR:

# camcontrol tur da34 -v -C 0
Unit is not ready
(pass42:mps1:0:172:0): TEST UNIT READY. CDB: 00 00 00 00 00 00
(pass42:mps1:0:172:0): CAM status: SCSI Status Error
(pass42:mps1:0:172:0): SCSI status: Check Condition
(pass42:mps1:0:172:0): SCSI sense: UNIT ATTENTION asc:29,2 (SCSI bus reset occurred)
(pass42:mps1:0:172:0): Field Replaceable Unit: 2

There is the unit attention. camcontrol(8) has a default
retry_count of 1, in case someone sets the -E flag without
setting -C.

The CAM_PASS_ERR_RECOVER behavior was only broken with the
CAMIOCOMMAND ioctl, which is the synchronous pass(4) API.  It has
worked as intended (error recovery is only done when the flag
is set) in the asynchronous API (CAMIOQUEUE ioctl).

sys/cam/scsi/scsi_pass.c:
	In passsendccb(), when calling cam_periph_runccb(), only
	specify the error routine when CAM_PASS_ERR_RECOVER is set.

share/man/man4/pass.4:
	Document that CAM_PASS_ERR_RECOVER is needed to enable
	error recovery.

Reported by:	Terry Kennedy <TERRY@glaver.org>
PR:		kern/218572
MFC after:	1 week
Sponsored by:	Spectra Logic
2017-05-03 20:59:47 +00:00
Kenneth D. Merry
c36036beff Don't bother retrying errors for encrypted drives that are locked.
sys/cam/scsi/scsi_all.c:
	In the asc_table, if we get a 0x20,0x02 error ("Access denied -
	no access rights"), don't bother retrying.  Instead, immediately
	fail the command.

	This is the error returned by Self Encrypting Drives (SED) when
	they are locked.

MFC after:	3 days
Sponsored by:	Spectra Logic
2017-05-03 14:53:27 +00:00
Scott Long
da0d7209e0 Fix an unsafe malloc usage with sbufs.
Reported by:	ken
Sponsored by:	Netflix
2017-05-03 05:33:15 +00:00
Kenneth D. Merry
4ab558860e Add the SCSI SSC Manufacturer assigned serial number VPD page.
This is current as of SSC-5r03.

Submitted by:	Sam Klopsch
MFC after:	3 days
2017-05-02 14:52:28 +00:00
Alexander Motin
d0cfe1010e Change ctl_free_lun() locking.
This fixes potential callout_drain() sleep under non-sleepable lock.

PR:		218167
MFC after:	2 weeks
2017-04-24 12:52:42 +00:00
Alexander Motin
68bf823f9f Slightly compact the code.
MFC after:	2 weeks
2017-04-24 12:44:04 +00:00
Scott Long
fb2cec6f53 Reorder the minimum_cmd_size code to make it a little smaller and
easier to read.
2017-04-20 20:46:34 +00:00
Scott Long
5d01277f59 Add infrastructure to the ATA and SCSI transports that supports
using a driver-supplied sbuf for printing device discovery
announcements. This helps ensure that messages to the console
will be properly serialized (through sbuf_putbuf) and not be
truncated and interleaved with other messages. The
infrastructure mirrors the existing xpt_announce_periph()
entry point and is opt-in for now. No content or formatting
changes are visible to the operator other than the new coherency.

While here, eliminate the stack usage of the temporary
announcement buffer in some of the drivers. It's moved to the
softc for now, but future work will eliminate it entirely by
making the code flow more linear. Future work will also address
locking so that the sbufs can be dynamically sized.

The scsi_da, scs_cd, scsi_ses, and ata_da drivers are converted
at this point, other drivers can be converted at a later date.
A tunable+sysctl, kern.cam.announce_nosbuf, exists for testing
purposes but will be removed later.

TODO:
Eliminate all of the code duplication and temporary buffers.  The
old printf-based methods will be retired, and xpt_announce_periph()
will just be a wrapper that uses a dynamically sized sbuf.  This
requires that the register and deregister paths be made malloc-safe,
which they aren't currently.

Sponsored by:	Netflix
2017-04-19 15:04:52 +00:00
Conrad Meyer
ac30bca611 da(4): Fix a TRIM regression introduced in r308155
According to Warner, multiple TRIM BIOs are collapsed into a single CCB with
NULL bp.  It is invalid to biotrack() NULL, and results in a fault.  So,
don't do that.

Reported by:	asomers@
Sponsored by:	Dell EMC Isilon
2017-04-18 21:05:05 +00:00
Alexander Motin
bb8cea1b21 Fix few minor issues found by Clang Analyzer.
MFC after:	2 weeks
2017-04-09 07:54:39 +00:00
Enji Cooper
653e7d6396 Split iscsi(4) ctl frontend off of ctl(4) as cfiscsi(4)
The goal of this work is to remove the explicit dependency for ctl(4)
on iscsi(4), so end-users without iscsi(4) support in the kernel can
use ctl(4) for its other functions.

This allows those without iscsi(4) support built into the kernel to use
ctl(4) as a test mechanism. As a sidenote, this was possible around the
10.0-RELEASE period, but made impossible for end-users without iscsi(4)
between 10.0-RELEASE and 11.0-RELEASE.

Automatically load cfiscsi(4) from ctladm(8) and ctld(8) for backwards
compatibility with previously releases. The automatic loading feature is
compiled into the beforementioned tools if MK_ISCSI == yes when building
world.

Add a manpage for cfiscsi(4) and refer to it in ctl(4).

Differential Revision:	D10099
MFC after:	2 months
Relnotes:	yes
Reviewed by:	mav, trasz
Sponsored by:	Dell EMC Isilon
2017-03-30 04:56:27 +00:00
Michael Gmelin
9fc511b8a5 In r289137 the legacy_aliases compatibility shims for ata were removed,
also remove a leftover define used for implementing them.

Reviewed by:	mav
Differential Revision:	https://reviews.freebsd.org/D6726
2017-03-28 23:02:41 +00:00
Bryan Drewery
9ff3cdff12 Release ccb if mode_buffer allocation fails.
MFC after:	2 weeks
Obtained from:	OneFS
Sponsored by:	Dell EMC Isilon
2017-03-28 00:39:41 +00:00
Alexander Motin
62df0949fd Remove "UNMAPPED" messages printed on da periph attach.
I think this message is not very useful for end user.  Also its formatting
does not match other messages printed at that time.  Those who really need
this information can always find it in `camcontrol negotiate daX -v`.

MFC after:	2 weeks
2017-03-23 10:50:45 +00:00
Warner Losh
79d80af216 Implement moving SD.
From the paper "Incremental calculation of weighted mean and variance"
by Tony Finch Februrary 2009, retrieved from
http://people.ds.cam.ac.uk/fanf2/hermes/doc/antiforgery/stats.pdf
converted to use shifting.
2017-03-22 19:18:47 +00:00
Alexander Motin
331d00ba74 Minor cosmetic addition to r315673.
Now CAM_SIM_LOCK() macros are not used and may be removed later.

MFC after:	2 weeks
2017-03-21 09:24:07 +00:00
Alexander Motin
401ed17ad0 Make CAM SIM lock optional.
For three years now CAM does not use SIM lock, but still enforces SIM to
use it.  Remove this requirement, allowing SIMs to have any locking they
prefer, if they pass no mutex to cam_sim_alloc().

MFC after:	2 weeks
2017-03-21 09:12:41 +00:00
Alexander Motin
b1303ffeb2 Increase device openings to tagged maximum.
Some SIMs report much less untagged device openings then tagged ones.
Target mode devices are not handled by regular probing routines, and so
there is nothing to increase queue size for them to the SIM's maximum.
To fix that resize the queue explicitly on ctl periph registration.
This radically improves performance of mpt(4) in target mode.

Also fetch and report device queue statistics in `ctladm dumpstructs`,
since regular way of `camcontrol tags` is not usable in target mode.

MFC after:	2 weeks
2017-03-11 18:46:46 +00:00
Alexander Motin
2ef6e7aea8 Allow XPT_GDEV_STATS for UNCONFIGURED devices.
Queue statistics has nothing to do with presence or absence of INQUIRY
data, etc.  Target mode devices are never configured, but have queues.

MFC after:	2 weeks
2017-03-11 18:23:05 +00:00
Alexander Motin
ad0f05e629 Abort all ATIOs and INOTs queued to SIM on LUN disable.
Some SIMs may not abort them implicitly, that either fail the LUN disable
request or just make us wait for those CCBs forever.  With this change
I can successfully disable LUNs on mpt(4).  For isp(4), which aborts them
implicitly, this change should be irrelevant.

MFC after:	2 weeks
2017-03-10 21:09:33 +00:00
Alexander Motin
832529c5bd Switch work_queue from TAILQ to STAILQ.
It is mostly FIFO and we don't need random removal there.

MFC after:	2 weeks
2017-03-10 20:20:00 +00:00
Alexander Motin
45400376e0 Request change of SIM target role only when it is different.
Separate WWNs change into separate request to know what actually failed.

MFC after:	2 weeks
2017-03-10 19:43:45 +00:00
Alexander Motin
6fffdbbd67 Add initial support for UNMAP granularity.
Report UNMAP granularity as stripesize/-offset if we have no other values
to report there.

Add new quirk DA_Q_STRICT_UNMAP for cases when target is too critical to
misaligned UNMAP request, reporting errors instead of being suboptimal.
Setting this quirk makes da periph to forcefully align all UNMAP requests
to avoid those errors by the cost of some odd ranges not being UNMAP'ed.
This makes UNMAP usable within VMware 6.x VMs, just now 100% efficient.

MFC after:	2 weeks
2017-03-08 11:24:33 +00:00
Alexander Motin
94173c3c9b Add mechanism to unload CAM periph drivers.
For now it allows to unload CTL kernel module if there are no target-capable
SIMs in CAM.  As next step full teardown of CAM targets can be implemented.
2017-03-07 17:41:08 +00:00
Mark Johnston
a0bbf9e0e3 Reject userland CCBs that have CAM_UNLOCKED set.
CAM_UNLOCKED is internal flag and cannot correctly be set by userland.
Return EINVAL from CAMIOCOMMAND and CAMIOQUEUE if it is set.

Also fix leaks in some of the error paths for CAMIOQUEUE.

PR:		215356
Reviewed by:	ken, mav
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D9869
2017-03-03 20:51:57 +00:00
Alexander Motin
9d42b1fc43 Add check missed in r314257.
MFC after:	11 days
2017-03-01 17:35:56 +00:00
Alexander Motin
3a13860a1b Make ctl_queue_sense() not sleep.
It may be called in non-sleepable frontend context.

MFC after:	2 weeks
2017-02-28 11:56:17 +00:00
Alexander Motin
9ff948d05f Polish handling of different reset flavours.
The biggest change is that ctl_remove_initiator() now generates I_T NEXUS
LOSS event, cleaning part of LUs state related to the initiator.

MFC after:	2 weeks
2017-02-27 14:59:00 +00:00
Alexander Motin
b371466e29 Add support for SIMs without autosense.
If we asked to send sense data by setting CAM_SEND_SENSE, but SIM didn't
confirm transmission by setting CAM_SENT_SENSE, assume it was not sent.
Queue the I/O back to CTL for later REQUEST SENSE with ctl_queue_sense().
This is needed for error reporting on SPI HBAs like ahc(4)/ahd(4).

MFC after:	2 weeks
2017-02-26 19:23:03 +00:00
Alexander Motin
15b2cdedca Use resid field of CTIO to detect under/overruns.
MFC after:	2 weeks
2017-02-26 12:54:27 +00:00
Warner Losh
2379d1d6ed Move inclusion of opt_printf.h around so that we can compile all the
SCSI modules outside of a sub-build from the kernel.

Differential Revision: https://reviews.freebsd.org/D9653
Sponsored by: Netflix
2017-02-25 22:11:10 +00:00
Alexander Motin
a9d2a1930b Add reporting SAS protocol, in case we ever have one.
MFC after:	2 weeks
2017-02-25 14:36:24 +00:00
Alexander Motin
6563855634 Reenable CTL_WITH_CA, optimizing it for lower memory usage.
This code was disabled due to its high memory usage.  But now we need this
functionality for cfumass(4) frontend, since USB MS BBB transport does not
support autosense.

MFC after:	2 weeks
2017-02-25 14:20:30 +00:00
Alexander Motin
03ea6ef2db Axe out some forever disabled questionable functionality.
This code is complicated enough even in its base shape.

MFC after:	2 weeks
2017-02-25 04:24:51 +00:00
Alexander Motin
3afd480696 Improve CAM target frontend reference counting.
Before this change it was possible to trigger some use-after-free panics
by disabling LUNs/ports under heavy load.

MFC after:	2 weeks
2017-02-25 04:04:11 +00:00
Alexander Motin
d7c2cc352e Explicitly abort ATIO if CTIO sending status has failed.
This helps SIM to free related resources in questionable cases.

MFC after:	2 weeks
2017-02-24 12:12:30 +00:00
Alexander Motin
8d1316f914 We can't access periph after ctlfe_free_ccb().
MFC after:	2 weeks
2017-02-24 11:25:32 +00:00
Alexander Motin
a504738fac Unify ATIO/INOT CCBs requeuing.
MFC after:	2 weeks
2017-02-24 09:16:21 +00:00
Alexander Motin
6b0878502e Some code cleanup.
MFC after:	2 weeks
2017-02-24 07:47:50 +00:00
Alexander Motin
3b63a91d6d Do not blindly free completed ATIOs/INOTs on invalidation.
When LUN is disabled, SIM starts returning queued ATIOs/INOTs.  But at the
same time there can be some ATIOs/INOTs still carrying real new requests.
If we free those, SIM may leak some resources, forever expecting for any
response from us.  So try to be careful, separating ATIOs/INOTs carrying
requests which still must be processed, from ATIOs/INOTs completed with
errors which can be freed.

MFC after:	2 weeks
2017-02-21 06:10:11 +00:00
Alexander Motin
950c5aca4a Remove dead mentions of CAM target mode APIs from drivers.
This makes grepping kernel for target mode implementation much easier.
2017-02-19 17:27:58 +00:00
Alexander Motin
46511441fb Change XCOPY memory allocations.
Before this change XCOPY code could allocate memory in chunks up to 16-32MB
(VMware does XCOPY in 4MB chunks by default), that could be difficult for
VM subsystem to do due to KVA fragmentation, that sometimes created huge
allocation delays, blocking any I/O for respective LU for that time.

This change limits allocations down to TPC_MAX_IO_SIZE, which is 1MB now.
1MB is also not a cookie, but ZFS also can do that for large blocks, so
it should be less dramatic.  As drawback this increases CPU overhead, but
it still look acceptable comparing to time consumed by ZFS read/write.

MFC after:	1 week
2017-02-18 06:03:16 +00:00
Kenneth D. Merry
e9200a6cc2 Make ctl(4) build with CTL_IO_DELAY defined.
sys/cam/ctl/ctl.c:
	In ctl_datamove(), inside CTL_IO_DELAY, add a lun variable and fill
	it in before trying to dereference it.

MFC after:	3 days
Sponsored by:	Spectra Logic
2017-02-17 20:15:27 +00:00
Alexander Motin
7a465c285f Change the way MaxCmdSN is used.
Before this change MaxCmdSN was reported as CmdSN + delta, that made it
limit number of requests in transmission from the initiator to target,
that was pretty useless.  After this change MaxCmdSN limits number of
requests queued to CTL, i.e. maximal queue depth for the initiator.
The default limit is 256 outstanding requests per initiator at a time.

This code uses existing cs_outstanding_ctl_pdus counter to track queue
depth.  It's semantics doen't perfectly match, but close enough to not
add another counter.  Just don't set the maxtags below 2.

MFC after:	2 weeks
2017-02-17 05:22:58 +00:00
Alexander Motin
b6eed5e4e0 No need to erase sense_data when sense_len is set to zero.
MFC after:	2 weeks
2017-02-14 21:05:36 +00:00
Alexander Motin
2fb3637007 Fix panic on shutdown of ramdisk LU with zero capacity.
MFC after:	1 week
2017-02-14 18:03:17 +00:00
Baptiste Daroussin
b4b4b5304b Revert crap accidentally committed 2017-01-28 16:31:23 +00:00
Baptiste Daroussin
814aaaa7da Revert r312923 a better approach will be taken later 2017-01-28 16:30:14 +00:00
Yoshihiro Takahashi
2b375b4edd Remove pc98 support completely.
I thank all developers and contributors for pc98.

Relnotes:	yes
2017-01-28 02:22:15 +00:00
Scott Long
bf1a889535 Squash a couple of uses of xpt_print_path()
Sponsored by:	Netflix
2017-01-27 21:55:47 +00:00
Warner Losh
e831795b8a Remove nested #ifdef that can't possibly be false. 2017-01-27 08:30:43 +00:00
Jung-uk Kim
a196ef645a Fix libcam build. It was broken with r312827. 2017-01-27 00:17:07 +00:00
Scott Long
a136ca542c Fix a development mis-merge from r312827
Sponsored by:	Netflix
2017-01-26 20:18:03 +00:00
Scott Long
ab3e89f1ab Refactor xpt_print_path, xpt_print, and xpt_path_string. Implement
all of them in terms of an sbuf-based back-end, xpt_path_sbuf.  This
unifies the implementation, but more importantly it stops the output
fropm being split between 4 or more invocations of printf.  The
multiple invocations cause interleaving of the messages on the
console during boot, making the output of disk discovery often
unintelligible.  This change helps a lot, but more work is needed.

Reviewed by:	ken, mav
Sponsored by:	Netflix
2017-01-26 20:08:58 +00:00
Edward Tomasz Napierala
5ab1cf33f7 Bring the ctl headers a bit closer to style(9). No functional changes. 2017-01-25 22:52:57 +00:00
Warner Losh
b20c0a07fb Preening pass to fix up trailing white space and other minor style(9)
nits (though I'm sure others remain).

MFC After: 3 days
2017-01-25 02:05:08 +00:00
Alexander Motin
e7037673ca Make CTL ramdisk backend a real RAM disk.
If "capacity" LU option is set, ramdisk backend now implements featured
thin provisioned disk, storing data in malloc(9) allocated memory blocks
of pblocksize bytes (default PAGE_SIZE or 4KB).  Additionally ~0.2% of LU
size is used for indirection tree (bigger pblocksize reduce the overhead).
Backend supports all unmap and anchor operations.  If configured capacity
is overflowed, proper error conditions are reported.

If "capacity" LU option is not set, the backend operates mostly the same
as before without allocating real storage: writes go to nowhere, reads
return zeroes, reporting that all LBAs are unmapped.

This backend is still mostly oriented on testing and benchmarking (it is
still a volatile RAM disk), but now it should allow to run real FS tests,
not only simple dumb dd.

MFC after:	2 weeks
2017-01-24 12:13:41 +00:00