Matt Johnston [Tue, 30 Nov 2021 04:46:50 +0000 (12:46 +0800)]
mi: Add facility to scan MI endpoints from MCTP daemon
This change adds support for querying a local MCTP daemon ("mctpd")
instance over its D-Bus interface, to populate the list of available
enpoints in root->endpoints.
This requires libsystemd for sdbus, if not available the
nvme_mi_scan_mctp() will always return failure at runtime.
Update for v1.x root API by Jeremy Kerr <jk@codeconstruct.com.au>.
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Tue, 21 Jun 2022 08:47:18 +0000 (16:47 +0800)]
mi: free endpoints on root destruction
The root_t object needs to persist through the lifetime of an endpoint,
so close the endpoints on nvme_mi_free_root, and track allocated
endpoints in the root->endpoints list.
To do the destruction safely, we need a _safe variant of the endpoint
iterator macro.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Matt Johnston [Tue, 21 Jun 2022 08:12:46 +0000 (16:12 +0800)]
mi: provide a facility for transports to describe endpoints
This change adds a callback to struct nvme_mi_transport, allowing
transports to way to describe the endpoint as a human-readable string.
We call this in a new API function, nvme_mi_endpoint_desc(), which has a
fallback implementation if no callback is provided.
[split out from a previous patch by Jeremy Kerr, test added]
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Thu, 23 Jun 2022 11:35:25 +0000 (19:35 +0800)]
test: define separate library for MI unit tests
We previously exposed a couple of internal functions for libnvme-mi.so
in ce4a044720. However, Daniel Wagner has suggest instead using a
separate shared library with all symbols visible, just for the unit
test.
This change reverts the symbol visibility changes for the installed
libnvme-mi.so, and defines a separate, non-installed library for the MI
unit tests. This is the same as libnvme-mi.so, but has no linker script
or versioning information.
This means we're not exposing the init_ep and crc32 functions in the
actual .so, but can still allow unit tests to access non-public symbols.
The coverage reports can handle the separate library just fine, as the
coverage data is correlated on the underlying source files.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Thu, 23 Jun 2022 07:37:20 +0000 (15:37 +0800)]
MI: reinstate init_ep and crc32 functions for use in test
Ideally, we would be using the actual implementation of
nvme_mi_init_ep() and nvme_mi_crc32_update for our tests, rather than
open-coding it in the test init.
This change exports nvme_mi_init_ep and nvme_mi_crc32_update from
libnvme-mi.so, but both remain excluded from the headers, as they are
only intended for use in the transport API. This means we can call them
from the tests, but keep somewhat-internal.
We put this into a specific _TEST section of the version script, to keep
separate from the public symbols, and add a comment to suit.
This prevents us from diverging the endpoint init process in our
testcases.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Hannes Reinecke [Wed, 22 Jun 2022 10:28:00 +0000 (12:28 +0200)]
fabrics: Update controller authentication in nvmf_add_ctrl()
When calling merge_config() in nvmf_add_ctrl() the controller
authentication key can't be updated reliably as it may already
been set. So update the controller with the correct key
manually.
Suggested-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Hannes Reinecke <hare@suse.de>
Daniel Wagner [Wed, 22 Jun 2022 06:52:32 +0000 (08:52 +0200)]
test: Remove code dependency for mi test
When generating th coverage report, lcov chokes on the '../src/nvme'
paths prefix:
geninfo: WARNING: GCOV did not produce any data for /home/wagi/work/libnvme-upstream/obj/src/test-mi.p/.._test_mi.c.gcda
We could restructure the project layout, e.g. by moving the test/mi.c
file to the src/nvme direcotry. But that looks ugly and as it turns
out we only really need one function copied over
nvme_mi_crc32_update() to resolve the dependency. The other function
is nvme_mi_init_ep() which we can easily open code.
Obviously, it would be better to fix the path issue for lcov but for
the time being let's go with this.
Daniel Wagner [Mon, 20 Jun 2022 08:07:25 +0000 (10:07 +0200)]
doc: Add kernel-doc to header files
Add missing documentation bits to all header files. This a very
rudimentary and surely needs a to be refined later. But let's first
try to get kernel-doc to report 0 warning/errors so we can actually
detect offenders added by new code.
Jeremy Kerr [Mon, 8 Nov 2021 02:13:18 +0000 (10:13 +0800)]
mi: Add security send & security receive commands
Add functions for the Security Send & Security Receive Admin Channel
commands, and a small example in mi-mctp.
Includes a fix for specifying the security_send data, Reported-by: Hao Jiang <jianghao@google.com> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Mon, 20 Jun 2022 07:29:07 +0000 (15:29 +0800)]
mi: fixes for MI Identify command serialisation
We have a couple of bugs when creating the Identify command message,
particularly on big-endian platforms. In general, we should be
performing endian-conversion on the whole cdw fields, rather than on
individual components, provided we've done the shift operations in the
same manner as the LSB/MSB descriptions in the spec.
We also had a swap of the cdw1 / cdw11 fields; cdw1 should contain the
NSID, cdw11 the CSI and CNS-specific ID.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Mon, 20 Jun 2022 05:10:42 +0000 (13:10 +0800)]
Fix %llx/%lx build warnings on powerpc
powerpc64 uses the int-l64 type definitions, so we get an unsigned long
for our __u64 type. This causes several build warnings when we're
printing with %llx in tests/register.c and example/discover-loop.c, as
it's an unsigned long, not an unsigned long long.
One way to fix this would be to use the PRIx64 definitions from
inttypes.h - however, those are keyed off the __WORDSIZE definition,
essentially:
- and that breaks on x86_64, where our __u64 is an unsigned long long,
and would need %llx.
The powerpc types header does give us an option to use the int-l64
definitions though:
/*
* This is here because we used to use l64 for 64bit powerpc
* and we don't want to impact user mode with our change to ll64
* in the kernel.
*
* However, some user programs are fine with this. They can
* flag __SANE_USERSPACE_TYPES__ to get int-ll64.h here.
*/
#if !defined(__SANE_USERSPACE_TYPES__) && defined(__powerpc64__) && !defined(__KERNEL__)
# include <asm-generic/int-l64.h>
#else
# include <asm-generic/int-ll64.h>
#endif
... and in our case we are in fact fine with this. So, #define
__SANE_USERSPACE_TYPES__ for the two example programs.
We refrain from doing this to the library headers though, as we have no
idea what libnvme users will need for __u64.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Daniel Wagner [Mon, 13 Jun 2022 11:32:32 +0000 (13:32 +0200)]
doc: move update instruction into template
The documentation added in 7fecc4881a3c ("doc: add quickstart and
installation") and 6a9758bbde33 ("doc: update installation doc")
should have been added to the template.
Hannes Reinecke [Fri, 10 Jun 2022 08:19:01 +0000 (10:19 +0200)]
tree: make nvme_ctrl_scan_namespace() idempotent
When issuing a rescan the list of namespaces is not cleared, so
just blindly adding new entries might not yield the expected result.
This patch clears out old entries from the controller namespace list
before adding new ones, ensuring that we only ever have one namespace
with a given name in the list of controller namespaces.
Hannes Reinecke [Fri, 10 Jun 2022 08:19:01 +0000 (10:19 +0200)]
tree: make nvme_subsystem_scan_namespace() idempotent
When issuing a rescan the list of namespaces is not cleared, so
just blindly adding new entries might not yield the expected result.
This patch clears out old entries from the subsystem namespace list
before adding new ones, ensuring that we only ever have one namespace
with a given name in the list of subsystem namespaces.
Hannes Reinecke [Fri, 10 Jun 2022 07:48:03 +0000 (09:48 +0200)]
tree: simplifiy nvme_subsystem_lookup_namespace()
The list of namespaces needs to be considered static, and should
only be changed on a full rescan. So simplify the function to just
return the corresponding namespace entry from the topology tree.
Jeremy Kerr [Fri, 10 Jun 2022 01:41:52 +0000 (09:41 +0800)]
test/mi: Improve test OK reporting, print log data separately
Currently, we have a confusing output for tests (all of which currenly
pass):
$ ./obj/test/test-mi
crc mismatch
$ echo $?
0
This change adds reporting for each test, and separates the nvme_msg log
data from the report:
$ ./obj/test/test-mi
Running test read_mi_data... OK
Running test transport_fail... OK
Running test invalid_crc... OK
--- begin test output
crc mismatch
--- end test output
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Wed, 20 Oct 2021 03:20:39 +0000 (11:20 +0800)]
mi: Add initial Admin channel commands
This change adds Admin Channel commands, and the first admin channel
command to the MI transport: Identify. The admin functions have the
nvme_mi_admin_ prefix.
For this, we need a couple of definitions for Admin-Channel-over-MI
serialisation, and add individual admin commands using those.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Wed, 15 Sep 2021 09:27:30 +0000 (17:27 +0800)]
examples/mi-mctp: Add subcommand support
A future change will introduce further mi commands, and admin channel
commands, so we'll want a way to invoke mi-mctp to perform these
additional commands.
This change introduces an <action> argument, which currently defaults to
the existing 'info' action.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Jeremy Kerr [Tue, 5 Apr 2022 07:51:26 +0000 (15:51 +0800)]
mi: Add basic tests
This change adds a couple of basic tests for the mi infrastrcucture.
To do this, we define a test "transport", which just allows inserting a
custom function as the transport's ->submit callback. Each test is then
a pair of: the test itself, and a callback to implement a specific
response from the test "device".
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
This change adds support for the NVMe-MI protocol, as a secondary
library: libnvme-mi.{a,so,h}. This allows management of NVMe devices,
typically through NVMe Admin Channel commands, transmitted over a
side-band channel - typically MCTP over SMBus.
There's a fair amount of shared structure between the direct-ioctl and
MI channel implementations; for example, the Admin command set is used
mostly as-is over the MI transport. The library is built as separate
.so/.a objects as client applications would typically either use one or
the other. MI-specific functions are added with a 'nvme_mi' prefix.
This change introduces a small set of MI commands using this channel.
We'll extend this to further MI commands in subsequent changes, as well
as implement Admin Channel commands too.
We currently assume a MCTP transport for NVMe-commands, using the new
AF_MCTP socket support in Linux. However, the transport-specific code is
kept somewhat separate, through the internal struct nvme_mi_transport
interface. This allows potential alternative transports in future - for
example in-band PCIe.
Finally, we start a new example application, mi-mctp, which provides
a reference application using the new library.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
The kernel returns status information via error codes. Currently we
map all error codes to ENVME_CONNECT_WRITE if the operation
fails. Some of those error codes should be treated differently, such
as EALREADY which means the connection attempt failed because the
connection is already established.
Many of the error codes are overloaded so we have to guess if they are
actually from the nvme subsystem and not from the write
command. Though in practice it's almost certainly the nvme
subsystem. Still it's a guessing game due the very limited API
between userland and kernel.
Brandon Paupore [Fri, 18 Mar 2022 22:03:56 +0000 (17:03 -0500)]
libnvme: 64-bit Reference Tags and TP-4068 changes
Adds support for expanded reference and storage tags, automatically
placing them into the appropriate bits based on Protection Information
Format and Storage Tag Size. This includes updates to nvme_io_args
expanding the size of the tags and adding these STS and PIF values.
Also adds a new copy range format as defined by the NVMe 2.0 spec, as it
determines the reference/storage tags associated to the range being
copied.
Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com> Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
Anuj Gupta [Thu, 19 May 2022 11:35:21 +0000 (17:05 +0530)]
ioctl: nvme_uring_cmd add structure and opcodes
This adds definition of struct nvme_uring_cmd and
NVME_URING_CMD_IO/NVME_URING_CMD_IO_VEC opcodes. The new structure
definition and opcodes are required for using uring-nvme-passthrough
feature. This feature has been picked for 5.19 kernel.
Daniel Wagner [Thu, 19 May 2022 08:49:40 +0000 (10:49 +0200)]
fabrics: Consider config from file when adding new controller
nvme_read_config() function is attaching the configuration
to tree. But when we create a new controller via nvme_create_ctrl()
and then call nvmf_add_ctrl() we ignore this previously read
in configuration.
Hence lookup if there exist a controller/config and merge into
the fabrics config.
Note, the order of the merge is important. For example we want
the config from the command line to have higher priority
than the one from the config file.
Daniel Wagner [Thu, 19 May 2022 08:44:24 +0000 (10:44 +0200)]
tree: Factor lookup code for controller
nvme_lookup_ctrl() will create a controller if it is not
found. In the case where we really just want the lookup
if a controller is in the tree we are missing a pure
lookup function. Hence factor out the lookup into a internal
function.