2019-02-18 11:36:11 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-06-21 18:04:20 +02:00
|
|
|
/*
|
|
|
|
* NVMe Fabrics command implementation.
|
|
|
|
* Copyright (c) 2015-2016 HGST, a Western Digital Company.
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include "nvmet.h"
|
|
|
|
|
|
|
|
static void nvmet_execute_prop_set(struct nvmet_req *req)
|
|
|
|
{
|
2018-12-12 15:11:44 -08:00
|
|
|
u64 val = le64_to_cpu(req->cmd->prop_set.value);
|
2016-06-21 18:04:20 +02:00
|
|
|
u16 status = 0;
|
|
|
|
|
2020-05-19 17:05:59 +03:00
|
|
|
if (!nvmet_check_transfer_len(req, 0))
|
2019-10-23 10:35:44 -06:00
|
|
|
return;
|
|
|
|
|
2018-12-12 15:11:44 -08:00
|
|
|
if (req->cmd->prop_set.attrib & 1) {
|
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvmf_property_set_command, attrib);
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
|
2018-12-12 15:11:44 -08:00
|
|
|
goto out;
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:11:44 -08:00
|
|
|
switch (le32_to_cpu(req->cmd->prop_set.offset)) {
|
|
|
|
case NVME_REG_CC:
|
|
|
|
nvmet_update_cc(req->sq->ctrl, val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvmf_property_set_command, offset);
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
|
2018-12-12 15:11:44 -08:00
|
|
|
}
|
|
|
|
out:
|
2016-06-21 18:04:20 +02:00
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nvmet_execute_prop_get(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvmet_ctrl *ctrl = req->sq->ctrl;
|
|
|
|
u16 status = 0;
|
|
|
|
u64 val = 0;
|
|
|
|
|
2020-05-19 17:05:59 +03:00
|
|
|
if (!nvmet_check_transfer_len(req, 0))
|
2019-10-23 10:35:44 -06:00
|
|
|
return;
|
|
|
|
|
2016-06-21 18:04:20 +02:00
|
|
|
if (req->cmd->prop_get.attrib & 1) {
|
|
|
|
switch (le32_to_cpu(req->cmd->prop_get.offset)) {
|
|
|
|
case NVME_REG_CAP:
|
|
|
|
val = ctrl->cap;
|
|
|
|
break;
|
|
|
|
default:
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (le32_to_cpu(req->cmd->prop_get.offset)) {
|
|
|
|
case NVME_REG_VS:
|
|
|
|
val = ctrl->subsys->ver;
|
|
|
|
break;
|
|
|
|
case NVME_REG_CC:
|
|
|
|
val = ctrl->cc;
|
|
|
|
break;
|
|
|
|
case NVME_REG_CSTS:
|
|
|
|
val = ctrl->csts;
|
|
|
|
break;
|
2024-11-04 14:17:59 -08:00
|
|
|
case NVME_REG_CRTO:
|
|
|
|
val = NVME_CAP_TIMEOUT(ctrl->csts);
|
|
|
|
break;
|
2016-06-21 18:04:20 +02:00
|
|
|
default:
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:11:44 -08:00
|
|
|
if (status && req->cmd->prop_get.attrib & 1) {
|
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvmf_property_get_command, offset);
|
|
|
|
} else {
|
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvmf_property_get_command, attrib);
|
|
|
|
}
|
|
|
|
|
2019-04-08 18:39:59 +03:00
|
|
|
req->cqe->result.u64 = cpu_to_le64(val);
|
2016-06-21 18:04:20 +02:00
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
}
|
|
|
|
|
2025-01-04 13:59:41 +09:00
|
|
|
u32 nvmet_fabrics_admin_cmd_data_len(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
switch (cmd->fabrics.fctype) {
|
|
|
|
#ifdef CONFIG_NVME_TARGET_AUTH
|
|
|
|
case nvme_fabrics_type_auth_send:
|
|
|
|
return nvmet_auth_send_data_len(req);
|
|
|
|
case nvme_fabrics_type_auth_receive:
|
|
|
|
return nvmet_auth_receive_data_len(req);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:52:04 +02:00
|
|
|
u16 nvmet_parse_fabrics_admin_cmd(struct nvmet_req *req)
|
2016-06-21 18:04:20 +02:00
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
switch (cmd->fabrics.fctype) {
|
|
|
|
case nvme_fabrics_type_property_set:
|
|
|
|
req->execute = nvmet_execute_prop_set;
|
|
|
|
break;
|
|
|
|
case nvme_fabrics_type_property_get:
|
|
|
|
req->execute = nvmet_execute_prop_get;
|
|
|
|
break;
|
2022-06-27 11:52:05 +02:00
|
|
|
#ifdef CONFIG_NVME_TARGET_AUTH
|
|
|
|
case nvme_fabrics_type_auth_send:
|
|
|
|
req->execute = nvmet_execute_auth_send;
|
|
|
|
break;
|
|
|
|
case nvme_fabrics_type_auth_receive:
|
|
|
|
req->execute = nvmet_execute_auth_receive;
|
|
|
|
break;
|
|
|
|
#endif
|
2016-06-21 18:04:20 +02:00
|
|
|
default:
|
2021-05-10 12:15:38 -07:00
|
|
|
pr_debug("received unknown capsule type 0x%x\n",
|
2016-06-21 18:04:20 +02:00
|
|
|
cmd->fabrics.fctype);
|
2018-12-12 15:11:44 -08:00
|
|
|
req->error_loc = offsetof(struct nvmf_common_command, fctype);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2025-01-04 13:59:41 +09:00
|
|
|
u32 nvmet_fabrics_io_cmd_data_len(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
switch (cmd->fabrics.fctype) {
|
|
|
|
#ifdef CONFIG_NVME_TARGET_AUTH
|
|
|
|
case nvme_fabrics_type_auth_send:
|
|
|
|
return nvmet_auth_send_data_len(req);
|
|
|
|
case nvme_fabrics_type_auth_receive:
|
|
|
|
return nvmet_auth_receive_data_len(req);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:52:04 +02:00
|
|
|
u16 nvmet_parse_fabrics_io_cmd(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
switch (cmd->fabrics.fctype) {
|
2022-06-27 11:52:05 +02:00
|
|
|
#ifdef CONFIG_NVME_TARGET_AUTH
|
|
|
|
case nvme_fabrics_type_auth_send:
|
|
|
|
req->execute = nvmet_execute_auth_send;
|
|
|
|
break;
|
|
|
|
case nvme_fabrics_type_auth_receive:
|
|
|
|
req->execute = nvmet_execute_auth_receive;
|
|
|
|
break;
|
|
|
|
#endif
|
2022-06-27 11:52:04 +02:00
|
|
|
default:
|
|
|
|
pr_debug("received unknown capsule type 0x%x\n",
|
|
|
|
cmd->fabrics.fctype);
|
|
|
|
req->error_loc = offsetof(struct nvmf_common_command, fctype);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_STATUS_DNR;
|
2022-06-27 11:52:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:04:20 +02:00
|
|
|
static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvmf_connect_command *c = &req->cmd->connect;
|
|
|
|
u16 qid = le16_to_cpu(c->qid);
|
|
|
|
u16 sqsize = le16_to_cpu(c->sqsize);
|
|
|
|
struct nvmet_ctrl *old;
|
2021-08-05 18:02:51 +03:00
|
|
|
u16 mqes = NVME_CAP_MQES(ctrl->cap);
|
2020-02-04 14:38:10 +02:00
|
|
|
u16 ret;
|
2016-06-21 18:04:20 +02:00
|
|
|
|
2017-09-18 09:08:29 -07:00
|
|
|
if (!sqsize) {
|
|
|
|
pr_warn("queue size zero!\n");
|
2018-12-12 15:11:44 -08:00
|
|
|
req->error_loc = offsetof(struct nvmf_connect_command, sqsize);
|
2021-08-08 09:20:14 +03:00
|
|
|
req->cqe->result.u32 = IPO_IATTR_CONNECT_SQE(sqsize);
|
2024-06-03 20:57:01 +08:00
|
|
|
ret = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR;
|
2020-02-04 14:38:10 +02:00
|
|
|
goto err;
|
2017-09-18 09:08:29 -07:00
|
|
|
}
|
2016-06-21 18:04:20 +02:00
|
|
|
|
2021-08-08 18:06:15 +03:00
|
|
|
if (ctrl->sqs[qid] != NULL) {
|
|
|
|
pr_warn("qid %u has already been created\n", qid);
|
|
|
|
req->error_loc = offsetof(struct nvmf_connect_command, qid);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_CMD_SEQ_ERROR | NVME_STATUS_DNR;
|
2021-08-08 18:06:15 +03:00
|
|
|
}
|
|
|
|
|
2024-01-23 16:40:26 +02:00
|
|
|
/* for fabrics, this value applies to only the I/O Submission Queues */
|
|
|
|
if (qid && sqsize > mqes) {
|
2021-08-05 18:02:51 +03:00
|
|
|
pr_warn("sqsize %u is larger than MQES supported %u cntlid %d\n",
|
|
|
|
sqsize, mqes, ctrl->cntlid);
|
|
|
|
req->error_loc = offsetof(struct nvmf_connect_command, sqsize);
|
|
|
|
req->cqe->result.u32 = IPO_IATTR_CONNECT_SQE(sqsize);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR;
|
2021-08-05 18:02:51 +03:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:06:15 +03:00
|
|
|
old = cmpxchg(&req->sq->ctrl, NULL, ctrl);
|
|
|
|
if (old) {
|
|
|
|
pr_warn("queue already connected!\n");
|
|
|
|
req->error_loc = offsetof(struct nvmf_connect_command, opcode);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_CONNECT_CTRL_BUSY | NVME_STATUS_DNR;
|
2021-08-08 18:06:15 +03:00
|
|
|
}
|
|
|
|
|
2025-04-24 15:13:51 +10:00
|
|
|
kref_get(&ctrl->ref);
|
|
|
|
old = cmpxchg(&req->cq->ctrl, NULL, ctrl);
|
|
|
|
if (old) {
|
|
|
|
pr_warn("queue already connected!\n");
|
|
|
|
req->error_loc = offsetof(struct nvmf_connect_command, opcode);
|
|
|
|
return NVME_SC_CONNECT_CTRL_BUSY | NVME_STATUS_DNR;
|
|
|
|
}
|
|
|
|
|
2017-09-18 09:08:29 -07:00
|
|
|
/* note: convert queue size from 0's-based value to 1's-based value */
|
|
|
|
nvmet_cq_setup(ctrl, req->cq, qid, sqsize + 1);
|
|
|
|
nvmet_sq_setup(ctrl, req->sq, qid, sqsize + 1);
|
2018-11-19 14:11:12 -08:00
|
|
|
|
|
|
|
if (c->cattr & NVME_CONNECT_DISABLE_SQFLOW) {
|
|
|
|
req->sq->sqhd_disabled = true;
|
2019-04-08 18:39:59 +03:00
|
|
|
req->cqe->sq_head = cpu_to_le16(0xffff);
|
2018-11-19 14:11:12 -08:00
|
|
|
}
|
|
|
|
|
2018-12-03 17:52:11 -08:00
|
|
|
if (ctrl->ops->install_queue) {
|
2020-02-04 14:38:10 +02:00
|
|
|
ret = ctrl->ops->install_queue(req->sq);
|
2018-12-03 17:52:11 -08:00
|
|
|
if (ret) {
|
|
|
|
pr_err("failed to install queue %d cntlid %d ret %x\n",
|
2020-02-04 14:38:09 +02:00
|
|
|
qid, ctrl->cntlid, ret);
|
2021-08-08 18:06:15 +03:00
|
|
|
ctrl->sqs[qid] = NULL;
|
2020-02-04 14:38:10 +02:00
|
|
|
goto err;
|
2018-12-03 17:52:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:04:20 +02:00
|
|
|
return 0;
|
2020-02-04 14:38:10 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
req->sq->ctrl = NULL;
|
|
|
|
return ret;
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
|
2025-02-24 13:38:16 +01:00
|
|
|
static u32 nvmet_connect_result(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq)
|
2022-09-20 16:09:57 +02:00
|
|
|
{
|
2025-02-24 13:38:17 +01:00
|
|
|
bool needs_auth = nvmet_has_auth(ctrl, sq);
|
|
|
|
key_serial_t keyid = nvmet_queue_tls_keyid(sq);
|
|
|
|
|
2025-04-22 11:15:55 +02:00
|
|
|
/* Do not authenticate I/O queues */
|
|
|
|
if (sq->qid)
|
2025-02-24 13:38:17 +01:00
|
|
|
needs_auth = false;
|
|
|
|
|
|
|
|
if (keyid)
|
|
|
|
pr_debug("%s: ctrl %d qid %d should %sauthenticate, tls psk %08x\n",
|
|
|
|
__func__, ctrl->cntlid, sq->qid,
|
|
|
|
needs_auth ? "" : "not ", keyid);
|
|
|
|
else
|
|
|
|
pr_debug("%s: ctrl %d qid %d should %sauthenticate%s\n",
|
|
|
|
__func__, ctrl->cntlid, sq->qid,
|
|
|
|
needs_auth ? "" : "not ",
|
|
|
|
ctrl->concat ? ", secure concatenation" : "");
|
2022-09-20 16:09:57 +02:00
|
|
|
return (u32)ctrl->cntlid |
|
2025-02-24 13:38:16 +01:00
|
|
|
(needs_auth ? NVME_CONNECT_AUTHREQ_ATR : 0);
|
2022-09-20 16:09:57 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 18:04:20 +02:00
|
|
|
static void nvmet_execute_admin_connect(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvmf_connect_command *c = &req->cmd->connect;
|
|
|
|
struct nvmf_connect_data *d;
|
|
|
|
struct nvmet_ctrl *ctrl = NULL;
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
struct nvmet_alloc_ctrl_args args = {
|
|
|
|
.port = req->port,
|
2025-02-24 13:38:16 +01:00
|
|
|
.sq = req->sq,
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
.ops = req->ops,
|
|
|
|
.p2p_client = req->p2p_client,
|
|
|
|
.kato = le32_to_cpu(c->kato),
|
|
|
|
};
|
2016-06-21 18:04:20 +02:00
|
|
|
|
2020-05-19 17:05:59 +03:00
|
|
|
if (!nvmet_check_transfer_len(req, sizeof(struct nvmf_connect_data)))
|
2019-10-23 10:35:44 -06:00
|
|
|
return;
|
|
|
|
|
2017-04-18 17:32:15 -06:00
|
|
|
d = kmalloc(sizeof(*d), GFP_KERNEL);
|
|
|
|
if (!d) {
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.status = NVME_SC_INTERNAL;
|
2017-04-18 17:32:15 -06:00
|
|
|
goto complete;
|
|
|
|
}
|
|
|
|
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.status = nvmet_copy_from_sgl(req, 0, d, sizeof(*d));
|
|
|
|
if (args.status)
|
2017-04-18 17:32:15 -06:00
|
|
|
goto out;
|
2016-06-21 18:04:20 +02:00
|
|
|
|
|
|
|
if (c->recfmt != 0) {
|
|
|
|
pr_warn("invalid connect version (%d).\n",
|
|
|
|
le16_to_cpu(c->recfmt));
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.error_loc = offsetof(struct nvmf_connect_command, recfmt);
|
|
|
|
args.status = NVME_SC_CONNECT_FORMAT | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(d->cntlid != cpu_to_le16(0xffff))) {
|
|
|
|
pr_warn("connect attempt for invalid controller ID %#x\n",
|
|
|
|
d->cntlid);
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.status = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR;
|
|
|
|
args.result = IPO_IATTR_CONNECT_DATA(cntlid);
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2023-11-17 08:13:36 -05:00
|
|
|
d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
|
|
|
|
d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
|
2018-12-12 15:11:44 -08:00
|
|
|
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.subsysnqn = d->subsysnqn;
|
|
|
|
args.hostnqn = d->hostnqn;
|
|
|
|
args.hostid = &d->hostid;
|
2025-01-28 08:55:34 +01:00
|
|
|
args.kato = le32_to_cpu(c->kato);
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
|
|
|
|
ctrl = nvmet_alloc_ctrl(&args);
|
|
|
|
if (!ctrl)
|
2022-06-27 11:52:05 +02:00
|
|
|
goto out;
|
|
|
|
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
args.status = nvmet_install_queue(ctrl, req);
|
|
|
|
if (args.status) {
|
2016-06-21 18:04:20 +02:00
|
|
|
nvmet_ctrl_put(ctrl);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2025-02-24 13:38:16 +01:00
|
|
|
args.result = cpu_to_le32(nvmet_connect_result(ctrl, req->sq));
|
2016-06-21 18:04:20 +02:00
|
|
|
out:
|
2017-04-18 17:32:15 -06:00
|
|
|
kfree(d);
|
|
|
|
complete:
|
nvmet: Improve nvmet_alloc_ctrl() interface and implementation
Introduce struct nvmet_alloc_ctrl_args to define the arguments for
the function nvmet_alloc_ctrl() to avoid the need for passing a pointer
to a struct nvmet_req as an argument. This new data structure aggregates
together the arguments that were passed to nvmet_alloc_ctrl()
(subsysnqn, hostnqn and kato), together with the struct nvmet_req fields
used by nvmet_alloc_ctrl(), that is, the fields port, p2p_client, and
ops as input and the result and error_loc fields as output, as well as a
status field. nvmet_alloc_ctrl() is also changed to return a pointer
to the allocated and initialized controller structure instead of a
status code, as the status is now returned through the status field of
struct nvmet_alloc_ctrl_args.
The function nvmet_setup_p2p_ns_map() is changed to not take a pointer
to a struct nvmet_req as argument, instead, directly specify the
p2p_client device pointer needed as argument.
The code in nvmet_execute_admin_connect() that initializes a new target
controller after allocating it is moved into nvmet_alloc_ctrl().
The code that sets up an admin queue for the controller (and the call
to nvmet_install_queue()) remains in nvmet_execute_admin_connect().
Finally, nvmet_alloc_ctrl() is also exported to allow target drivers to
use this function directly to allocate and initialize a new controller
structure without the need to rely on a fabrics connect command request.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
2025-01-04 13:59:40 +09:00
|
|
|
req->error_loc = args.error_loc;
|
|
|
|
req->cqe->result.u32 = args.result;
|
|
|
|
nvmet_req_complete(req, args.status);
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nvmet_execute_io_connect(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvmf_connect_command *c = &req->cmd->connect;
|
|
|
|
struct nvmf_connect_data *d;
|
2021-03-09 17:16:32 -08:00
|
|
|
struct nvmet_ctrl *ctrl;
|
2016-06-21 18:04:20 +02:00
|
|
|
u16 qid = le16_to_cpu(c->qid);
|
2024-02-12 23:58:24 -08:00
|
|
|
u16 status;
|
2016-06-21 18:04:20 +02:00
|
|
|
|
2020-05-19 17:05:59 +03:00
|
|
|
if (!nvmet_check_transfer_len(req, sizeof(struct nvmf_connect_data)))
|
2019-10-23 10:35:44 -06:00
|
|
|
return;
|
|
|
|
|
2017-04-18 17:32:15 -06:00
|
|
|
d = kmalloc(sizeof(*d), GFP_KERNEL);
|
|
|
|
if (!d) {
|
|
|
|
status = NVME_SC_INTERNAL;
|
|
|
|
goto complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = nvmet_copy_from_sgl(req, 0, d, sizeof(*d));
|
|
|
|
if (status)
|
|
|
|
goto out;
|
2016-06-21 18:04:20 +02:00
|
|
|
|
|
|
|
if (c->recfmt != 0) {
|
|
|
|
pr_warn("invalid connect version (%d).\n",
|
|
|
|
le16_to_cpu(c->recfmt));
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_CONNECT_FORMAT | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2023-11-17 08:13:36 -05:00
|
|
|
d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
|
|
|
|
d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
|
2021-03-09 17:16:32 -08:00
|
|
|
ctrl = nvmet_ctrl_find_get(d->subsysnqn, d->hostnqn,
|
|
|
|
le16_to_cpu(d->cntlid), req);
|
|
|
|
if (!ctrl) {
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out;
|
2021-03-09 17:16:32 -08:00
|
|
|
}
|
2016-06-21 18:04:20 +02:00
|
|
|
|
|
|
|
if (unlikely(qid > ctrl->subsys->max_qid)) {
|
|
|
|
pr_warn("invalid queue id (%d)\n", qid);
|
2024-06-03 20:57:01 +08:00
|
|
|
status = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR;
|
2019-04-08 18:39:59 +03:00
|
|
|
req->cqe->result.u32 = IPO_IATTR_CONNECT_SQE(qid);
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out_ctrl_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = nvmet_install_queue(ctrl, req);
|
2021-08-08 09:20:14 +03:00
|
|
|
if (status)
|
2016-06-21 18:04:20 +02:00
|
|
|
goto out_ctrl_put;
|
2021-08-08 09:20:14 +03:00
|
|
|
|
2017-12-04 10:47:09 +02:00
|
|
|
pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid);
|
2025-02-24 13:38:16 +01:00
|
|
|
req->cqe->result.u32 = cpu_to_le32(nvmet_connect_result(ctrl, req->sq));
|
2016-06-21 18:04:20 +02:00
|
|
|
out:
|
2017-04-18 17:32:15 -06:00
|
|
|
kfree(d);
|
|
|
|
complete:
|
2016-06-21 18:04:20 +02:00
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_ctrl_put:
|
|
|
|
nvmet_ctrl_put(ctrl);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2025-01-04 13:59:41 +09:00
|
|
|
u32 nvmet_connect_cmd_data_len(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
if (!nvme_is_fabrics(cmd) ||
|
|
|
|
cmd->fabrics.fctype != nvme_fabrics_type_connect)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return sizeof(struct nvmf_connect_data);
|
|
|
|
}
|
|
|
|
|
2017-02-27 23:21:33 -06:00
|
|
|
u16 nvmet_parse_connect_cmd(struct nvmet_req *req)
|
2016-06-21 18:04:20 +02:00
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
2019-06-06 14:30:14 +09:00
|
|
|
if (!nvme_is_fabrics(cmd)) {
|
2021-05-10 12:15:38 -07:00
|
|
|
pr_debug("invalid command 0x%x on unconnected queue.\n",
|
2016-06-21 18:04:20 +02:00
|
|
|
cmd->fabrics.opcode);
|
2018-12-12 15:11:44 -08:00
|
|
|
req->error_loc = offsetof(struct nvme_common_command, opcode);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
if (cmd->fabrics.fctype != nvme_fabrics_type_connect) {
|
2021-05-10 12:15:38 -07:00
|
|
|
pr_debug("invalid capsule type 0x%x on unconnected queue.\n",
|
2016-06-21 18:04:20 +02:00
|
|
|
cmd->fabrics.fctype);
|
2018-12-12 15:11:44 -08:00
|
|
|
req->error_loc = offsetof(struct nvmf_common_command, fctype);
|
2024-06-03 20:57:01 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_STATUS_DNR;
|
2016-06-21 18:04:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd->connect.qid == 0)
|
|
|
|
req->execute = nvmet_execute_admin_connect;
|
|
|
|
else
|
|
|
|
req->execute = nvmet_execute_io_connect;
|
|
|
|
return 0;
|
|
|
|
}
|