Skip to content

Commit 94cc781

Browse files
author
Christoph Hellwig
committed
nvme: move OPAL setup from PCIe to core
Nothing about the TCG Opal support is PCIe transport specific, so move it to the core code. For this nvme_init_ctrl_finish grows a new was_suspended argument that allows the transport driver to tell the OPAL code if the controller came out of a suspend cycle. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: James Smart <[email protected]> Tested-by Gerd Bayer <[email protected]>
1 parent 1e37a30 commit 94cc781

File tree

8 files changed

+29
-25
lines changed

8 files changed

+29
-25
lines changed

drivers/nvme/host/apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ static void apple_nvme_reset_work(struct work_struct *work)
11021102
goto out;
11031103
}
11041104

1105-
ret = nvme_init_ctrl_finish(&anv->ctrl);
1105+
ret = nvme_init_ctrl_finish(&anv->ctrl, false);
11061106
if (ret)
11071107
goto out;
11081108

drivers/nvme/host/core.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ const struct pr_ops nvme_pr_ops = {
21922192
};
21932193

21942194
#ifdef CONFIG_BLK_SED_OPAL
2195-
int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
2195+
static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
21962196
bool send)
21972197
{
21982198
struct nvme_ctrl *ctrl = data;
@@ -2209,7 +2209,23 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
22092209
return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len,
22102210
NVME_QID_ANY, 1, 0);
22112211
}
2212-
EXPORT_SYMBOL_GPL(nvme_sec_submit);
2212+
2213+
static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)
2214+
{
2215+
if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) {
2216+
if (!ctrl->opal_dev)
2217+
ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit);
2218+
else if (was_suspended)
2219+
opal_unlock_from_suspend(ctrl->opal_dev);
2220+
} else {
2221+
free_opal_dev(ctrl->opal_dev);
2222+
ctrl->opal_dev = NULL;
2223+
}
2224+
}
2225+
#else
2226+
static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)
2227+
{
2228+
}
22132229
#endif /* CONFIG_BLK_SED_OPAL */
22142230

22152231
#ifdef CONFIG_BLK_DEV_ZONED
@@ -3242,7 +3258,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
32423258
* register in our nvme_ctrl structure. This should be called as soon as
32433259
* the admin queue is fully up and running.
32443260
*/
3245-
int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
3261+
int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended)
32463262
{
32473263
int ret;
32483264

@@ -3273,6 +3289,8 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
32733289
if (ret < 0)
32743290
return ret;
32753291

3292+
nvme_configure_opal(ctrl, was_suspended);
3293+
32763294
if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) {
32773295
/*
32783296
* Do not return errors unless we are in a controller reset,
@@ -5007,6 +5025,7 @@ static void nvme_free_ctrl(struct device *dev)
50075025
nvme_auth_stop(ctrl);
50085026
nvme_auth_free(ctrl);
50095027
__free_page(ctrl->discard_page);
5028+
free_opal_dev(ctrl->opal_dev);
50105029

50115030
if (subsys) {
50125031
mutex_lock(&nvme_subsystems_lock);

drivers/nvme/host/fc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
31073107

31083108
nvme_start_admin_queue(&ctrl->ctrl);
31093109

3110-
ret = nvme_init_ctrl_finish(&ctrl->ctrl);
3110+
ret = nvme_init_ctrl_finish(&ctrl->ctrl, false);
31113111
if (ret || test_bit(ASSOC_FAILED, &ctrl->flags))
31123112
goto out_disconnect_admin_queue;
31133113

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
736736
void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
737737
void nvme_start_ctrl(struct nvme_ctrl *ctrl);
738738
void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
739-
int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl);
739+
int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended);
740740
int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
741741
const struct blk_mq_ops *ops, unsigned int flags,
742742
unsigned int cmd_size);
@@ -748,9 +748,6 @@ void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl);
748748

749749
void nvme_remove_namespaces(struct nvme_ctrl *ctrl);
750750

751-
int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
752-
bool send);
753-
754751
void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
755752
volatile union nvme_result *res);
756753

drivers/nvme/host/pci.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,6 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
27722772
nvme_free_tagset(dev);
27732773
if (dev->ctrl.admin_q)
27742774
blk_put_queue(dev->ctrl.admin_q);
2775-
free_opal_dev(dev->ctrl.opal_dev);
27762775
mempool_destroy(dev->iod_mempool);
27772776
put_device(dev->dev);
27782777
kfree(dev->queues);
@@ -2866,21 +2865,10 @@ static void nvme_reset_work(struct work_struct *work)
28662865
*/
28672866
dev->ctrl.max_integrity_segments = 1;
28682867

2869-
result = nvme_init_ctrl_finish(&dev->ctrl);
2868+
result = nvme_init_ctrl_finish(&dev->ctrl, was_suspend);
28702869
if (result)
28712870
goto out;
28722871

2873-
if (dev->ctrl.oacs & NVME_CTRL_OACS_SEC_SUPP) {
2874-
if (!dev->ctrl.opal_dev)
2875-
dev->ctrl.opal_dev =
2876-
init_opal_dev(&dev->ctrl, &nvme_sec_submit);
2877-
else if (was_suspend)
2878-
opal_unlock_from_suspend(dev->ctrl.opal_dev);
2879-
} else {
2880-
free_opal_dev(dev->ctrl.opal_dev);
2881-
dev->ctrl.opal_dev = NULL;
2882-
}
2883-
28842872
if (dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP) {
28852873
result = nvme_dbbuf_dma_alloc(dev);
28862874
if (result)

drivers/nvme/host/rdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
871871

872872
nvme_start_admin_queue(&ctrl->ctrl);
873873

874-
error = nvme_init_ctrl_finish(&ctrl->ctrl);
874+
error = nvme_init_ctrl_finish(&ctrl->ctrl, false);
875875
if (error)
876876
goto out_quiesce_queue;
877877

drivers/nvme/host/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ static int nvme_tcp_configure_admin_queue(struct nvme_ctrl *ctrl, bool new)
19491949

19501950
nvme_start_admin_queue(ctrl);
19511951

1952-
error = nvme_init_ctrl_finish(ctrl);
1952+
error = nvme_init_ctrl_finish(ctrl, false);
19531953
if (error)
19541954
goto out_quiesce_queue;
19551955

drivers/nvme/target/loop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl)
377377

378378
nvme_start_admin_queue(&ctrl->ctrl);
379379

380-
error = nvme_init_ctrl_finish(&ctrl->ctrl);
380+
error = nvme_init_ctrl_finish(&ctrl->ctrl, false);
381381
if (error)
382382
goto out_cleanup_tagset;
383383

0 commit comments

Comments
 (0)