Skip to content

libnvme: mi: add libnvme_mi_mi_controller_health_status_poll - #4006

Open
drakedog2008 wants to merge 2 commits into
linux-nvme:masterfrom
drakedog2008:ctrl-health-poll
Open

drakedog2008 wants to merge 2 commits into
linux-nvme:masterfrom
drakedog2008:ctrl-health-poll

Conversation

@drakedog2008

Copy link
Copy Markdown
Contributor

Port Controller Health Status Poll changes from linux-nvme/libnvme#1144 to libnvme3.
Implement Controller Health Status Poll (Opcode 02h) defined in NVMe-MI 2.0 (Section 5.3 & 5.3.1) for libnvme3:

  1. mi: add libnvme_mi_mi_controller_health_status_poll:
    • Add nvme_mi_mi_opcode_ctrl_health_status_poll (0x02) to enum nvme_mi_mi_opcode.
    • Add NVME_MI_CSTS_TCIDA to enum nvme_mi_csts and NVME_MI_CHSC_* compatibility aliases.
    • Define struct libnvme_mi_ctrl_health_poll_args with args_size for ABI safety.
    • Implement libnvme_mi_mi_controller_health_status_poll() with automatic multi-request paging when requesting >255 entries.
    • Implement libnvme_mi_mi_controller_health_status_poll_all() convenience helper.
    • Export libnvme_mi_mi_controller_health_status_poll in libnvme-mi.ld (verified by check-public-symbols and check-public-headers).
    • Add unit tests in libnvme/tests/mi.c covering single-entry query, filter flags, multi-page chunk boundaries, and error validation.
  2. examples/mi-mctp: add controller health status support:
    • Update the controllers subcommand in mi-mctp to poll and display controller health status alongside topology and PCI configuration.
    • Add show_chsc_flags() to decode active changed flags (CHSCF).
      Signed-off-by: Hao Jiang jianghao@google.com

@igaw

igaw commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

FTR, we are working on getting the libnvme1 submission in shape first.

@drakedog2008

Copy link
Copy Markdown
Contributor Author

Following the review on linux-nvme/libnvme#1144 (comment), I applied the same struct layout change here: struct nvme_mi_ctrl_health_status now uses __le16 chscf and is __attribute__((packed)). The struct stays 16 bytes and the existing fields keep their offsets.

  • tests/mi.c: added asserts for sizeof() == 16 and offsetof(chscf) == 9, and checks the decoded chscf value.
  • examples/mi-mctp.c: uses le16_to_cpu(chs->chscf).
  • NEWS.md: updated the existing TP6039 entry to note that chscf is a __le16 and the struct is packed (source-level change only).

Add support for the NVMe-MI 2.0 Controller Health Status Poll command
(opcode 0x02) to read Controller Health Data Structures from an NVM
subsystem.

- Add nvme_mi_mi_opcode_ctrl_health_status_poll (0x02) to
  enum nvme_mi_mi_opcode.
- Add NVME_MI_CSTS_TCIDA to enum nvme_mi_csts and NVME_MI_CHSC_*
  compatibility aliases.
- Define struct libnvme_mi_ctrl_health_poll_args to configure command
  parameters (starting controller ID, clear changed flags,
  include/filter flags) and output buffers.
- Implement libnvme_mi_mi_controller_health_status_poll() with automatic
  multi-request paging when more than 255 entries are requested.
- Implement libnvme_mi_mi_controller_health_status_poll_all()
  convenience helper.
- Export libnvme_mi_mi_controller_health_status_poll in libnvme-mi.ld.
- Add unit tests in tests/mi.c covering single-entry query, filter flags,
  multi-page queries, and error parameter validation.

Signed-off-by: Hao Jiang <jianghao@google.com>
Update the controllers subcommand in mi-mctp to display controller
health status alongside controller topology and PCI configuration.

- Poll all controller health entries using
  libnvme_mi_mi_controller_health_status_poll_all().
- Group health information by controller ID inside show_ctrl().
- Add show_chsc_flags() to decode active Controller Health Status
  Changed Flags (CHSCF) whenever the status changed field is non-zero.

Signed-off-by: Hao Jiang <jianghao@google.com>
@drakedog2008

Copy link
Copy Markdown
Contributor Author

Same follow-up as linux-nvme/libnvme#1144: the struct nvme_mi_ctrl_health_status size (16) and chscf offset (9) checks moved out of tests/mi.c into libnvme/src/nvme/mi.c as file-scope _Static_asserts, next to the existing AEM struct asserts.

Comment thread libnvme/src/nvme/mi.h
bool filter_cwarn;
struct nvme_mi_ctrl_health_status *entries;
unsigned int *num_entries;
};

@igaw igaw Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nvme-cli 3 we removed this type of API (struct args) because it is a PITA for ABI stability.

Instead we are using static line function which do not introduce a stable library ABI interface, see nvme-cmds-base.h. I think something like this should be used here as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants