Commit graph

246 commits

Author SHA1 Message Date
Warner Losh 3d966ae789 nvmecontrol: Appease a meaningless signed error warning thing
Consistently use the weird ssize_t type for things I know are unsigned,
but which none-the-less need to be compared to signed things to prevent
a bogus warning. Sigh, these aren't bugs, can't possibly be bugs and
a waste of time to fix.

Sponsored by:		Netflix
2024-05-11 13:03:29 -06:00
Warner Losh c1fccf0f60 nvmecontrol: Implement telemetry-log command.
This produces the same data as the Linux nvme-cli 'nvme telemetry-log'
command. It extracts the telemetry log from drive. This is a variable
length log, so we read the first page and find out how much of the log
to grab. There's 3 levels of details available, and we grab the level of
detail specified on the command line.

Sponsored by:		Netflix
2024-05-11 12:09:51 -06:00
John Baldwin 1662e47d91 nvmecontrol: Free the addrinfo list when failing to open a TCP socket
Reported by:	Coverity Scan
CID:	 	1545048
Sponsored by:	Chelsio Communications
2024-05-10 09:13:40 -07:00
John Baldwin 0ac468c7b6 nvmecontrol: Free array of I/O queue pairs on failure to handoff
This is harmless but cleaner.

Reported by:	Coverity Scan
CID:	 	1545041,1545049
Sponsored by:	Chelsio Communications
2024-05-10 09:13:21 -07:00
John Baldwin bf1820f187 nvmecontrol: Fix a sizeof mismatch
In this case it is harmless since it is an array of pointers so the
resulting length is identical.

Reported by:	Coverity Scan
CID:		1545055
Sponsored by:	Chelsio Communications
2024-05-10 08:54:02 -07:00
John Baldwin c8703409ed nvmecontrol: Fix a sign compare mismatch
Even though mqes (uint16_t) and queue_size (u_int) are both unsigned,
the expression 'mqes + 1' gets promoted to int which is signed.  Keep
the value unsigned by explicitly promoting mqes to u_int before
incrementing the value.

Reported by:	GCC
2024-05-07 13:54:00 -07:00
John Baldwin 1058c12197 nvmecontrol: New commands to support Fabrics hosts
- discover: Connects to a remote Discovery controller, fetches its
  Discovery Log Page, and enumerates the remote controllers described
  in the log page.

  The -v option can be used to display the Identify Controller data
  structure for the Discovery controller.  This is only really useful
  for debugging.

- connect: Connects to a remote I/O controller and establishes an
  association of an admin queue and a single I/O queue.  The
  association is handed off to the in-kernel host to create a new
  nvmeX device.

- connect-all: Connects to a Discovery controller and attempts to
  create an association with each I/O controller enumerated in the
  Discovery controller's Discovery Log Page.

- reconnect: Establishes a new association with a remote I/O
  controller for an existing nvmeX device.  This can be used to
  restore access to a remote I/O controller after the loss of a prior
  association due to a transport error, controller reboot, etc.

- disconnect: Deletes one or more nvmeX devices after detaching its
  namespaces and terminating any active associations.  The devices to
  delete can be identified by either a nvmeX device name or the NQN of
  the remote controller.

- disconnect-all: Deletes all active associations with remote
  controllers.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44715
2024-05-02 16:30:10 -07:00
Warner Losh b12cae88cf nvmecontrol: Allow optional /dev/ for device names
nvmecontrol operates on devices. Allow a user to specify the /dev/ if
they want. Any device that starts with / will be treated as if it was a
full path for maximum flexbility.

Sponsored by:		Netflix
2024-05-02 15:52:20 -06:00
Warner Losh ce3b53ffcc nvmecontrol: Flesh out nvmecontrol format information
The format command takes a number of different parameters. Include a
brief summary of what the values mean, though since the driver's support
for metadata is at best weak, 0's are almost always used for values
other than -f format. Add an example that ties it all together.

Sponsored by:		Netflix
Reviewed by:		pauamma@gundo.com, chuck
Differential Revision:	https://reviews.freebsd.org/D44958
2024-04-25 17:47:18 -06:00
Gordon Bergling 6573ce292f nvmecontrol(8): Remove a double word in a source code comment
- s/the the/the/

MFC after:	3 days
2024-04-20 11:18:59 +02:00
Warner Losh 49ea0889f2 nvmecontrol: One file per line
Move to a one file per line setup, and sort the files alphabetically.

Sponsored by:		Netflix
Reviewed by:		chuck, jhb
Differential Revision:	https://reviews.freebsd.org/D44684
2024-04-16 21:30:19 -06:00
Warner Losh 98ab7d0a30 nvmecontrol: Add nvme 2.0 fields to read_logpage
Add the lpo, ot, csi and uuid_index fields to read_logpage. The logpage
command has not been updated to allow these to be specified.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44683
2024-04-16 21:30:19 -06:00
Warner Losh 383a44fc0b nvmecontrol: Preliminary namespace documentation
Provide preliminary namespace subcommand documentation, along with some
basic definitions from the NVM standards relating to namespaces.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D44682
2024-04-16 21:30:19 -06:00
Warner Losh e39873820d nvmecontrol: add newlines where needed for ns command printfs
Sponsored by:		Netflix
Reviewed by:		chuck, jhb
Differential Revision:	https://reviews.freebsd.org/D44681
2024-04-16 21:30:19 -06:00
Warner Losh f0f7e9616d nvmecontrol: Move intel temperature page printing to little endian orderinng
Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44658
2024-04-16 21:30:18 -06:00
Warner Losh 55a1679ece nvmecontrol: Move sanitize status page printing to little endian orderinng
Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44657
2024-04-16 21:30:18 -06:00
Warner Losh 3d28a9c608 nvmecontrol: Move reservation notifcation page printing to little endian orderinng
Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44656
2024-04-16 21:30:18 -06:00
Warner Losh b850caf7b7 nvmecontrol: Move command effeccts page printing to little endian orderinng
Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44655
2024-04-16 21:30:18 -06:00
Warner Losh 98f841efd8 nvmecontrol: Move self test status page printing to little endian orderinng
Also, add printing vnedor_specific field, which doesn't have a valid
bit, so is always valid.

Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44654
2024-04-16 21:30:18 -06:00
Warner Losh acdf72f7bb nvmecontrol: Move namespace change page printing to little endian orderinng
Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44653
2024-04-16 21:30:18 -06:00
Warner Losh 729ee4c88f nvmecontrol: Move smart/health printing to little endian orderinng
Move health printing to little endian ordering...

Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44652
2024-04-16 21:30:18 -06:00
Warner Losh 1c4b7effa7 nvmecontrol: Fix to128 for big endian targets
The source is always 128-bits in little endian format. For big endian
hosts, we have to convert, or we print bogus numbers.

Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44651
2024-04-16 21:30:18 -06:00
Warner Losh e098d24b52 nvmecontrol: Have to truncate on all 32-bit architectures
armv7, powerpc, powerpcspe and i386 all lack 128-bit integer
types. Adjust the comment and #ifdef. I don't think we support nvme on
any of these other architectures at the moment, but it won't hurt to be
more precise.

Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44650
2024-04-16 21:30:17 -06:00
Warner Losh 85656a9a01 nvmecontrol: Make the error log page work on native format
As the number of page types proliferates, it becomes untennable to
convert them in read_logpage (especailly since new UUID page types will
need to be supported). Convert the error page printing code to operate
on little endian data.

Sponsored by:		Netflix
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44680
2024-04-16 21:30:17 -06:00
Warner Losh 67163bc485 nvmecontrol: Create letoh to generically convert to host order
Using _Generic, create letoh which will generically convert uintXX_t
types from little endian to host, regardless of the size. This name has
been floated as a possible addition to endian.h.

Sponsored by:		Netflix
Discussed with:		jhb
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D44649
2024-04-16 21:30:17 -06:00
Warner Losh fe83abacd4 nvme: Add my copyright to logpage.c
Reflect the command line refactoring I did, and other changes. git blame
says I'm to blame for ~1/4 of this file.

Sponsored by:		Netflix
2024-04-05 16:53:47 -06:00
John Baldwin acbc176c3d nvmecontrol: Display additional Fabrics-related fields for cdata
Some of these fields are specific to Fabrics controllers (such as the
size of capsules) while other fields are shared with PCI-e
controllers, but are more relevant for Fabrics controllers (such as
KeepAlive timer properties).

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44449
2024-03-22 17:25:07 -07:00
John Baldwin 1b38f851d8 nvmecontrol: Update the test for a valid firmare revision slot
Reported by:	Coverity Scan
CID:		1539214
Fixes:		7485926e09 nvme: Firmware revisions in the firmware slot info logpage are ASCII strings
2024-03-15 08:18:47 -07:00
John Baldwin 7485926e09 nvme: Firmware revisions in the firmware slot info logpage are ASCII strings
In particular, don't try to byteswap the values as 64-bit integers and
always print a non-empty version as a string.

Reviewed by:	chuck, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44121
2024-03-01 14:18:43 -08:00
Stefan Schlosser 77f6c0ce92 nvmecontrol.8: Fix the SYNOPSIS section
The manpage of nvmecontrol(8) has the following SYNOPSIS:

nvmecontrol format [-f fmt] [-m mset] [-o pi] [-l pil] [-E]
[-C] <device-id | namespace-id>

The correct switch for the pi option is -p according
to sbin/nvmecontrol/format.c:

OPT("pi", 'p', arg_uint32, opt, pi, "Protective information")

So correct the SYNOPSIS section accordingly.

PR:	276554
Reviewed by:	imp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D44099
2024-02-28 09:26:20 +01:00
Yu-Sheng Ma 69f9c5a513
nvmecontrol(8): Fix typo in ns.c
`Insufficient` was spelled wrongly on line 537.

Event:		Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/997
2024-02-13 15:06:22 +08:00
John Baldwin c68ec278de nvmecontrol: Use NVMEF macro to construct fields
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43606
2024-01-29 11:01:46 -08:00
John Baldwin fba73a4083 nvmecontrol: Use the NVMEV macro instead of expanded versions
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43597
2024-01-29 10:34:02 -08:00
Warner Losh 32e86a82f5 sbin: 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
2023-11-26 22:23:59 -07:00
Warner Losh fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Andrius V abe10d21b4 nvmecontrol: fix typos
PR:		261911
Reviewed by:	kp
2023-08-03 12:14:19 +02:00
John Baldwin 39248950a0 nvmecontrol.8: Fix a few formatting nits. 2023-07-13 17:10:36 -07:00
Elyes Haouas 589fe499b7 nvmecontrol: Fix typos
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/653
2023-06-01 20:33:39 -06:00
Alexander Motin f409f11bc5 nvmecontrol: Fix power subcommand output.
The returned value consists of two fields.  Report them separately.

MFC after:	2 weeks
2023-05-15 16:48:50 -04:00
Warner Losh 4d846d260e 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
2023-05-12 10:44:03 -06:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Yuri Pankov 21af4e09f4 nvmecontrol(8): fix resv register -i synopsis
-i is "ignore existing key" and does not take argument

Reviewed by:	pauamma (manpages)
Differential Revision:	https://reviews.freebsd.org/D37709
2023-03-27 15:00:33 +02:00
Yuri Pankov 6aa5b10d0c nvme: fix resv commands with nda device
- passing I/O commands through nda requires nsid field to be set (it was
  unused when going through nvme_ns_ioctl())
- ccb's status can be OR'ed with the flags, use CAM_STATUS_MASK

Reviewed by:	imp (cam)
Differential Revision:	https://reviews.freebsd.org/D37696
2023-03-27 14:53:24 +02:00
Alexander Motin 20dc2c4d11 nvmecontrol: Fix default ns create parameters.
Instead of passing 0xff's for all unset parameters, prefer reasonable
defaults.  It is much easier to use it this was without specs in hand.

MFC after:	1 week
2023-03-09 10:19:00 -05:00
Wanpeng Qian 41be508d31 nvmecontrol: Fix IEEE OUI Identifier output
Current sequence of IEEE OUI Identifier output is wrong.

For Intel, current output is e4 d2 5c, specification is 5CD2E4h
For Samsung, current output is 38 25 00, specification is 002538h
also check with Linux nvme-cli.

Reviewed by:	imp, chuck
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D33856
2022-11-19 19:14:00 -08:00
Wanpeng Qian 0fd43b0c6a
nvmecontrol: Fix condition when print number of Firmware Slots and Firmware Slot1 Readonly.
The Number of Firmware Slots should never be zero. So, a Firmware Slot 1
should always exist. For that reason, always print the Number of
Firmware Slots and the Firmware Slot 1 Read-Only value.

Reviewed by:		imp
Approved by:		manu (mentor)
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D34700
2022-11-15 07:48:20 +01:00
Wanpeng Qian 3a194eac3c nvmecontrol: fix wrong temperature unit for INTEL SSDs.
Although intel's specification did not tell which unit for Temperature
Statistics (Log Identifier C5h), I believe it is based on Celsius
instead of Kelvin.

here is my P3700 SSDs result(before):

Intel Temperature Log
=====================
Current:                        30 K, -243.15 C, -405.67 F
Overtemp Last Flags             0
Overtemp Lifetime Flags         0
Max Temperature                 53 K, -220.15 C, -364.27 F
Min Temperature                 17 K, -256.15 C, -429.07 F
Max Operating Temperature       63 K, -210.15 C, -346.27 F
Min Operating Temperature       0 K, -273.15 C, -459.67 F
Estimated Temperature Offset:   0 C/K
after apply the patch, result is

Intel Temperature Log
=====================
Current:                        303.15 K, 30 C, 86.00 F
Overtemp Last Flags             0
Overtemp Lifetime Flags         0
Max Temperature                 326.15 K, 53 C, 127.40 F
Min Temperature                 290.15 K, 17 C, 62.60 F
Max Operating Temperature       336.15 K, 63 C, 145.40 F
Min Operating Temperature       273.15 K, 0 C, 32.00 F
Estimated Temperature Offset:   0 C/K
I also compare to smartctl's report. it match very well.

also tested on Intel P3600, it fixed the problem.

Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Reviewed by: imp (added tweak to samsung.c so it still compiles)
Differential Revision: https://reviews.freebsd.org/D32845
2022-11-11 12:15:52 -07:00