Commit graph

2709 commits

Author SHA1 Message Date
Alan Somers edbd489d09 ctladm: don't require the use of "-p" with "port -r"
When removing a port, the ioctl frontend requires the "-p" argument.
But other frontends, like cfiscsi, do not.  So don't require that
argument in the ctladm command.  The frontend driver will report an
error if any required argument is missing.

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279
2024-06-10 10:01:25 -06:00
Alan Somers afecc74cd7 ctladm: better documentation for adding and removing cfiscsi ports
MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279
2024-06-10 10:01:25 -06:00
Warner Losh 99c14fb99f cam: Drop periph lock when completing I/O with ENOMEM status
When biofinish calls g_io_deliver with an error of ENOMEM, that kicks
off the slowdown protocol, forcing I/O to go through g_down rather than
be directly dispatch. One of the side effects is that the I/O is
resubmitted, so the start routines get called recursively, leading to a
recursive lock panic. Rather than make the periph lock recursive, drop
and reacquire the lock around such calls to biofinish.

For nda, this happens only when we can't allocate space to construct a
TRIM. For ada and da, this is only for certain ZONE operations.

Sponsored by:		Netflix
Reviewed by:		gallatin
Differential Revision:	https://reviews.freebsd.org/D45310
2024-05-24 08:32:04 -06:00
Gleb Smirnoff 0d37895849 ctl: use socket buffer mutexes in struct socket directly
A mechanical change performed with sed(1) script:

s/SOCKBUF_LOCK\(&so->so_rcv\)/SOCK_RECVBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_rcv\)/SOCK_RECVBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_rcv\)/SOCK_RECVBUF_MTX(so)/
s/SOCKBUF_LOCK\(&so->so_snd\)/SOCK_SENDBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_snd\)/SOCK_SENDBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_snd\)/SOCK_SENDBUF_MTX(so)/

Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D45190
2024-05-23 12:11:54 -07:00
John Baldwin 1f83483d73 ctl_backend_block: Correct value of NVME nsdata nuse field
Reported by:	Coverity Scan
CID:	 	1545043
Sponsored by:	Chelsio Communications
2024-05-10 09:13:40 -07:00
Matthew Grooms 12117d0e93 da: Update trim stats for WRITE SAME and ATA TRIM
The scsi UNMAP path updated trim stats in the da sysctl, but the ATA
TRIM passthru and WRITE SAME paths did not. Add code so they do.

PR: 277637
Reviewed by: imp (tweaked WS path to update ranges)
2024-05-03 08:46:59 -06:00
John Baldwin 25bad5a2da ctl: Add NVMF port type and ioctls
- Add CTL_PORT_NVMF as a new port type.

- Define a new CTL_NVMF ioctl for NVMF-specific operations similar to
  CTL_ISCSI.  This ioctl supports a command to handoff a single
  queue pair, a command to enumerate active associations, and a
  command to disconnect one or more active associations.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44724
2024-05-02 16:38:30 -07:00
John Baldwin 374f12c52f ctl_backend_block: Add support for NVMe
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44723
2024-05-02 16:38:30 -07:00
John Baldwin 40a4359064 ctl_backend_block: Prepare for NVMe support
- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- Use protocol-agnostic wrapper routines for I/O completion status.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44851
2024-05-02 16:38:30 -07:00
John Baldwin d5c21c6883 ctl_backend_ramdisk: Add support for NVMe
One known caveat is that the support for WRITE_UNCORRECTABLE is not
quite correct as reads from LBAs after a WRITE_UNCORRECTABLE will
return zeroes rather than an error.  Fixing this would likely require
special handling for PG_ANCHOR for NVMe requests (or adding a new
PG_UNCORRECTABLE).

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44722
2024-05-02 16:38:30 -07:00
John Baldwin ccaaee4607 ctl_backend_ramdisk: Prepare for NVMe support
- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- Use protocol-agnostic wrapper routines for I/O completion status.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44849
2024-05-02 16:38:30 -07:00
John Baldwin bef5da8ebf ctl: Add helper routines to populate NVMe namespace data IDs for a LUN
These will be used by the backends to populate the unique ID fields
like EUI64 in the NVMe namespace data (CNS == 0) and namespace
identification descriptor list (CNS == 3).

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44721
2024-05-02 16:38:19 -07:00
John Baldwin 0c4ee619df ctl: Support for NVMe commands
- Add support for queueing and executing NVMe admin and NVM commands
  via ctl_run and ctl_queue.  This requires fixing a few places that
  were SCSI-specific to add NVME logic.

- NVMe has much simpler command ordering requirements than SCSI.  In
  particular, the HBA is not required to enforce any specific ordering
  for requests with overlapping LBAs.  The host is required to manage
  that ordering.  However, fused commands (currently only COMPARE and
  WRITE NVM commands can be fused) are required to be executed
  atomically.

  To support fused commands, make the second half of a fused command
  block on the first half, and have commands submitted after a fused
  command pair block on the second half.

- Add handlers and command tables for admin and NVM commands that
  operate on individual namespaces and will be passed down from an
  NVMe over Fabrics controller to a CTL LUN.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44720
2024-05-02 16:32:09 -07:00
John Baldwin 105333f1d6 ctl: Add assertions in SCSI-only paths
Assert that only SCSI I/O requests are passed in various places
that assume a SCSI I/O request (that is, places that access fields
in io->scsiio directly).

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44847
2024-05-02 16:31:59 -07:00
John Baldwin ab4b83874a ctl: Update some core data paths to be protocol agnostic
- Add wrapper routines for invoking the be_move_done and io_continue
  callbacks in SCSI and NVMe I/O requests.

- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- ctl_config_write_done is not fully updated since it resubmits SCSI
  commands via ctl_scsiio.  This will be completed in a subsequent
  commit when ctl_nvmeio is added.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44846
2024-05-02 16:31:44 -07:00
John Baldwin 6f308bcf57 ctl: Support NVMe requests in debug trace functions
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44719
2024-05-02 16:31:34 -07:00
John Baldwin 75577946b5 ctl: Add helper routines for setting NVMe completion status
Also includes a few protocol-agnostic wrappers for setting a generic
status (such as success) for a CTL I/O request whether it be SCSI or
NVMe.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44718
2024-05-02 16:31:20 -07:00
John Baldwin 59657816b9 ctl: Add structure and related constants for NVMe commands
This includes static inline functions to serve as getters/setters for
fields shared between SCSI and NVMe I/O requests to manage data
buffers.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44717
2024-05-02 16:31:11 -07:00
John Baldwin ac7a514e20 ctl: Add CTL_IO_ASSERT wrapper macro
Currently, this pattern is commonly used to assert that a union ctl_io
is a SCSI request.  In the future it will be used to assert other
types.

Suggested by:	imp
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44844
2024-05-02 16:30:44 -07:00
John Baldwin 352cf4a64a ctl: Avoid an upcast for calling ctl_scsi_path_string
Change the first argument of ctl_scsi_path_string to be the embedded
header structure instead of the union.  Currently union ctl_io and
struct ctl_scsiio have the same alignment, but this changes on i386 if
a new union member is added that contains a uint64_t member (such as
an embedded struct nvme_command for NVMeoF).  In that case, union
ctl_io requires stronger alignment, so the upcast from struct
ctl_scsiio to union ctl_io in ctl_scsi_sense_sbuf raises an increasing
alignment warning on i386.

Avoid the warning by passing struct ctl_io_hdr as the first argument
to ctl_scsi_path_string instead.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44716
2024-05-02 16:30:20 -07:00
John Baldwin 07c6a62bab cam: Add a XPORT_NVMF for NVMe over Fabrics sims
Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44713
2024-05-02 16:29:26 -07:00
Warner Losh d21c19d412 cam/iosched: Document latency buckets correctly.
Document how latency buckets are actually computed: They are a doubling
from 20us to 10.485s by default, but based at
kern.cam.iosched.bucket_base_us and increase with a ratio of
kern.cam.iosched.bucket_ration / 100 from one to the next.

Sponsored by:		Netflix
2024-05-02 16:02:04 -06:00
HP van Braam 86fbb05da1 ctl: Fix CTL GET EVENT STATUS NOTIFICATION valid bits
Linux as an initiator periodically sends the following to SCSI cdrom
devices: 4a 01 00 00 10 00 00 00 08 00

According to the ctl_cmd_entry for this command this is invalid which
leads to a lot of failed SCSI commands.

The mask in this commit is based off of an early draft of the mmc
standard, https://www.t10.org/ftp/t10/document.97/97-108r0.pdf,
as well as subsequent standards (mmc2 through mmc6).

This solves the issue with Linux initiators.

Signed-off-by: HP van Braam <hp@tmm.cx>
Reviewed by: imp, mav
Pull Request: https://github.com/freebsd/freebsd-src/pull/1201
2024-04-29 08:37:30 -06:00
HP van Braam f0e59ecff8 CTL: READ(6) should be allowed on CD devices
DOS ASPI drivers use this, with this change applied it is possible to
load a DOS ASPI CDROM driver and run the Windows 98 installer.

Signed-off-by: HP van Braam <hp@tmm.cx>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1202
2024-04-25 20:31:14 -06:00
Alexander Motin 7c667affb7 CTL: Drop Format Device and Rigid Disk Geometry mode pages
Those mode pages are obsolete since SBC-2 specification almost 20
years ago.  First I was trying to understand possible relations
between physical block and physical sector terms in different specs.
Then was thinking about possible relations to device CHS geometry
and compatibility issues.  Finally I just decided that none of it
worth the efforts and should rest in piece.

PR:	276524
2024-02-27 13:28:44 -05:00
Andriy Gapon b7dce5b8e9 scsi_da: add 4K quirks for Samsung SSD 860 and 870
Although the actual flash page size is either 8K or 16K for those
devices (according to different sources of various reliability), they
seem to be optimized for the "industry-standard" emulated 4K block size.

To do: consolidate very similar Samsung SSD entries for 830 - 870
models.

MFC after:	2 weeks
2024-02-19 12:16:47 +02:00
Andriy Gapon c01af41c3c ata_da: add quirk to disable NCQ TRIM for Samsung 860/870 SSDs
NCQ TRIM for Samsung 860/870 SSDs results in data corruption on systems
with some SATA controllers.

This can be easily reproduced using ZFS which uses TRIM and is able to
detect block content changes.

Linux bug report for this issue:
 https://bugzilla.kernel.org/show_bug.cgi?id=201693

Since at present we can not limit a quirk based on the contorller / SIM,
apply the quirk in all cases.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43961
2024-02-19 12:08:12 +02:00
Warner Losh a6cef61766 ada: Another NCQ Trim instability drive
The Seagate IronWolf 110 SATA SSD drive has been reported to be unstable
with NCQ trim enabled.

PR: 264139
Sponsored by:		Netflix
2024-02-18 22:18:38 -07:00
Dan Kotowski 9cc816c255 Fix typo in da flags reporting
ANNOUCNED -> ANNOUNCED

Reviewed by:		imp
Differential Revision:	https://reviews.freebsd.org/D41948
2024-02-13 10:44:59 -07:00
John Baldwin eb86c6c5b4 cam: Check if cam_simq_alloc fails for the xpt bus during module init
This is very unlikely to fail (and if it does, CAM isn't going to work
regardless), but fail with an error rather than a gauranteed panic via
NULL pointer dereference.

PR:		276770
Reported by:	Qiushi <w290680224@gmail.com>
2024-02-09 11:53:43 -08:00
Mark Johnston 0c0ec5c8cc scsi_cd: Remove commented-out code
This is left over from before the implementation of asynchronous media
probing, which was committed in dd78f43259
("scsi_cd: make the media check asynchronous") quite a while ago now.

No functional change intended.

MFC after:	1 week
Reviewed by:	imp, avg
Differential Revision:	https://reviews.freebsd.org/D43650
2024-01-30 09:26:03 -05:00
Mark Johnston c961afe825 scsi_cd: Maintain a periph reference during media checks
Otherwise nothing prevents the asynchronous media check state machine
from running after the periph has been destroyed, which can result in a
double free.  Acquire the reference even when performing a synchronous
check, since that doesn't hurt and keeps things simpler.

PR:		276251
Reviewed by:	imp
Fixes:		dd78f43259 ("scsi_cd: make the media check asynchronous")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43525
2024-01-30 09:24:55 -05:00
Mark Johnston b1710124ff scsi_cd: Use a bool for the second parameter of cdcheckmedia()
No functional change intended.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43525
2024-01-30 09:24:36 -05:00
John Baldwin 2cb78e7150 nda: Use the NVMEV macro instead of expanded versions
Reviewed by:	chuck
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43596
2024-01-29 10:33:39 -08:00
Mark Johnston 904cd456f0 targ: Handle errors from suword()
In targstart() we are already handling an error and have no go way to
signal the failure to upper layers, so ignore the return value of
suword() there.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43202
2024-01-04 08:39:53 -05:00
Mark Johnston d068ea16e3 cam: Let cam_periph_unmapmem() return an error
As of commit b059686a71, cam_periph_unmapmem() can legitimately fail
if the copyout() operation fails.  However, this failure was never
signaled to upper layers.  In practice it is unlikely to occur
since cap_periph_mapmem() would most likely fail in such
circumstances anyway, but an error is nonetheless possible.

However, some code reading revealed a few paths where the return value
of cam_periph_mapmem() is not checked, and this is definitely a bug.
Add error checking there and let cam_periph_unmapmem() return errors
from copyout().

Reviewed by:	dab, mav
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43201
2023-12-28 12:36:15 -05:00
Mark Johnston 46a6cfee1b sa: Make sa_param_table[] const and static
No functional change intended.

Reviewed by:	ken, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43204
2023-12-27 20:28:25 -05:00
Mark Johnston 4d3c234d8e sa: Check for errors from copyout()
This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	ken
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43203
2023-12-27 20:28:25 -05:00
John Baldwin 105eee97b0 ctl: Add missing comma after CTL_FLAG_ALREADY_DONE
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42930
2023-12-27 10:09:52 -08:00
John Baldwin dfbb6f2e59 ctl_frontend.h: Note that ctl_port.frontend is set by the FETD
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42931
2023-12-27 10:09:40 -08:00
John Baldwin e03e77ba4d ctl: Always return errno values from ctl_port_register
Return EBUSY instead of a bare 1 if a port number is already active.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42929
2023-12-27 10:09:24 -08:00
Mark Johnston 771501e96f ses: Add error checking for copyout() calls
This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	mav, imp, asomers
Tested by:	asomers
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43130
2023-12-25 21:04:00 -05:00
Warner Losh 0f83811158 cam: Make cam.h self-contained for userland
We reference FILE * here, but don't include stdio.h. Do so (both of
these are in !_KERNEL blocks).

Sponsored by:		Netflix
2023-11-30 18:32:39 -07:00
Warner Losh 54521a6fe6 cam: Remove prototype for cam_sim_alloc_dev
The implementation was removed in dcd5dea965, but the prototype was
not. Correct that oversight.

Fixes: dcd5dea965
Sponsored by:		Netflix
2023-11-30 18:32:39 -07:00
Gleb Smirnoff cfb1e92912 sockets: don't malloc/free sockaddr memory on accept(2)
Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient.  Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do.  Linux also does that. Update tests accordingly.

Reviewed by:		rscheff, tuexen, zlei, dchagin
Differential Revision:	https://reviews.freebsd.org/D42635
2023-11-30 08:30:55 -08:00
Mitchell Horne 9d61fd0849 ctl_ha: don't shutdown threads if scheduler is stopped
In this case, just return.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42341
2023-11-23 12:07:42 -04:00
Alexander Motin 519b24f029 CAM: Replace random sbuf_printf() with cheaper cat/putc. 2023-11-22 18:04:05 -05:00
Alexander Motin 1b44079584 CAM: Use sbuf_new_for_sysctl() in more places
There is no need to allocate buffer, worry about overflows, etc.

MFC after:	2 weeks
2023-11-22 15:33:48 -05:00
Alexander Motin 6332e0f1a4 CAM: Remove return value from xpt_path_sbuf()
It is wrong to call sbuf_len() on third-party sbuf.  If that sbuf
has a drain function, it ends up in assertion.  But even would it
work, it would return not newly written length, but the full one.
Searching through the sources I don't see this value used.
2023-11-22 15:10:57 -05:00
Alexander Motin d282baddb0 Add interface NVME to devstat
This allows to list only NVMe devices in systat, iostat, vmstat, etc.
Previously those were counted as OTHER.
2023-11-15 23:03:40 -05:00