]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
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 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>
3 years agotest/mi: Improve test OK reporting, print log data separately
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>
3 years agoioctl: Fixed get log LSP and LSI mask values
Jeff Lien [Thu, 9 Jun 2022 14:44:50 +0000 (09:44 -0500)]
ioctl:  Fixed get log LSP and LSI mask values

Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
3 years agoAdd pkgconfig for libnvme-mi
Hao Jiang [Thu, 24 Mar 2022 23:34:52 +0000 (16:34 -0700)]
Add pkgconfig for libnvme-mi

Signed-off-by: Hao Jiang <jianghao@google.com>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoexamples/mi-mctp: Add identify subcommand
Jeremy Kerr [Thu, 16 Sep 2021 02:58:11 +0000 (10:58 +0800)]
examples/mi-mctp: Add identify subcommand

Now that we have admin command support in libnvme-mi, use the new
partial identify to request basic serial/model/firmware information from
the drive.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomi: Add initial Admin channel commands
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>
3 years agomi: Add NVMe-MI Read MI Data Structure commands for controller and controller list
Jeremy Kerr [Wed, 15 Sep 2021 09:13:44 +0000 (17:13 +0800)]
mi: Add NVMe-MI Read MI Data Structure commands for controller and controller list

Add MI functions perform Read MI Data Structure commands (section 5.6 of
the NVMe-MI v1.1), to retrieve the controller list, and the controller
data.

Use these new functions to extend the mi-mctp example to show controller
info, as a 'controllers' subcommand.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agoexamples/mi-mctp: Add subcommand support
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>
3 years agomi: Add basic tests
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>
3 years agolibnvme-mi: Introduce NVMe Managament Interface library
Jeremy Kerr [Thu, 29 Jul 2021 05:32:51 +0000 (13:32 +0800)]
libnvme-mi: Introduce NVMe Managament Interface library

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>
3 years agoMerge pull request #372 from CodeConstruct/32-bit
Daniel Wagner [Thu, 9 Jun 2022 09:05:31 +0000 (11:05 +0200)]
Merge pull request #372 from CodeConstruct/32-bit

examples: Fix printf format warnings on 32-bit

3 years agoMerge pull request #370 from ankit-sam/master
Daniel Wagner [Thu, 9 Jun 2022 09:04:49 +0000 (11:04 +0200)]
Merge pull request #370 from ankit-sam/master

types.h: add missing fields for identify controller DS

3 years agoMerge pull request #371 from CodeConstruct/optional-cxx
Daniel Wagner [Thu, 9 Jun 2022 08:54:52 +0000 (10:54 +0200)]
Merge pull request #371 from CodeConstruct/optional-cxx

meson: only build test/cpp if a c++ compiler is available

3 years agotypes.h: add missing enum for format nvm attributes
Ankit Kumar [Wed, 8 Jun 2022 17:34:52 +0000 (23:04 +0530)]
types.h: add missing enum for format nvm attributes

Add bit3, format NVM command support nsid value set to
FFFFFFFFh enum and its description.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agotypes.h: add missing enum for optional nvm command
Ankit Kumar [Wed, 8 Jun 2022 17:30:41 +0000 (23:00 +0530)]
types.h: add missing enum for optional nvm command

Add bit 8, NVM command set copy command support enum and
its description.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agotypes.h: add missing description and enum for log page att
Ankit Kumar [Wed, 8 Jun 2022 17:16:35 +0000 (22:46 +0530)]
types.h: add missing description and enum for log page att

1. Add missing description for existing log page attributes.
2. Add bit 5, 6 enum and their respective descriptions.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agotypes.h: add missing enum for firmware updates
Ankit Kumar [Wed, 8 Jun 2022 17:06:04 +0000 (22:36 +0530)]
types.h: add missing enum for firmware updates

Add bit 5, support multiple update detection enum and
its description.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agotypes.h: add missing enum for optional admin command support
Ankit Kumar [Wed, 8 Jun 2022 16:59:16 +0000 (22:29 +0530)]
types.h: add missing enum for optional admin command support

Add bit 10, command and feature lockdown capability enum and
its description.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agotypes.h: Add missing enum for power state descriptor
Ankit Kumar [Wed, 8 Jun 2022 16:49:47 +0000 (22:19 +0530)]
types.h: Add missing enum for power state descriptor

1. Add enum and description for not reported power scale.
2. Add enum and description for power workload.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agoexamples: Fix printf format warnings on 32-bit
Jeremy Kerr [Wed, 8 Jun 2022 05:18:55 +0000 (13:18 +0800)]
examples: Fix printf format warnings on 32-bit

We have a few warnings from mismatched printf format specifiers on
32-bit builds. Use PRIu64 for uint64_t, and %z for size_t.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agomeson: only build test/cpp if a c++ compiler is available
Jeremy Kerr [Tue, 7 Jun 2022 06:59:02 +0000 (14:59 +0800)]
meson: only build test/cpp if a c++ compiler is available

Currently, the meson project configuration specifies both 'c' and 'ccp'
languages. We use the latter to build a single test binary.

This change makes the cpp language optional, so we can compile the rest
of libnvme without a C++ environment.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
3 years agotypes: Add Storage Tag Check IO Control flag
Jeff Lien [Tue, 7 Jun 2022 19:58:13 +0000 (14:58 -0500)]
types: Add Storage Tag Check IO Control flag

Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
3 years agoMerge pull request #353 from igaw/introduce-connection-error-mapping
Daniel Wagner [Fri, 3 Jun 2022 09:42:36 +0000 (11:42 +0200)]
Merge pull request #353 from igaw/introduce-connection-error-mapping

fabrics: Introduce connection connect error mapping

3 years agoMerge pull request #365 from jeffreyalien/master
Daniel Wagner [Fri, 3 Jun 2022 07:24:23 +0000 (09:24 +0200)]
Merge pull request #365 from jeffreyalien/master

ioctl: Fix STC mask for device-self-test command

3 years agoMerge pull request #366 from sc108-lee/export-symbol
Daniel Wagner [Fri, 3 Jun 2022 07:06:40 +0000 (09:06 +0200)]
Merge pull request #366 from sc108-lee/export-symbol

libnvme: export 'nvme_scan_ctrls'

3 years agolibnvme: export 'nvme_scan_ctrls'
Steven Seungcheol Lee [Fri, 3 Jun 2022 06:54:37 +0000 (15:54 +0900)]
libnvme: export 'nvme_scan_ctrls'

For some reason it has been missing from the map file.

Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
3 years agoioctl: Fix STC mask for device-self-test command
Jeff Lien [Thu, 2 Jun 2022 19:50:05 +0000 (14:50 -0500)]
ioctl: Fix STC mask for device-self-test command

Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
3 years agofabrics: Introduce connection connect error mapping
Daniel Wagner [Thu, 14 Apr 2022 11:38:25 +0000 (13:38 +0200)]
fabrics: Introduce connection connect error mapping

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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #362 from ankit-sam/master
Daniel Wagner [Tue, 24 May 2022 13:26:03 +0000 (15:26 +0200)]
Merge pull request #362 from ankit-sam/master

ioctl: nvme_uring_cmd add structure and opcodes

3 years agoMerge pull request #363 from igaw/apply-file-config
Daniel Wagner [Tue, 24 May 2022 13:11:06 +0000 (15:11 +0200)]
Merge pull request #363 from igaw/apply-file-config

Consider file config when adding controller

3 years agoMerge pull request #358 from jeffreyalien/tp-4068-4084
Daniel Wagner [Fri, 20 May 2022 08:21:21 +0000 (10:21 +0200)]
Merge pull request #358 from jeffreyalien/tp-4068-4084

Changes to support TP 4068 and TP 4084

3 years agodoc: Add function nvme_init_copy_range_f1 doc
Jeff Lien [Mon, 16 May 2022 21:25:33 +0000 (16:25 -0500)]
doc: Add function nvme_init_copy_range_f1 doc

Signed-off-by: Jeff Lien <jeff.lien@wdc.com>
3 years agolibnvme: 64-bit Reference Tags and TP-4068 changes
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>
3 years agoioctl: nvme_uring_cmd add structure and opcodes
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.

Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
3 years agofabrics: Consider config from file when adding new controller
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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agotree: Factor lookup code for controller
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.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agolibnvme: Export nvme_ctrl_get_config
Daniel Wagner [Thu, 19 May 2022 08:41:27 +0000 (10:41 +0200)]
libnvme: Export nvme_ctrl_get_config

We missed to export the nvme_ctrl_get_config() function in
version 1.0.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agoMerge pull request #361 from igaw/clarify-license
Hannes Reinecke [Tue, 17 May 2022 15:02:24 +0000 (17:02 +0200)]
Merge pull request #361 from igaw/clarify-license

Clarify license and add missing SPDX identifiers

3 years agomeson: Use SPDX identifier as license text
Daniel Wagner [Tue, 17 May 2022 14:01:23 +0000 (16:01 +0200)]
meson: Use SPDX identifier as license text

First it is recommended to use SPDX identifiers for the version field
and second it clarifies which LGPL version this project is using.

While at it, also use the SPDX identifier in the README.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agotreewide: Add SPDX identifier
Daniel Wagner [Tue, 17 May 2022 13:49:24 +0000 (15:49 +0200)]
treewide: Add SPDX identifier

Add the SPDX identifer with the projects default license choice.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
3 years agolog: Change license to LGPL-2.1-or-later
Daniel Wagner [Tue, 17 May 2022 13:48:14 +0000 (15:48 +0200)]
log: Change license to LGPL-2.1-or-later

Change the license to LGPL-2.1-or-later to match with the projects
license.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Hannes Reinecke <hare@suse.de>
3 years agolicenses: Remove old dir from initial ccan import
Daniel Wagner [Tue, 17 May 2022 13:34:00 +0000 (15:34 +0200)]
licenses: Remove old dir from initial ccan import

The ccan directory has been moved to nvme-cli/ccan including the
initial location of licenses. Remove stale directory.

Signed-off-by: Daniel Wagner <dwagner@suse.de>