nvme: merge nvme_shutdown_ctrl into nvme_disable_ctrl
authorChristoph Hellwig <hch@lst.de>
Tue, 8 Nov 2022 10:20:12 +0000 (11:20 +0100)
committerChristoph Hellwig <hch@lst.de>
Tue, 6 Dec 2022 13:36:54 +0000 (14:36 +0100)
Many of the callers decide which one to use based on a bool argument and
there is at least some code to be shared, so merge these two.  Also
move a comment specific to a single callsite to that callsite.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Hector Martin <marcan@marcan.st>
drivers/nvme/host/apple.c
drivers/nvme/host/core.c
drivers/nvme/host/fc.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c
drivers/nvme/host/rdma.c
drivers/nvme/host/tcp.c
drivers/nvme/target/loop.c

index 56d9e9be945b760f189249de2f12b52a49f44df8..e36aeb50b4edc1263654308f59610b28b04253e5 100644 (file)
@@ -829,10 +829,7 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown)
                        apple_nvme_remove_cq(anv);
                }
 
-               if (shutdown)
-                       nvme_shutdown_ctrl(&anv->ctrl);
-               else
-                       nvme_disable_ctrl(&anv->ctrl);
+               nvme_disable_ctrl(&anv->ctrl, shutdown);
        }
 
        WRITE_ONCE(anv->ioq.enabled, false);
index 03b2e34dcf724919591289e469f61165b380a691..30717f7cfc94bcc9c668b986ae52e32c2658148c 100644 (file)
@@ -2279,23 +2279,25 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
        return ret;
 }
 
-/*
- * If the device has been passed off to us in an enabled state, just clear
- * the enabled bit.  The spec says we should set the 'shutdown notification
- * bits', but doing so may cause the device to complete commands to the
- * admin queue ... and we don't know what memory that might be pointing at!
- */
-int nvme_disable_ctrl(struct nvme_ctrl *ctrl)
+int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown)
 {
        int ret;
 
        ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
-       ctrl->ctrl_config &= ~NVME_CC_ENABLE;
+       if (shutdown)
+               ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
+       else
+               ctrl->ctrl_config &= ~NVME_CC_ENABLE;
 
        ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
        if (ret)
                return ret;
 
+       if (shutdown) {
+               return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK,
+                                      NVME_CSTS_SHST_CMPLT,
+                                      ctrl->shutdown_timeout, "shutdown");
+       }
        if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY)
                msleep(NVME_QUIRK_DELAY_AMOUNT);
        return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0,
@@ -2369,21 +2371,6 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)
 }
 EXPORT_SYMBOL_GPL(nvme_enable_ctrl);
 
-int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl)
-{
-       int ret;
-
-       ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
-       ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
-
-       ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
-       if (ret)
-               return ret;
-       return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, NVME_CSTS_SHST_CMPLT,
-                              ctrl->shutdown_timeout, "shutdown");
-}
-EXPORT_SYMBOL_GPL(nvme_shutdown_ctrl);
-
 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl)
 {
        __le64 ts;
index 42fa450187f87a9967d3e4f7257dbc25c66654ec..bb89c7f7196aeb2cf09371317b27852549b811da 100644 (file)
@@ -2518,7 +2518,7 @@ __nvme_fc_abort_outstanding_ios(struct nvme_fc_ctrl *ctrl, bool start_queues)
         * Other transports, which don't have link-level contexts bound
         * to sqe's, would try to gracefully shutdown the controller by
         * writing the registers for shutdown and polling (call
-        * nvme_shutdown_ctrl()). Given a bunch of i/o was potentially
+        * nvme_disable_ctrl()). Given a bunch of i/o was potentially
         * just aborted and we will wait on those contexts, and given
         * there was no indication of how live the controlelr is on the
         * link, don't send more io to create more contexts for the
index e01fa9f696faecf696340c459ab5a98e0eef6043..2cad9f6f2282cdd73cb92ac6550aebc4cf1b168d 100644 (file)
@@ -733,9 +733,8 @@ void nvme_cancel_tagset(struct nvme_ctrl *ctrl);
 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl);
 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
                enum nvme_ctrl_state new_state);
-int nvme_disable_ctrl(struct nvme_ctrl *ctrl);
+int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown);
 int nvme_enable_ctrl(struct nvme_ctrl *ctrl);
-int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
                const struct nvme_ctrl_ops *ops, unsigned long quirks);
 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
index ac734c8f6640e5b5a84c0fbd89bdc0438bc83cc6..84226dce9b3b92cadd6b65d62bf8558acc735c44 100644 (file)
@@ -1500,11 +1500,7 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
 {
        struct nvme_queue *nvmeq = &dev->queues[0];
 
-       if (shutdown)
-               nvme_shutdown_ctrl(&dev->ctrl);
-       else
-               nvme_disable_ctrl(&dev->ctrl);
-
+       nvme_disable_ctrl(&dev->ctrl, shutdown);
        nvme_poll_irqdisable(nvmeq);
 }
 
@@ -1819,7 +1815,14 @@ static int nvme_pci_configure_admin_queue(struct nvme_dev *dev)
            (readl(dev->bar + NVME_REG_CSTS) & NVME_CSTS_NSSRO))
                writel(NVME_CSTS_NSSRO, dev->bar + NVME_REG_CSTS);
 
-       result = nvme_disable_ctrl(&dev->ctrl);
+       /*
+        * If the device has been passed off to us in an enabled state, just
+        * clear the enabled bit.  The spec says we should set the 'shutdown
+        * notification bits', but doing so may cause the device to complete
+        * commands to the admin queue ... and we don't know what memory that
+        * might be pointing at!
+        */
+       result = nvme_disable_ctrl(&dev->ctrl, false);
        if (result < 0)
                return result;
 
index 448abf8cdf1f6e8b5a0b82554208b70cb3134e85..cc61a1b8311b16b638296c21ac8c572f99a96fe4 100644 (file)
@@ -2208,10 +2208,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)
 {
        nvme_rdma_teardown_io_queues(ctrl, shutdown);
        nvme_quiesce_admin_queue(&ctrl->ctrl);
-       if (shutdown)
-               nvme_shutdown_ctrl(&ctrl->ctrl);
-       else
-               nvme_disable_ctrl(&ctrl->ctrl);
+       nvme_disable_ctrl(&ctrl->ctrl, shutdown);
        nvme_rdma_teardown_admin_queue(ctrl, shutdown);
 }
 
index 79789daddeac522f05241ed61e48e1b815fb16bf..95e54e9c1bb1fccd904eda581aaa2ec335216dc3 100644 (file)
@@ -2142,10 +2142,7 @@ static void nvme_tcp_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown)
 {
        nvme_tcp_teardown_io_queues(ctrl, shutdown);
        nvme_quiesce_admin_queue(ctrl);
-       if (shutdown)
-               nvme_shutdown_ctrl(ctrl);
-       else
-               nvme_disable_ctrl(ctrl);
+       nvme_disable_ctrl(ctrl, shutdown);
        nvme_tcp_teardown_admin_queue(ctrl, shutdown);
 }
 
index 6d176621f46dc6974523d21d6244d3044f1ef38a..0015aed5c16996a59ffc0592eea7475b1312d183 100644 (file)
@@ -401,7 +401,7 @@ static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl)
 
        nvme_quiesce_admin_queue(&ctrl->ctrl);
        if (ctrl->ctrl.state == NVME_CTRL_LIVE)
-               nvme_shutdown_ctrl(&ctrl->ctrl);
+               nvme_disable_ctrl(&ctrl->ctrl, true);
 
        nvme_cancel_admin_tagset(&ctrl->ctrl);
        nvme_loop_destroy_admin_queue(ctrl);