]> www.infradead.org Git - nvme.git/commit
nvmet: pci-epf: clear CC and CSTS when disabling the controller
authorDamien Le Moal <dlemoal@kernel.org>
Fri, 11 Apr 2025 01:42:10 +0000 (10:42 +0900)
committerChristoph Hellwig <hch@lst.de>
Wed, 16 Apr 2025 05:37:37 +0000 (07:37 +0200)
commitf8e01fa93f3e4fc255d240cfa0c045ce0b5c97ea
tree08ac1c51db18ebc456d9dacec94b461459d98fba
parentffe0398c7d6a38af0584d4668d3762b7a97e2275
nvmet: pci-epf: clear CC and CSTS when disabling the controller

When a host shuts down the controller when shutting down but does so
without first disabling the controller, the enable bit remains set in
the controller configuration register. When the host restarts and
attempts to enable the controller again, the
nvmet_pci_epf_poll_cc_work() function is unable to detect the change
from 0 to 1 of the enable bit, and thus the controller is not enabled
again, which result in a device scan timeout on the host. This problem
also occurs if the host shuts down uncleanly or if the PCIe link goes
down: as the CC.EN value is not reset, the controller is not enabled
again when the host restarts.

Fix this by introducing the function nvmet_pci_epf_clear_ctrl_config()
to clear the CC and CSTS registers of the controller when the PCIe link
is lost (nvmet_pci_epf_stop_ctrl() function), or when starting the
controller fails (nvmet_pci_epf_enable_ctrl() fails). Also use this
function in nvmet_pci_epf_init_bar() to simplify the initialization of
the CC and CSTS registers.

Furthermore, modify the function nvmet_pci_epf_disable_ctrl() to clear
the CC.EN bit and write this updated value to the BAR register when the
controller is shutdown by the host, to ensure that upon restart, we can
detect the host setting CC.EN.

Fixes: 0faa0fe6f90e ("nvmet: New NVMe PCI endpoint function target driver")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/pci-epf.c