History log of /freebsd-current/sys/dev/nvd/nvd.c
Revision Date Author Comments
# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# d282badd 15-Nov-2023 Alexander Motin <mav@FreeBSD.org>

Add interface NVME to devstat

This allows to list only NVMe devices in systat, iostat, vmstat, etc.
Previously those were counted as OTHER.


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# c46c9b3f 19-Jul-2022 Dimitry Andric <dim@FreeBSD.org>

Adjust nvd_{load,unload}() definitions to avoid clang 15 warnings

With clang 15, the following -Werror warnings are produced:

sys/dev/nvd/nvd.c:150:9: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
nvd_load()
^
void
sys/dev/nvd/nvd.c:166:11: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
nvd_unload()
^
void

This is because nvd_load() and nvd_unload() are declared with a (void)
argument list, but defined with an empty argument list. Make the
definitions match the declarations.

MFC after: 3 days


# 489ba222 13-May-2022 Mitchell Horne <mhorne@FreeBSD.org>

kerneldump: remove physical argument from d_dumper

The physical address argument is essentially ignored by every dumper
method. In addition, the dump routines don't actually pass a real
address; every call to dump_append() passes a value of zero for
physical.

Reviewed by: markj
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35173


# b8194f37 06-Dec-2021 Warner Losh <imp@FreeBSD.org>

nvd: For AHCI attached devices, report ahci bridge

When an NVME device is attached via a AHCI controller, we have no access
to its config space. So instead of information about the nvme drive
itself, return info about the AHCI controller as the next best
thing. Since the Intel Hardware RAID support looks at these values, this
likely is best.

Sponsored by: Netflix
Reviewed by: mav
Differential Revision: https://reviews.freebsd.org/D33286


# 06e9b422 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

nvd: clean up empty lines in .c and .h files


# e8cc9e1d 12-Aug-2020 Alexander Motin <mav@FreeBSD.org>

Report attachment for nvd same as reported for nda.

MFC after: 1 week


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# 0e8ead28 13-Aug-2019 Alexander Motin <mav@FreeBSD.org>

Add missing break statements in r351004.

Surprisingly code still worked, but thanks imp@ for noticing it.

MFC after: 1 week


# 443b0ad7 13-Aug-2019 Alexander Motin <mav@FreeBSD.org>

Make nvd(4) report NGUID or EUI64 as GEOM::lunid.

With support for multiple namespaces and multiple ports in NVMe there is
now a need for reliable unique namespace identification alike to SCSI.

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


# ca7e89ce 12-Aug-2019 Alexander Motin <mav@FreeBSD.org>

Missed part of r350523.

MFC after: 3 days


# e34c0290 29-Jan-2019 Alexander Motin <mav@FreeBSD.org>

Fix GCC build, failed due to false integer overflow in r343562.

MFC after: 2 weeks


# 56eee7cb 29-Jan-2019 Alexander Motin <mav@FreeBSD.org>

Reimplement BIO_ORDERED handling in nvd(4).

This fixes BIO_ORDERED semantics while also improving performance by:
- sleeping also before BIO_ORDERED bio, as defined, not only after;
- not queueing BIO_ORDERED bio to taskqueue if no other bios running;
- waking up sleeping taskqueue explicitly rather then rely on polling.

On Samsung SSD 970 PRO this shows sync write latency, measured with
`diskinfo -wS`, reduction from ~2ms to ~1.1ms by not sleeping without
reason till next HZ tick.

On the same device ZFS pool with 8 ZVOLs synchronously writing 4KB blocks
shows ~950 IOPS instead of ~750 IOPS before. I suspect ZFS does not need
BIO_ORDERED on BIO_FLUSH at all, but that will be next question.

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


# 4968e1a2 27-Dec-2018 Alexander Motin <mav@FreeBSD.org>

Fix incorrectly inserted copyright in r342557.

Reported by: rgrimes
MFC after: 1 month


# 4d07b689 27-Dec-2018 Alexander Motin <mav@FreeBSD.org>

Reimplement nvd(4) detach handling.

Previous code typically crashed in case of NVMe device unplug or even clean
detach while some I/Os are still in flight. To fix this the new code calls
disk_gone() and waits for confirmation of all references gone before calling
disk_destroy(), freeing other resources and allowing controller detach.

While there, fix disk lists locking and reimplement unit numbers assignment.

MFC after: 1 month
Sponsored by: iXsystems, Inc.


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: 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.


# 8a5d94f9 03-Aug-2017 Warner Losh <imp@FreeBSD.org>

Make nvd vs nda choice boot-time rather than build-time

Introduce hw.nvme.use_nvd tunable. This tunable allows both nvd and
nda to be installed in the kernel, while allowing only one of them to
create devices. This is an all-or-nothing setting, and you can't
change it after boot-time. However, it will allow easier A/B testing.

Differential Revision: https://reviews.freebsd.org/D11825


# 17160457 12-Jan-2017 Alexander Motin <mav@FreeBSD.org>

Report random flash storage as non-rotating to GEOM_DISK.

While doing it, introduce respective constants in geom_disk.h.

MFC after: 1 week


# 3c791011 19-Jul-2016 Scott Long <scottl@FreeBSD.org>

Remove unused variable from last commit.


# 49e20d24 19-Jul-2016 Scott Long <scottl@FreeBSD.org>

Supporting flushing the dump before returning, and simplify/combine the
logic. Switch to a 5us delay since most NVME devices can easily do 200,000
iops.

Submitted by: imp
MFC after: 3 days
Sponsored by: Netflix, Inc.


# a498975e 18-Jul-2016 Scott Long <scottl@FreeBSD.org>

Implement crashdump support on NVME

MFC after: 3 days
Sponsored by: Netflix, Inc.


# ee7f4d81 10-Mar-2016 Alexander Motin <mav@FreeBSD.org>

Revert r292074 (by smh): Limit stripesize reported from nvd(4) to 4K

I believe that this patch handled the problem from the wrong side.
Instead of making ZFS properly handle large stripe sizes, it made
unrelated driver to lie in reported parameters to workaround that.

Alternative solution for this problem from ZFS side was committed at
r296615.

Discussed with: smh


# aeae6079 28-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: add hw.nvd.delete_max tunable

The NVMe specification does not define a maximum or optimal delete
size, so technically max delete size is min(full size of namespace,
2^32 - 1 LBAs). A single delete operation for a multi-TB NVMe
namespace though may take much longer to complete than the nvme(4)
I/O timeout period. So choose a sensible default here that is still
suitably large to minimize the number of overall delete operations.

This also fixes possible uint32_t overflow on initial TRIM operation
for zpool create operations for NVMe namespaces with >4G LBAs.

MFC after: 3 days
Sponsored by: Intel


# 58d0b8f3 07-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: submit bios directly when BIO_ORDERED not set or in flight

This significantly improves parallelism in the most common case.
The taskqueue is still used whenever BIO_ORDERED bios are in flight.

This patch is based heavily on a patch from gallatin@.

MFC after: 3 days
Sponsored by: Intel


# 47ef4244 07-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: break out submission logic into separate function

This enables a future patch using this same logic to submit
I/O directly bypassing the taskqueue.

MFC after: 3 days
Sponsored by: Intel


# 26ca317a 07-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: skip BIO_ORDERED logic when bio fails submission

This ensures the bio flags are not read after biodone().
The ordering will still be enforced, after the bio is
submitted successfully.

MFC after: 3 days
Sponsored by: Intel


# 8fe5c0d2 07-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: do not wait for previous bios before submitting ordered bio

Still wait until all in-flight bios (including the ordered bio)
complete before processing more bios from the queue.

MFC after: 3 days
Sponsored by: Intel


# 454f163b 07-Jan-2016 Jim Harris <jimharris@FreeBSD.org>

nvd: set DISKFLAG_DIRECT_COMPLETION

Submitted by: gallatin
MFC after: 3 days


# fdf16a68 10-Dec-2015 Steven Hartland <smh@FreeBSD.org>

Limit stripesize reported from nvd(4) to 4K

Intel NVMe controllers have a slow path for I/Os that span a 128KB stripe boundary but ZFS limits ashift, which is derived from d_stripesize, to 13 (8KB) so we limit the stripesize reported to geom(8) to 4KB.

This may result in a small number of additional I/Os to require splitting in nvme(4), however the NVMe I/O path is very efficient so these additional I/Os will cause very minimal (if any) difference in performance or CPU utilisation.

This can be controller by the new sysctl kern.nvme.max_optimal_sectorsize.

MFC after: 1 week
Sponsored by: Multiplay
Differential Revision: https://reviews.freebsd.org/D4446


# fdbd3d80 30-Oct-2015 Jim Harris <jimharris@FreeBSD.org>

nvd, nvme: report stripesize through GEOM disk layer

MFC after: 3 days
Sponsored by: Intel


# 70fb74bd 21-Jul-2015 Jim Harris <jimharris@FreeBSD.org>

nvd: set d_delmaxsize to full capacity of NVMe namespace

The NVMe specification has no ability to specify a maximum delete size
that is less than the full capacity of the namespace - so just using the
namespace size is the correct value here.

This fixes reported issues where ZFS trim on init looked like it was
hanging the system - previously the default I/O max size (128KB on
Intel NVMe controllers) was used for delete operations which worked out
to only about 8MB/s. With this patch I can add an 800GB DC P3700
drive to a ZFS pool in about 15-20 seconds.

Reported by: Dylan Just <dylan@techtangents.com>
MFC after: 3 days
Sponsored by: Intel


# a40e72a6 08-Oct-2013 Jim Harris <jimharris@FreeBSD.org>

Add driver-assisted striping for upcoming Intel NVMe controllers that can
benefit from it.

Sponsored by: Intel
Reviewed by: kib (earlier version), carl
Approved by: re (hrs)
MFC after: 1 week


# 38441bd9 19-Jul-2013 Jim Harris <jimharris@FreeBSD.org>

Add message when nvd disks are attached and detached.

As part of this commit, add an nvme_strvis() function which borrows
heavily from cam_strvis(). This will allow stripping of
leading/trailing whitespace and also handle unprintable characters
in model/serial numbers. This function goes into a new nvme_util.c
file which is used by both the driver and nvmecontrol.

Sponsored by: Intel
Reviewed by: carl
MFC after: 3 days


# c3e9dd89 19-Jul-2013 Jim Harris <jimharris@FreeBSD.org>

Do not call disk_create() until we have completed all initialization of our
internal disk structure.

Sponsored by: Intel
Reviewed by: carl
MFC after: 3 days


# e8f25c62 17-Jul-2013 Jim Harris <jimharris@FreeBSD.org>

Define constants for the lengths of the serial number, model number
and firmware revision in the controller's identify structure.

Also modify consumers of these fields to ensure they only use the
specified number of bytes for their respective fields.

Sponsored by: Intel
Reviewed by: carl
MFC after: 3 days


# e9efbc13 09-Jul-2013 Jim Harris <jimharris@FreeBSD.org>

Update copyright dates.

MFC after: 3 days


# 5fdf9c3c 01-Apr-2013 Jim Harris <jimharris@FreeBSD.org>

Add unmapped bio support to nvme(4) and nvd(4).

Sponsored by: Intel


# 237d2019 26-Mar-2013 Jim Harris <jimharris@FreeBSD.org>

Change a number of malloc(9) calls to use M_WAITOK instead of
M_NOWAIT.

Sponsored by: Intel
Suggested by: carl
Reviewed by: carl


# 232e2edb 26-Mar-2013 Jim Harris <jimharris@FreeBSD.org>

Add the ability to internally mark a controller as failed, if it is unable to
start or reset. Also add a notifier for NVMe consumers for controller fail
conditions and plumb this notifier for nvd(4) to destroy the associated
GEOM disks when a failure occurs.

This requires a bit of work to cover the races when a consumer is sending
I/O requests to a controller that is transitioning to the failed state. To
help cover this condition, add a task to defer completion of I/Os submitted
to a failed controller, so that the consumer will still always receive its
completions in a different context than the submission.

Sponsored by: Intel
Reviewed by: carl


# ec84ecbb 26-Mar-2013 Jim Harris <jimharris@FreeBSD.org>

Have nvd(4) register for controller notifications.

Also have nvd maintain controller/namespace relationships internally.

Sponsored by: Intel
Reviewed by: carl


# cf81529c 26-Mar-2013 Jim Harris <jimharris@FreeBSD.org>

Create struct nvme_status.

NVMe error log entries include status, so breaking this out into
its own data structure allows it to be included in both the
nvme_completion data structure as well as error log entry data
structures.

While here, expose nvme_completion_is_error(), and change all of
the places that were explicitly looking at sc/sct bits to use this
macro instead.

Sponsored by: Intel
Reviewed by: carl


# 038a5ee4 26-Mar-2013 Jim Harris <jimharris@FreeBSD.org>

Add an interface for nvme shim drivers (i.e. nvd) to register for
notifications when new nvme controllers are added to the system.

Sponsored by: Intel


# 0f71ecf7 17-Oct-2012 Jim Harris <jimharris@FreeBSD.org>

Add ability to queue nvme_request objects if no nvme_trackers are available.

This eliminates the need to manage queue depth at the nvd(4) level for
Chatham prototype board workarounds, and also adds the ability to
accept a number of requests on a single qpair that is much larger
than the number of trackers allocated.

Sponsored by: Intel


# 9eb93f29 17-Oct-2012 Jim Harris <jimharris@FreeBSD.org>

Add return codes to all functions used for submitting commands to I/O
queues.

Sponsored by: Intel


# 9823d527 10-Oct-2012 Kevin Lo <kevlo@FreeBSD.org>

Revert previous commit...

Pointyhat to: kevlo (myself)


# a10cee30 09-Oct-2012 Kevin Lo <kevlo@FreeBSD.org>

Prefer NULL over 0 for pointers


# bb0ec6b3 17-Sep-2012 Jim Harris <jimharris@FreeBSD.org>

This is the first of several commits which will add NVM Express (NVMe)
support to FreeBSD. A full description of the overall functionality
being added is below. nvmexpress.org defines NVM Express as "an optimized
register interface, command set and feature set fo PCI Express (PCIe)-based
Solid-State Drives (SSDs)."

This commit adds nvme(4) and nvd(4) driver source code and Makefiles
to the tree.

Full NVMe functionality description:
Add nvme(4) and nvd(4) drivers and nvmecontrol(8) for NVM Express (NVMe)
device support.

There will continue to be ongoing work on NVM Express support, but there
is more than enough to allow for evaluation of pre-production NVM Express
devices as well as soliciting feedback. Questions and feedback are welcome.

nvme(4) implements NVMe hardware abstraction and is a provider of NVMe
namespaces. The closest equivalent of an NVMe namespace is a SCSI LUN.
nvd(4) is an NVMe consumer, surfacing NVMe namespaces as GEOM disks.
nvmecontrol(8) is used for NVMe configuration and management.

The following are currently supported:
nvme(4)
- full mandatory NVM command set support
- per-CPU IO queues (enabled by default but configurable)
- per-queue sysctls for statistics and full command/completion queue
dumps for debugging
- registration API for NVMe namespace consumers
- I/O error handling (except for timeoutsee below)
- compilation switches for support back to stable-7

nvd(4)
- BIO_DELETE and BIO_FLUSH (if supported by controller)
- proper BIO_ORDERED handling

nvmecontrol(8)
- devlist: list NVMe controllers and their namespaces
- identify: display controller or namespace identify data in
human-readable or hex format
- perftest: quick and dirty performance test to measure raw
performance of NVMe device without userspace/physio/GEOM
overhead

The following are still work in progress and will be completed over the
next 3-6 months in rough priority order:
- complete man pages
- firmware download and activation
- asynchronous error requests
- command timeout error handling
- controller resets
- nvmecontrol(8) log page retrieval

This has been primarily tested on amd64, with light testing on i386. I
would be happy to provide assistance to anyone interested in porting
this to other architectures, but am not currently planning to do this
work myself. Big-endian and dmamap sync for command/completion queues
are the main areas that would need to be addressed.

The nvme(4) driver currently has references to Chatham, which is an
Intel-developed prototype board which is not fully spec compliant.
These references will all be removed over time.

Sponsored by: Intel
Contributions from: Joe Golio/EMC <joseph dot golio at emc dot com>