Commit Graph

2502 Commits

Author SHA1 Message Date
Warner Losh
da73926566 libcam: Define depop structures and introduce scsi_wrap
Define structures related to the depop set of commands (GET PHYSICAL ELEMENT
STATUS, REMOVE ELEMENT AND TRUNCATE, and RESTORE ELEMENT AND REBUILD) as
well as the CDB construction routines.

Also create scsi_wrap.c. This will have convenience routines that will do all
the elements of allocating the ccb, generating the CDB, sending the command
(looping as necessary for cases where data is returned, but it's size isn't
known up front), etc. As this functionality is fleshed out, calling many
camcontrol commands programatically gets much easier.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D29017
2021-09-20 16:27:59 -06:00
John Baldwin
0cd6e85e24 iscsi: Abort data-out tasks queued on a terminating session.
cfiscsi_datamove_out() can race with cfiscsi_session_terminate_tasks()
and enqueue a new task after the latter function has aborted existing
tasks.  This could result in a deadlock as
cfiscsi_session_terminate_tasks() waited forever for this task to
complete.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31892
2021-09-15 13:25:30 -07:00
John Baldwin
529364b032 iscsi: Add a helper routine to abort a data-out task.
Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31891
2021-09-15 13:25:04 -07:00
John Baldwin
d2bc7754a2 Assert that invalid bus widths can't be passed to bus_width_str().
This appeases a -Wreturn-type warning from GCC.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D31935
2021-09-15 09:03:17 -07:00
Ka Ho Ng
49050613ef ctl(4): Do hole-punching for UNMAP to file-backed LUNs
This adds support for SCSI UNMAP command to file-backed LUNs, if the
underlying file system has a non-zerofilling VOP_DEALLOCATE
implementation where some or all parts of the requested operation range
may be deallocated.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	mav
Differential Revision:	https://reviews.freebsd.org/D31922
2021-09-15 03:51:58 +08:00
Alexander Motin
e76786909c Fix data race in scsi cd driver.
There is a data race between cdsysctlinit and cdcheckmedia.  Both
functions change softc->flags without synchronization.

Submitted by:	Arseny Smalyuk <smalukav@gmail.com>
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D31726
2021-09-13 08:59:51 -04:00
Alan Somers
cc2d08d388 ses: Guard the elm_type_names declaration by _KERNEL
MFC after:	2 weeks
Sponsored by:	Axcient
2021-09-02 14:47:18 -06:00
Alan Somers
1fb52e4373 ses: Correct spelling of "Temperature Sensor"
According to SES 4 revision 2 table 71, it should be singular.

MFC after:	2 weeks
Sponsored by:	Axcient
2021-09-02 14:38:06 -06:00
Edward Tomasz Napierala
0f49ecffb7 cam: revert second half of 75b5caa08e
This turns debugging printf() into a KASSERT().

Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31523
2021-09-01 09:35:27 +00:00
Alexander Motin
f3dcedd3de targ(4): Remove D_NEEDGIANT.
I don't believe this code needs Giant, if ever needed.

MFC after:	1 month
2021-08-21 11:20:54 -04:00
Alexander Motin
84d5b6bd68 cam(4): Fix quick unplug/replug for SCSI.
If some device is plugged back in after unplug before the probe periph
destroyed, it will just restart the probe process. But I've found that
PROBE_INQUIRY_CKSUM flag not cleared between the iterations may cause
AC_FOUND_DEVICE not reported on the second iteration, and because of
AC_LOST_DEVICE reported during the first iteration, the device end up
configured, but without any periphs attached.

We've found that enabled serial console and 102-disk JBOD cause enough
probe delays to easily trigger the issue for half of the disks.  This
change fixes it reliably on my tests.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2021-08-21 09:58:05 -04:00
John Baldwin
c261b6ea4e iscsi: Teach the iSCSI stack about "large" received PDUs.
When using iSCSI PDU offload (cxgbei) on T6 adapters, a burst of
received PDUs can be reported via a single message to the driver.

Previously the driver passed these multi-PDU bursts up to the iSCSI
stack up as a single "large" PDU by rewriting the buffer offset, data
segment length, and DataSN fields in the iSCSI header.  The DataSN
field in particular was rewritten so that each of the "large" PDUs
used consecutively increasing values.  While this worked, the forged
DataSN values did not match the ExpDataSN value in the subsequent SCSI
Response PDU.  The initiator does not currently verify this value, but
the forged DataSN values prevent adding a check.

To avoid this, allow a logical iSCSI PDU (struct icl_pdu) to describe
a burst of PDUs via a new 'ip_additional_pdus' field.  Normally this
field is set to zero when 'struct icl_pdu' represents a single PDU.
If logical PDU represents a burst of on-the-wire PDUs, then 'ip_npdus'
contains the count of additional on-the-wire PDUs.  The header of this
"large" PDU is still modified, but the DataSN field now contains the
DataSN value of the first on-the-wire PDU in the burst.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31577
2021-08-18 10:56:28 -07:00
Gordon Bergling
1da11b8ac3 Fix a common typo in source code comments
- s/definitons/definitions/

MFC after:	5 days
2021-08-14 14:08:46 +02:00
Gordon Bergling
34f620f1d0 Fix a few typos in source code comments
- s/posbile/possible/

MFC after:	5 days
2021-08-14 09:39:17 +02:00
Alexander Motin
303477d325 cam(4): Mark all sysctls as CTLFLAG_MPSAFE.
This code does not use Giant lock for very long time.

MFC after:	2 weeks
2021-08-10 20:07:19 -04:00
Edward Tomasz Napierala
b0cf8194c2 cam: revert half of 75b5caa08e
This turns debugging printf() into a KASSERT().
It's for ATA for now; SCSI will came later.

Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31380
2021-08-08 13:24:19 +00:00
Gordon Bergling
04389c855e Fix some common typos in comments
- s/configuraiton/configuration/
- s/specifed/specified/
- s/compatiblity/compatibility/

MFC after:	5 days
2021-08-08 10:16:06 +02:00
John Baldwin
f0594f52f6 iSCSI: Add support for segmentation offload for hardware offloads.
Similar to TSO, iSCSI segmentation offload permits the upper layers to
submit a "large" virtual PDU which is split up into multiple segments
(PDUs) on the wire.  Similar to how the TCP/IP headers are used as
templates for TSO, the BHS at the start of a large PDU is used as a
template to construct the specific BHS at the start of each PDU.  In
particular, the DataSN is incremented for each subsequent PDU, and the
'F' flag is only set on the last PDU.

struct icl_conn has a new 'ic_hw_isomax' field which defaults to 0,
but can be set to the largest virtual PDU a backend supports.  If this
value is non-zero, the iSCSI target and initiator use this size
instead of 'ic_max_send_data_segment_length' to determine the maximum
size for SCSI Data-In and SCSI Data-Out PDUs.  Note that since PDUs
can be constructed from multiple buffers before being dispatched, the
target and initiator must wait for the PDU to be fully constructed
before determining the number of DataSN values were consumed (and thus
updating the per-transfer DataSN value used for the start of the next
PDU).

The target generates large PDUs for SCSI Data-In PDUs in
cfiscsi_datamove_in().  The initiator generates large PDUs for SCSI
Data-Out PDUs generated in response to an R2T.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31222
2021-08-06 14:03:00 -07:00
Konstantin Belousov
0ef5eee9d9 Add vn_lktype_write()
and remove repetetive code that calculates vnode locking type for write.

Reviewed by:	khng, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31405
2021-08-04 19:40:13 +03:00
Edward Tomasz Napierala
60fb9e10c7 cam: enable kern.cam.da.enable_uma_ccbs by default
This makes the da(4) driver use UMA for its CCBs by default,
like ada(4) already does.  Please let me know via email
if you notice any suspicious kernel messages,

Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31257
2021-08-01 09:40:42 +00:00
Edward Tomasz Napierala
616a676a05 cam: clear stack-allocated CCB in the target layer
Note that, as pointed out by scottl@, this code should really look
a bit different, in that the stack allocations should be replaced
with dynamic allocation, and the periph creation should be moved
to a context where one can use M_WAITOK.  See the review for more
details.  For now let's go with a minimal fix until we're done with
UMA CCBs.

Reviewed By:	mav, imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D30298
2021-07-21 10:18:28 +01:00
Warner Losh
abea0c6b0d cam: Mark the qos data is valid in xpd_done_direct() too.
Sponsored by:		Netflix
2021-07-17 16:12:00 -06:00
Warner Losh
a065ccb280 cam_iosched: use tunable flag and make a bool really a bool
kern.cam.do_dynamic_iosched is really a bool, so change its type to
bool. While I'm here, also use the CTLFLAG_TUN flag instead of a
separate tunable line for it and kern.cam.iosched_alpha_bits.

MFC After:		1 week
Sponsored by:		Netflix
2021-07-13 14:13:21 -06:00
Young Xiao
431ddd9436 Fix potential NULL pointer dereference of device physical path
In ata_dev_advinfo() and nvme_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.

This code mirrors scsi_xpt.c does already as well.

Signed-off-by:	Young Xiao <92siuyang@gmail.com>
Reviewed by:	imp
PR:		238014
2021-07-13 14:13:21 -06:00
Andriy Gapon
66c183f43f mmc_cam_sim_default_action: do not touch the ccb after dispatching it
If MMC_SIM_CAM_REQUEST() is successful the ccb could be running or being
completed as the method returns.  Modifying the ccb status could override
whatever status was already set by a MMC driver.

I am not sure what was the purpose of setting the status to CAM_REQ_INVALID
in the success path.  I assume that it was to catch a possibility that the
ccb could be completed without its status explicitly set.  So, I am keeping
the code, it's just moved to before the MMC_SIM_CAM_REQUEST call.

Without this change I was getting random and phantom EIO errors on Rock64
running off an SD card (dwmmc driver) plus occasional panics like:
  Memory modified after free 0xffffa00003985800(2040) val=6 @ 0xffffa00003985854
  panic: Most recently used by CAM CCB

MFC after:	1 week
2021-07-12 21:29:26 +03:00
Edward Tomasz Napierala
6f147a0734 cam: enable kern.cam.ada.enable_uma_ccbs by default
This makes the ada(4) driver use UMA for its CCBs.  While it's
da(4) counterpart needs some more testing, this one seems to be
safe now.

Please let me know via email if you notice any suspicious kernel
messages,

Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D30567
2021-07-07 09:40:34 +01:00
Edward Tomasz Napierala
a081a943a0 cam: drop unused 'saved_ccb' field from softcs
No functional changes.  Do not MFC this, it changes kernel ABI.

Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D30698
2021-07-06 10:04:38 +01:00
Edward Tomasz Napierala
13aa56fcd5 cam(4): preserve alloc_flags when copying CCBs
Before UMA CCBs, all CCBs were of the same size, and could
be trivially copied using bcopy(9).  Now we have to preserve
alloc_flags, otherwise we might end up attempting to free
stack-allocated CCB to UMA; we also need to take CCB size
into account.

This fixes kernel panic which would occur when trying to access
a stopped (as in, SCSI START STOP, also "ctladm stop") SCSI device.

Reported By:	Gary Jennejohn <gljennjohn@gmail.com>
Tested By:	Gary Jennejohn <gljennjohn@gmail.com>
Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31054
2021-07-06 09:27:22 +01:00
Warner Losh
a72af82e31 cam: Fix GENERIC-MMCCAM build
Fix forgotten argument and type error. MMCCAM isn't enabled by default,
and I'd mistakenly thought it was, so these went undetected precommit.

Sponsored by:		Netflix
2021-06-28 17:22:35 -06:00
Warner Losh
9f0febd6a4 cam_sim: remove unused sim_doneq member
Its use was removed in 227d67aa54 by mav when locking was revamped.

Reviewed by:		scottl@, mav@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30890
2021-06-28 16:13:03 -06:00
Warner Losh
50aa1daf14 cam: change xpt_clone_path to return int
xpt_clone_path originally returned a cam_status, but it doesn't do I/O
and should return an errno instead. I added it last year and it's only
used in one place. It's not yet documented, so no doc changes are
nneeded.

Reviewed by:		scottl@, mav@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30884
2021-06-28 16:13:03 -06:00
Warner Losh
2b09870238 cam: Remove CAM_TRUE and CAM_FALSE, they are unused and duplicate bool
These were in the original CAM commit in 3.0, but were not used there,
nor have they been used since then. They also duplicate the now-standard
bool type. Remove them.

Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30879
2021-06-28 16:13:03 -06:00
Warner Losh
30f8afd027 cam: fix xpt_bus_register and xpt_bus_deregister return errno
xpt_bus_register and xpt_bus_deregister returns a hybrid error that's
neither a cam_status, nor an errno, but a mix of both.  Update
xpt_bus_register and xpt_bus_deregister to return an errno. The vast
majority of current users compare against zero, which can also be
spelled CAM_SUCCESS. Nobody uses CAM_FAILURE, so remove that symbol
to prevent comfusion (nothing returns it either).

Where the return value is saved, ensure that the variable 'error' is
used to store an errno and 'status' is used to store a cam_status where
it makes the code clearer (usually just in functions that already mix
and match). Where the return value isn't used at all, avoid storing it
at all.

Reviewed by:		scottl@, mav@ (earlier version)
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30860
2021-06-28 16:13:03 -06:00
Warner Losh
dcd5dea965 cam: delete cam_sim_alloc_dev
cam_sim_alloc_dev was only used internally by the MMC system. That has
been convered to using xpt_path_device() and has stopped using this
interface, so this can be retired.

Reviewed by:		scottl@, mav@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30858
2021-06-28 16:13:03 -06:00
Warner Losh
bd69852be1 mmc_sim: stop using cam_sim_alloc_dev
Use the vanilla flavor of cam_sim_alloc. Now that sdiob has been
converted to get the device_t from the cam_path, this data is no longer
necessary.

Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30856
2021-06-28 16:13:02 -06:00
Warner Losh
d6e7349254 cam mmc: Assert that the xpt_bus_register registered a device_t
Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30854
2021-06-28 15:59:04 -06:00
Warner Losh
1ed4016267 cam: add xpt_path_sim_device to return device_t associated with a path
Return the device associated with the sim's bus when it called
xpt_bus_register, if any. Most real SIMs in the tree set this device,
but some virtual ones do not have a device_t assocaited with them.

Reviewed by:		scottl@, mav@ (earlier version)
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30853
2021-06-28 15:57:51 -06:00
Warner Losh
9f1e411ae8 cam: Group all xpt_path*() functions together in cam_xpt.h
Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30852
2021-06-28 15:56:55 -06:00
Warner Losh
56e1161b09 cam: fix UB behavior
The trick of subtracting one from the poitner returned from malloc
results in undefined behavior:

>>C89: 3.3.6 Unless both the pointer operand and the result point to a
>>member of the same array object, or one past the last member of the
>>array object, the behavior is undefined.

Instead, allocate 1 extra element and stop adjusting the pointer. While
a little wasteful, the extra is in the noise on today's systems.

Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30847
2021-06-28 15:56:08 -06:00
Warner Losh
40990d5483 cam: save parent_dev in xpt_bus_register
Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30846
2021-06-28 15:55:02 -06:00
Warner Losh
c5d3206ac6 cam: kill trailing white space in two spots 2021-06-28 15:36:19 -06:00
Warner Losh
4afa62be71 cam: Set the CAM_QOS_VALID when valid
When the elapsed time of the operation is complete and stored in the QOS
field, set the CAM_QOS_VALID bit.  In iosched, test to make sure it's
set before using it.

Sponsored by:		Netflix
2021-06-20 19:14:13 -06:00
Emmanuel Vadot
3386347f65 mmc_sim: Make XPT_MMC_GET_TRAN_SETTINGS fully async
Sponsored by:	Diablotin Systems
2021-06-19 19:15:25 +02:00
Emmanuel Vadot
6506efea63 mmccam: Read the common members of CSD v1.0 and v2.0
And only get the differents ones based on the version.

No functional changes intented.

Sponsored by:	Diablotin Systems
2021-06-19 19:06:54 +02:00
Emmanuel Vadot
20d601682e mmccam: Style(9) more mmc_da.c
No functional changes.
Sponsored by:	Diablotin Systems
2021-06-19 19:06:54 +02:00
Dmitry Chagin
8345c513c5 sg: get rid of unused include.
sg driver does not depends on the Linuxulator any more.

Reviewed by:		imp
Differential Revision:	https://reviews.freebsd.org/D30750
MFC after:		2 weeks
2021-06-13 11:30:49 +03:00
Warner Losh
00e7a55367 cam_sim: style: sort includes
Sort and remove sys/systm.h, it's not needed.

Sponsored by:		Netflix
2021-05-25 09:56:56 -06:00
Warner Losh
1f348be6f2 cam: remove xpt_polled_action
Since periph_runccb now handles all the polling stuff, and
xpt_polled_action is now unused and can be removed.

Sponsored by:		Netflix
Reviewed by:		mav@
Differential Revision:	https://reviews.freebsd.org/D30394
2021-05-25 09:18:08 -06:00
Warner Losh
6c48134275 cam: Remove CAM_SIM_LOCK/UNLOCK macros, they are unused.
Sponsored by:		Netflix
Reviewed by:		mav@
Differential Revision:	https://reviews.freebsd.org/D30384
2021-05-25 09:18:08 -06:00
Warner Losh
28027f28e6 cam: remove sim callout
Nothing is using the sim callout to unfreeze the queue. Remove it to
simplify the SIM. This was introduced in the original CAM commit in 1998
but setting the CAM_SIM_REL_TIMEOUT_PENDING flag was removed in 1999 in
commit 87cfaf0e1f which reworked how bus reset worked. That work was
merged just after 3.2R was released. Remove the unused residuals.

Sponsored by:		Netflix
Reviewed by:		scottl@, mav@
Differential Revision:	https://reviews.freebsd.org/D30383
2021-05-25 09:18:08 -06:00