[2/2] nvme: Handle shut down controllers during initialization
Commit Message
According to the spec, controllers need an explicit reset to become
active again after a controller shutdown. Check for this state in
nvme_enable_ctrl and issue an explicit disable if required, which will
trigger the required reset.
Fixes: c76b8308e4c9 ("nvme-apple: fix controller shutdown in apple_nvme_disable")
Signed-off-by: Hector Martin <marcan@marcan.st>
---
drivers/nvme/host/core.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
On Wed, Jan 11, 2023 at 01:36:14PM +0900, Hector Martin wrote:
> According to the spec, controllers need an explicit reset to become
> active again after a controller shutdown. Check for this state in
> nvme_enable_ctrl and issue an explicit disable if required, which will
> trigger the required reset.
I don't think this belongs into nvme_enable_ctrl. It seems like
nvme-apple is missing the equivalent to the nvme_disable_ctrl call
in nvme_pci_configure_admin_queue, though.
@@ -2410,6 +2410,19 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)
if (ret)
return ret;
+ /*
+ * If the controller is enabled but shut down, we need to disable it to
+ * reset it and have it come up. If the controller has completed a
+ * shutdown and is disabled, then we need to clear the shutdown request
+ * and enable it in the same write to CC.
+ * See NVMe Base Spec 2.0c Figure 47.
+ */
+ if (ctrl->ctrl_config & NVME_CC_SHN_MASK && ctrl->ctrl_config & NVME_CC_ENABLE) {
+ ret = nvme_disable_ctrl(ctrl, false);
+ if (ret)
+ return ret;
+ }
+ ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
ctrl->ctrl_config |= NVME_CC_ENABLE;
ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
if (ret)