]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
3 years agoMerge pull request #422 from martin-belanger/eflag-2
Daniel Wagner [Mon, 11 Jul 2022 12:43:24 +0000 (14:43 +0200)]
Merge pull request #422 from martin-belanger/eflag-2

python: add eflags to discovery log page

3 years agoMerge pull request #421 from martin-belanger/eflag-1
Daniel Wagner [Mon, 11 Jul 2022 12:41:55 +0000 (14:41 +0200)]
Merge pull request #421 from martin-belanger/eflag-1

fabrics: add NCC to nvmf_disc_eflags

3 years agopython: add eflags to discovery log page
Martin Belanger [Mon, 11 Jul 2022 12:26:27 +0000 (08:26 -0400)]
python: add eflags to discovery log page

Python bindings are extended to report the EFLAGS when a discovery
command is issued. This was previously missing.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
3 years agofabrics: add NCC to nvmf_disc_eflags
Martin Belanger [Mon, 11 Jul 2022 12:19:39 +0000 (08:19 -0400)]
fabrics: add NCC to nvmf_disc_eflags

TP8010 defines an additional EFLAG: No CDC Connectivity (NCC)

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
3 years agoMerge pull request #419 from igaw/spell-checking
Daniel Wagner [Fri, 8 Jul 2022 12:12:23 +0000 (14:12 +0200)]
Merge pull request #419 from igaw/spell-checking

Fixing typos and whitespace damage in header files

3 years agonvme: More whitespace cleanup reported by checkpatch
Daniel Wagner [Thu, 7 Jul 2022 16:21:32 +0000 (18:21 +0200)]
nvme: More whitespace cleanup reported by checkpatch

While checkpatch can be very noise, it finds a lot of style
inconsistency. Let's cleanup most of them in the public headers.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agonvme: Whitespace cleanups in header files
Daniel Wagner [Thu, 7 Jul 2022 16:05:47 +0000 (18:05 +0200)]
nvme: Whitespace cleanups in header files

Cleanup whitespace damages with emacs whitespace cleanup tool.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agonvme: Fix typos in header files
Daniel Wagner [Thu, 7 Jul 2022 15:30:39 +0000 (17:30 +0200)]
nvme: Fix typos in header files

A quick run with ispell to fix the obvious typos.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #378 from igaw/fix-nvmf_get_discovery_log
Daniel Wagner [Thu, 7 Jul 2022 09:36:31 +0000 (11:36 +0200)]
Merge pull request #378 from igaw/fix-nvmf_get_discovery_log

fabrics: restructrure nvmf_get_discovery_log

3 years agoMerge pull request #418 from CodeConstruct/mi-retvals
Daniel Wagner [Thu, 7 Jul 2022 09:16:18 +0000 (11:16 +0200)]
Merge pull request #418 from CodeConstruct/mi-retvals

MI:  return value + errno unification

3 years agomi: make return values + errno consistent across error paths
Jeremy Kerr [Thu, 7 Jul 2022 07:06:19 +0000 (15:06 +0800)]
mi: make return values + errno consistent across error paths

This change unifies and documents the error return values for the MI
implementation. This gives us the following semantics:

 - zero on success

 - -1 for errors in the MI communication with an endpoint, with errno
   set accordingly

 - positive values where the MI communication succeeded, but we received
   an error response from the endpoint. The return value will be that
   from the MI response status field, and should correspond to one of
   the nvme_mi_resp_status values.

We add these semantics to the file-level kdoc comments in mi.h.

Most of the changes here are replacing the negative-errno returns:

    return -EIO;

with:

    errno = EIO;
    return -1;

but there are a few slightly-more-involved changes where we need to
preserve errno across a cleanup/log that might clobber it.

For the dbus code in mi-mctp.c, we need to convert the sd_bus convention of
negative-errno values into errno; we can do most of these through the
dbus_err() helper.

Fixes: https://github.com/linux-nvme/libnvme/issues/417
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi-mctp: suppress error on scanning endpoints we already have
Jeremy Kerr [Thu, 7 Jul 2022 08:14:38 +0000 (16:14 +0800)]
mi-mctp: suppress error on scanning endpoints we already have

It's not an error to have an endpoint in our list prior to scanning;
just suppress the duplicate and keep going.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add extended MI response status values
Jeremy Kerr [Thu, 7 Jul 2022 05:55:34 +0000 (13:55 +0800)]
mi: Add extended MI response status values

We'll want to make further use of the MI status values in an upcoming
change, so add the full set of values from NVMe-MI v1.2b.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #415 from CodeConstruct/mi-config
Daniel Wagner [Wed, 6 Jul 2022 10:09:48 +0000 (12:09 +0200)]
Merge pull request #415 from CodeConstruct/mi-config

mi: Add MI configuration commands

3 years agomi: Add examples for MI configuration commands
Jeremy Kerr [Wed, 6 Jul 2022 05:35:22 +0000 (13:35 +0800)]
mi: Add examples for MI configuration commands

Now that we have the MI Get/Set Configuration commands implemented, add
support in examples/mi-mctp to illustrate some basic configuration
interactions.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add MI configuration commands
Jeremy Kerr [Tue, 12 Oct 2021 03:13:58 +0000 (11:13 +0800)]
mi: Add MI configuration commands

This change adds an API to send MI Get / Set Configuration commands to
an endpoint, allowing control of endpoint SMBus frequenct, MCTP MTU and
clearing the subsystem health status bits.

We do this with a new couple of functions:

    int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1,
                              __u32 *nmresp)

    int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1)

The dw0, dw1 and nmresp formats depend on the type of configuration
accessed, which can be a little opaque. Se we add a bunch of helpers
too, to get/set the three configuration params:

    nvme_mi_mi_config_get_smbus_freq(...);
    nvme_mi_mi_config_set_smbus_freq(...);
    nvme_mi_mi_config_get_mctp_mtu(...);
    nvme_mi_mi_config_set_mctp_mtu(...);
    nvme_mi_mi_config_set_health_status_change(...);

[there's no getter for the latter, as this just clears polled bits]

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add types for MI Get/Set Configuration data
Jeremy Kerr [Tue, 12 Oct 2021 03:13:58 +0000 (11:13 +0800)]
mi: Add types for MI Get/Set Configuration data

This change adds the mi-specific types for Get/Set configuration
commands: enum nvme_mi_config_id for the currently-defined IDs, and enum
nvme_mi_config_smbus_freq for the possible SMBus frequency configuration
values.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #413 from CodeConstruct/not-cascading-style-sheets
Daniel Wagner [Mon, 4 Jul 2022 17:08:21 +0000 (19:08 +0200)]
Merge pull request #413 from CodeConstruct/not-cascading-style-sheets

types: fix typo on nvme_mi_ccs definitions in public API

3 years agotypes: fix typo on nvme_mi_ccs definitions in public API
Jeremy Kerr [Sat, 2 Jul 2022 06:22:16 +0000 (14:22 +0800)]
types: fix typo on nvme_mi_ccs definitions in public API

The NVMe-MI spec defines the Composite Controller Status definitions
using the abbreviation CCS. However, the libnvme code (since initial
commit) has used CSS, not CCS (except for CCS_RDY...).

This change fixes the definitions to use the _CCS_ names, and adds a set
of #defines to allow the old names to be used, including for the enum
itself.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #410 from CodeConstruct/mi+mpr
Daniel Wagner [Fri, 1 Jul 2022 09:02:06 +0000 (11:02 +0200)]
Merge pull request #410 from CodeConstruct/mi+mpr

MI: Strict response checking, add support for More Processing Required responses

3 years agomi-mctp: Add support for More Processing Required responses
Jeremy Kerr [Mon, 30 May 2022 07:01:18 +0000 (15:01 +0800)]
mi-mctp: Add support for More Processing Required responses

This change allows the mi-mctp transport to receive "more processing
required" responses from MI commands. When we detect a MPR response, we
keep listening for a subsequent message containing the actual response.

The NVMe-MI spec allows for only one MPR response per request.

To do this, we need to perform explicit tag control for MCTP messaging;
we cannot use the kernel's default tag handling, which would expire the
tag value once we've received the first (MPR) response. Instead, we use
the tag control ioctl()s to allocate tags, and expire once we receive
the final response.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agotest: move test_peer->rx_fn function to transmit path
Jeremy Kerr [Thu, 30 Jun 2022 07:49:12 +0000 (15:49 +0800)]
test: move test_peer->rx_fn function to transmit path

We currently have the peer->rx_fn called after libnvme has sent data to
the NVMe device, as a way for the test to check the sent data and modify
a response accordingly.

However, for testing More Processing Required responses, we will have
two TXes for a single RX. So, move the rx_fn callback to the TX side
(ie, when libnvme calls recvmsg). This allows the test to provide
TX-specific data for each call.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi-mctp: better handling for error/unexpected responses
Jeremy Kerr [Wed, 29 Jun 2022 10:14:51 +0000 (18:14 +0800)]
mi-mctp: better handling for error/unexpected responses

Currently, the mi-mctp transport expects there to be at least a complete
header-sized reply - matching the caller's resp->hdr_size value,
otherwise we consider this a transport failure.

However, Admin command responses have a header that's larger than the
generic error response message, so we should be able to handle response
messages that are just the small header and no payload.

This change reworks the response-buffer handling in the MCTP transport.
Rather than storing the payload and MIC into an extra allocated buffer,
we just lay out the response iovec directly into the header, payload and
MIC buffers, and then handle the short-response cases as needed. This
means we can properly extract the error response, rather than just
having the transport report a generic "header too small" failure itself.

This is at high risk for off-by-one errors, so add tests to cover each
of the possible buffer-arrangement cases.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: check response status after each submit()
Jeremy Kerr [Wed, 29 Jun 2022 08:45:38 +0000 (16:45 +0800)]
mi: check response status after each submit()

Add a few checks to the callers of nvme_mi_submit(), to ensure that the
response status is zero before considering the data valid.

In the existing cases, we'd currently fail for response length
mismatches, but we want to be explicit about the check.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: be pedantic with response message format
Jeremy Kerr [Wed, 29 Jun 2022 07:11:24 +0000 (15:11 +0800)]
mi: be pedantic with response message format

This change adds a few tests to check against invalid response data
received by the NVMe-MI device, and some tests to simulate these
conditions.

Because we're checking more of the response fields, we need a bit more
support for constructing default responses in the mi and mi-mctp tests,
so add that too.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: be pedantic with message sizes and offsets
Jeremy Kerr [Wed, 29 Jun 2022 03:11:26 +0000 (11:11 +0800)]
mi: be pedantic with message sizes and offsets

Check that we have enough data for a base header, and that the lengths
are properly aligned, for both request and response messages.

For the raw admin API, ensure we have correct data lengths and offsets.

Add some tests to suit, using the raw admin API

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge branch 'mi-mctp-test' of https://github.com/CodeConstruct/libnvme
Daniel Wagner [Thu, 30 Jun 2022 11:38:10 +0000 (13:38 +0200)]
Merge branch 'mi-mctp-test' of https://github.com/CodeConstruct/libnvme

Conflicts:
src/nvme/mi-mctp.c

3 years agoMerge pull request #409 from sc108-lee/libsystemd
Daniel Wagner [Thu, 30 Jun 2022 11:03:16 +0000 (13:03 +0200)]
Merge pull request #409 from sc108-lee/libsystemd

meson: libsystemd <= 219 does not support sd-bus, sd-event

3 years agomeson: libsystemd <= 219 does not support sd-bus, sd-event
Steven Seungcheol Lee [Thu, 30 Jun 2022 10:06:46 +0000 (19:06 +0900)]
meson: libsystemd <= 219 does not support sd-bus, sd-event

build error below
./dist-unpack/libnvme-1.0/src/nvme/mi-mctp.c
../dist-unpack/libnvme-1.0/src/nvme/mi-mctp.c:25:10: fatal error: systemd/sd-event.h: No such file or directory
   25 | #include <systemd/sd-event.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
[740/769] Compiling C object src/libnvme.so.1.0.0.p/nvme_tree.c.o

MCTP defined values are used when CONFIG_LIBSYSTEMD is defined

3 years agotest: Add initial tests for mi-mctp layer
Jeremy Kerr [Thu, 16 Jun 2022 06:55:40 +0000 (14:55 +0800)]
test: Add initial tests for mi-mctp layer

This change adds a new test module, for the MCTP transport of the MI
layer.

To do this, we hook into the socket, sendmsg and recvmsg calls from the
core mi-mctp code, allowing the test to provide a mock communication
with the kernel MCTP layer.

On top of this, we write a few simple test cases for the socket error
resonses, which we'll extend in future changes.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agotest: move some common test tools to test/utils.c
Jeremy Kerr [Tue, 28 Jun 2022 06:19:55 +0000 (14:19 +0800)]
test: move some common test tools to test/utils.c

We have a bit of test infrastructure in mi.c that may be helpful for
other tests, so move into a separate file.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agofabrics: don't treat host_traddr 'none' as a valid hostname
Sagi Grimberg [Mon, 27 Jun 2022 08:06:39 +0000 (11:06 +0300)]
fabrics: don't treat host_traddr 'none' as a valid hostname

We treat 'none' as an escape value for optional arguments, do the same
for host_traddr.

This makes prints like the below go away when passing --host-traddr=none:
sh[3244]: failed to resolve host none info

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Link: https://lore.kernel.org/r/20220627080639.108828-1-sagi@grimberg.me
3 years agoMerge pull request #406 from CodeConstruct/mi-ep-scan
Daniel Wagner [Mon, 27 Jun 2022 07:10:19 +0000 (09:10 +0200)]
Merge pull request #406 from CodeConstruct/mi-ep-scan

mi: track controller lifetime under endpoint and provide endpoint scan

3 years agomi: track controller lifetime under endpoint and provide endpoint scan
Jeremy Kerr [Mon, 27 Jun 2022 06:23:53 +0000 (14:23 +0800)]
mi: track controller lifetime under endpoint and provide endpoint scan

This change introduces a list of controllers under each MI endpoint, and
ties the controller's lifetime to the endpoints - when an endpoint is
free()ed, so are its controllers.

We also provide a new function to populate the controllers list:

   nvme_mi_scan_ep()

- which scans the endpoint for its owned controllers. For retrieving the
scan results, we now have a new macro:

   nvme_mi_for_each_ctrl(ep, ctrl) {
     ...
   }

Add a couple of new tests: one to check the lifetime semantics, and
another to test the scan using a fake Read MI Data (Controller List)
response.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agodoc: Workaround kenrel-doc code scanner
Daniel Wagner [Mon, 27 Jun 2022 06:19:47 +0000 (08:19 +0200)]
doc: Workaround kenrel-doc code scanner

The kernel-doc scanner trips over a void function. It will complain
with 'contents before sections'. To help out, explicitly move the
state machine into the next state which avoids the warning.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #405 from CodeConstruct/mi-h
Daniel Wagner [Mon, 27 Jun 2022 06:06:23 +0000 (08:06 +0200)]
Merge pull request #405 from CodeConstruct/mi-h

MI: install top-level libnvme-mi.h header

3 years agoMI: install top-level libnvme-mi.h header
Jeremy Kerr [Mon, 27 Jun 2022 02:58:03 +0000 (10:58 +0800)]
MI: install top-level libnvme-mi.h header

Now that we have a decent amount of the libnvme-mi definitions fairly
stable, add the top-level libnvme-mi.h header to the installed header
set.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #396 from CodeConstruct/mi+scan
Daniel Wagner [Fri, 24 Jun 2022 08:00:13 +0000 (10:00 +0200)]
Merge pull request #396 from CodeConstruct/mi+scan

MI: Add endpoint iterators, and allow scanning from MCTP endpoints on dbus

3 years agodoc: Add MCTP scan details to mi document
Jeremy Kerr [Thu, 23 Jun 2022 06:21:06 +0000 (14:21 +0800)]
doc: Add MCTP scan details to mi document

Add some background information on the scan process, including
dependencies on D-Bus and mctpd.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoexamples/mi-mctp: Add 'dbus' option
Matt Johnston [Tue, 30 Nov 2021 04:48:34 +0000 (12:48 +0800)]
examples/mi-mctp: Add 'dbus' option

This will query for all known endpoints and apply the action to each of
them.

Update to 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>
3 years agomi: Add facility to scan MI endpoints from MCTP daemon
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>
3 years agomi: free endpoints on root destruction
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>
3 years agomi: Add MI endpoints to root_t, and add iterators
Matt Johnston [Tue, 30 Nov 2021 04:44:15 +0000 (12:44 +0800)]
mi: Add MI endpoints to root_t, and add iterators

These can be used to iterate through a set of endpoints. This
will be used for transports such as MCTP's dbus scan functionality

Updated for v1.x by Jeremy Kerr <jk@codeconstruct.com.au>, using global
nvme_root_t as base context.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: provide a facility for transports to describe endpoints
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>
3 years agoMerge pull request #403 from CodeConstruct/mi-cov-visibility
Daniel Wagner [Thu, 23 Jun 2022 11:51:13 +0000 (13:51 +0200)]
Merge pull request #403 from CodeConstruct/mi-cov-visibility

test: define separate library for MI unit tests

3 years agotest: define separate library for MI unit tests
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>
3 years agoMerge pull request #400 from CodeConstruct/mi-test-ep-init
Daniel Wagner [Thu, 23 Jun 2022 08:35:11 +0000 (10:35 +0200)]
Merge pull request #400 from CodeConstruct/mi-test-ep-init

MI: reinstate nvme_mi_init_ep for endpoint initialisation in test

3 years agoMI: reinstate init_ep and crc32 functions for use in test
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>
3 years agoMerge pull request #402 from CodeConstruct/mi-kdoc
Daniel Wagner [Thu, 23 Jun 2022 08:26:24 +0000 (10:26 +0200)]
Merge pull request #402 from CodeConstruct/mi-kdoc

doc: check-in processed mi.rst

3 years agodoc: check-in processed mi.rst
Jeremy Kerr [Thu, 23 Jun 2022 08:18:00 +0000 (16:18 +0800)]
doc: check-in processed mi.rst

It looks like the generated doc output on readthedocs.io requires the
processed .rst output to be present in the repo, so check it in.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #399 from CodeConstruct/mi-kdoc
Daniel Wagner [Thu, 23 Jun 2022 07:21:09 +0000 (09:21 +0200)]
Merge pull request #399 from CodeConstruct/mi-kdoc

MI: Add kernel-doc documentation for MI API

3 years agomi: Add initial mi document
Jeremy Kerr [Thu, 23 Jun 2022 06:05:39 +0000 (14:05 +0800)]
mi: Add initial mi document

Add a base `mi.rst.in` document, for some background information on the
NVMe-MI interface, alongside the new mi API doc.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoworkflows: Add mi.h to documentation format check
Jeremy Kerr [Thu, 23 Jun 2022 04:05:06 +0000 (12:05 +0800)]
workflows: Add mi.h to documentation format check

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add kernel-doc documentation to mi header
Jeremy Kerr [Thu, 23 Jun 2022 02:45:53 +0000 (10:45 +0800)]
mi: Add kernel-doc documentation to mi header

This change adds proper kdoc-style documentation to the mi.h
definitions, and includes mi.h in the docs builds.

No functional change, just comments.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: rename start argument to _read_mi_data_ctrl_list function
Jeremy Kerr [Thu, 23 Jun 2022 03:44:54 +0000 (11:44 +0800)]
mi: rename start argument to _read_mi_data_ctrl_list function

This is a starting controller ID, not a starting port ID, fix the name
to suit.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #398 from hreinecke/ctrl-auth
Daniel Wagner [Wed, 22 Jun 2022 13:30:09 +0000 (15:30 +0200)]
Merge pull request #398 from hreinecke/ctrl-auth

fabrics: Update controller authentication in nvmf_add_ctrl()

3 years agofabrics: Update controller authentication in nvmf_add_ctrl()
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>
3 years agoMerge pull request #397 from igaw/fix-coderage-report
Daniel Wagner [Wed, 22 Jun 2022 07:51:12 +0000 (09:51 +0200)]
Merge pull request #397 from igaw/fix-coderage-report

test: Remove code dependency for mi test

3 years agotest: Remove code dependency for mi test
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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #390 from igaw/update-doc
Daniel Wagner [Tue, 21 Jun 2022 20:03:11 +0000 (22:03 +0200)]
Merge pull request #390 from igaw/update-doc

doc: Add kernel-doc to header files

3 years agodoc: Add kernel-doc to header files
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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #392 from CodeConstruct/mi+admin
Daniel Wagner [Tue, 21 Jun 2022 06:17:10 +0000 (08:17 +0200)]
Merge pull request #392 from CodeConstruct/mi+admin

MI: add further admin commands

3 years agomi: Add security send & security receive commands
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>
3 years agomi: Add direct admin transfer API
Jeremy Kerr [Tue, 2 Nov 2021 02:48:09 +0000 (10:48 +0800)]
mi: Add direct admin transfer API

Callers may want to invoke arbitrary admin commands; so implement a
direct admin API, passing just the Admin request/response header
pointers:

  int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl,
          struct nvme_mi_admin_req_hdr *admin_req,
          size_t req_data_size,
          struct nvme_mi_admin_resp_hdr *admin_resp,
          off_t resp_data_offset,
          size_t *resp_data_size);

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoexamples/mi-mctp: Add Get Log Page example
Jeremy Kerr [Tue, 26 Oct 2021 09:36:42 +0000 (17:36 +0800)]
examples/mi-mctp: Add Get Log Page example

Since we now have the Get Log Page API, add an example to the mi-mctp
utility. This will dump the log page data as hex:

  # mi-mctp 1 9 get-log-page 1
  Get log page (log id = 0x01) data:
  00000000  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
  00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
  00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
  [...]

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add Admin channel Get Log Page command
Jeremy Kerr [Tue, 26 Oct 2021 08:31:14 +0000 (16:31 +0800)]
mi: Add Admin channel Get Log Page command

This change add support for the Get Log Page command over the MI Admin
channel:

  int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl,
 struct nvme_get_log_args *args)

Since the log data can be large, we implement this as chunked transfers
of >4096 bytes.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #389 from CodeConstruct/powerpc
Daniel Wagner [Mon, 20 Jun 2022 12:38:30 +0000 (14:38 +0200)]
Merge pull request #389 from CodeConstruct/powerpc

Fix %llx/%lx build warnings on powerpc

3 years agoMerge pull request #391 from CodeConstruct/mi
Daniel Wagner [Mon, 20 Jun 2022 10:08:34 +0000 (12:08 +0200)]
Merge pull request #391 from CodeConstruct/mi

MI: tests and fixes

3 years agomi: fixes for MI Identify command serialisation
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>
3 years agomi: Add Admin error test
Jeremy Kerr [Thu, 16 Jun 2022 06:54:55 +0000 (14:54 +0800)]
mi: Add Admin error test

Ensure we handle an error response through the Admin command path.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add simple Admin command test
Jeremy Kerr [Mon, 20 Jun 2022 04:51:33 +0000 (12:51 +0800)]
mi: Add simple Admin command test

Add a little test for the MI Admin path, using Identify as a sample
admin function.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: be consistent with mi function prefixes
Jeremy Kerr [Mon, 20 Jun 2022 07:53:28 +0000 (15:53 +0800)]
mi: be consistent with mi function prefixes

We should be using nvme_mi_admin_* for the admin channel functions;
rename nvme_mi_identify_{ctrl,ctrl_list} accordingly.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: remove unused nvme_mi_admin_identify()
Jeremy Kerr [Mon, 20 Jun 2022 07:39:47 +0000 (15:39 +0800)]
mi: remove unused nvme_mi_admin_identify()

We have helpers that use identify_partial for this functionality, and
hadn't exported nvme_mi_admin_identify().

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #388 from CodeConstruct/conf-host-endian-fix
Daniel Wagner [Mon, 20 Jun 2022 06:03:43 +0000 (08:03 +0200)]
Merge pull request #388 from CodeConstruct/conf-host-endian-fix

meson: use host target for defining endianness

3 years agoFix %llx/%lx build warnings on powerpc
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:

    # if __WORDSIZE == 64
    #  define PRIx64 "lx"
    # else
    #  define PRIx64 "llx"
    # endif

- 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>
3 years agomeson: use host target for defining endianness
Jeremy Kerr [Mon, 20 Jun 2022 04:07:22 +0000 (12:07 +0800)]
meson: use host target for defining endianness

We're currently basing the host endian tests on the build_machine; we
should be using host_machine instead.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #387 from jeffreyalien/master
Daniel Wagner [Fri, 17 Jun 2022 16:41:22 +0000 (18:41 +0200)]
Merge pull request #387 from jeffreyalien/master

build: Add api-types.h to install headers

3 years agobuild: Add api-types.h to install headers
Jeff Lien [Fri, 17 Jun 2022 13:51:59 +0000 (08:51 -0500)]
build: Add api-types.h to install headers

Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
3 years agoMerge pull request #386 from CodeConstruct/mi
Daniel Wagner [Fri, 17 Jun 2022 12:39:43 +0000 (14:39 +0200)]
Merge pull request #386 from CodeConstruct/mi

MI: Update MI Admin API to suit core

3 years agoMerge pull request #384 from CodeConstruct/api-types
Daniel Wagner [Fri, 17 Jun 2022 12:35:48 +0000 (14:35 +0200)]
Merge pull request #384 from CodeConstruct/api-types

api: move _args defintions to api-types.h

3 years agoexample: provide an example of both the full and partial identify commands
Jeremy Kerr [Tue, 14 Jun 2022 05:20:26 +0000 (13:20 +0800)]
example: provide an example of both the full and partial identify commands

This change adds a --partial argument to the mi-mctp command, so we have
an example of both the full and partial identify APIs.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: change admin channel functions to use _args structs
Jeremy Kerr [Tue, 14 Jun 2022 05:12:19 +0000 (13:12 +0800)]
mi: change admin channel functions to use _args structs

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #383 from jeffreyalien/stc-control-bit-fix
Daniel Wagner [Tue, 14 Jun 2022 11:41:47 +0000 (13:41 +0200)]
Merge pull request #383 from jeffreyalien/stc-control-bit-fix

Fix/Add Bit Definitions NVMe Commands

3 years agoapi: move _args defintions to api-types.h
Jeremy Kerr [Tue, 14 Jun 2022 01:25:41 +0000 (09:25 +0800)]
api: move _args defintions to api-types.h

This change establishes a new (internal) header, api-types.h, and moves
the existing _args structs from ioctl.h.

This will allow us to share the definitions between the direct-ioctl
and MI interfaces.

The changes are purely a move of the struct definitions, and some
whitespace fixes, and some new file-level comments. None of the structs
are altered.

Fixes https://github.com/linux-nvme/libnvme/issues/373 .

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoMerge pull request #375 from hreinecke/subsys-ns-lookup
Daniel Wagner [Mon, 13 Jun 2022 12:33:36 +0000 (14:33 +0200)]
Merge pull request #375 from hreinecke/subsys-ns-lookup

tree: simplifiy nvme_subsystem_lookup_namespace()

3 years agoMerge pull request #376 from linux-nvme/dependabot/github_actions/actions/setup-python-4
Daniel Wagner [Mon, 13 Jun 2022 12:20:56 +0000 (14:20 +0200)]
Merge pull request #376 from linux-nvme/dependabot/github_actions/actions/setup-python-4

build(deps): bump actions/setup-python from 3 to 4

3 years agobuild(deps): bump actions/setup-python from 3 to 4
dependabot[bot] [Mon, 13 Jun 2022 12:18:28 +0000 (12:18 +0000)]
build(deps): bump actions/setup-python from 3 to 4

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
3 years agoMerge pull request #381 from igaw/add-version-to-setup-python
Daniel Wagner [Mon, 13 Jun 2022 12:17:59 +0000 (14:17 +0200)]
Merge pull request #381 from igaw/add-version-to-setup-python

ci: add python version to setup-python environment

3 years agoci: add python version to setup-python environment
Daniel Wagner [Mon, 13 Jun 2022 12:13:09 +0000 (14:13 +0200)]
ci: add python version to setup-python environment

v4 of the setup-python helper wants to know the python version number.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #380 from igaw/add-kernel-dep-note
Daniel Wagner [Mon, 13 Jun 2022 12:02:15 +0000 (14:02 +0200)]
Merge pull request #380 from igaw/add-kernel-dep-note

README: add note about min kernel version

3 years agoREADME: add note about min kernel version
Daniel Wagner [Mon, 13 Jun 2022 11:54:49 +0000 (13:54 +0200)]
README: add note about min kernel version

The min kernel version is v4.15 kernel because libnvme depends on the
/sys/class/nvme-subsystem interface.

Signed-off-by: Daniel Wagner dwagner@suse.de
3 years agodoc: update Python binding documentation
Daniel Wagner [Mon, 13 Jun 2022 11:53:30 +0000 (13:53 +0200)]
doc: update Python binding documentation

Move the Python documentation into a subsection so we don't mix it with
the main library.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agodoc: move update instruction into template
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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agofabrics: restructrure nvmf_get_discovery_log
Daniel Wagner [Mon, 13 Jun 2022 09:27:45 +0000 (11:27 +0200)]
fabrics: restructrure nvmf_get_discovery_log

Move the initial header read into the do while loop. This simplifies
the loop flow into first read header if there are records fetch them
too.

With this we keep the genctr and numrec in sync for both get log
invocation.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #379 from igaw/fix-libnvme-mi-build
Daniel Wagner [Mon, 13 Jun 2022 11:08:54 +0000 (13:08 +0200)]
Merge pull request #379 from igaw/fix-libnvme-mi-build

ioctl: Add inline to nvme_identify_cns_nsid and nvme_get_log_ana

3 years agoioctl: Add inline to nvme_identify_cns_nsid and nvme_get_log_ana
Daniel Wagner [Mon, 13 Jun 2022 11:05:09 +0000 (13:05 +0200)]
ioctl: Add inline to nvme_identify_cns_nsid and nvme_get_log_ana

Both function should always be inlined.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #76 from jk-ozlabs/mi
Daniel Wagner [Mon, 13 Jun 2022 07:28:17 +0000 (09:28 +0200)]
Merge pull request #76 from jk-ozlabs/mi

Initial NVMe-MI protocol support

3 years agotree: make nvme_ctrl_scan_namespace() idempotent
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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
3 years agotree: make nvme_subsystem_scan_namespace() idempotent
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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
3 years agotree: simplifiy nvme_subsystem_lookup_namespace()
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.

Signed-off-by: Hannes Reinecke <hare@suse.de>