2016-06-06 21:44:30 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
#include "nvmf_internal.h"
|
2016-07-14 22:25:23 +00:00
|
|
|
#include "transport.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2017-09-07 00:17:42 +00:00
|
|
|
#include "spdk/endian.h"
|
2017-08-23 18:32:09 +00:00
|
|
|
#include "spdk/io_channel.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/trace.h"
|
2016-06-22 23:23:36 +00:00
|
|
|
#include "spdk/nvme_spec.h"
|
2017-08-16 21:03:42 +00:00
|
|
|
#include "spdk/string.h"
|
2017-03-03 20:44:04 +00:00
|
|
|
#include "spdk/util.h"
|
2017-08-22 23:17:41 +00:00
|
|
|
#include "spdk/version.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-11-07 22:10:28 +00:00
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
2016-11-22 22:54:42 +00:00
|
|
|
#define MIN_KEEP_ALIVE_TIMEOUT 10000
|
|
|
|
|
2017-08-16 21:03:42 +00:00
|
|
|
#define MODEL_NUMBER "SPDK bdev Controller"
|
2017-08-22 23:17:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Report the SPDK version as the firmware revision.
|
|
|
|
* SPDK_VERSION_STRING won't fit into FR (only 8 bytes), so try to fit the most important parts.
|
|
|
|
*/
|
|
|
|
#define FW_VERSION SPDK_VERSION_MAJOR_STRING SPDK_VERSION_MINOR_STRING SPDK_VERSION_PATCH_STRING
|
2017-08-16 21:03:42 +00:00
|
|
|
|
|
|
|
static struct spdk_nvmf_ctrlr *
|
|
|
|
spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
struct spdk_nvmf_qpair *admin_qpair,
|
|
|
|
struct spdk_nvmf_fabric_connect_cmd *connect_cmd,
|
|
|
|
struct spdk_nvmf_fabric_connect_data *connect_data)
|
2016-06-22 23:23:36 +00:00
|
|
|
{
|
2017-08-18 22:26:41 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr;
|
|
|
|
struct spdk_nvmf_tgt *tgt;
|
|
|
|
|
|
|
|
tgt = subsystem->tgt;
|
2017-08-16 21:03:42 +00:00
|
|
|
|
|
|
|
ctrlr = calloc(1, sizeof(*ctrlr));
|
|
|
|
if (ctrlr == NULL) {
|
|
|
|
SPDK_ERRLOG("Memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
ctrlr->group = spdk_nvmf_poll_group_create(subsystem->tgt);
|
2017-08-16 21:03:42 +00:00
|
|
|
if (ctrlr->group == NULL) {
|
|
|
|
SPDK_ERRLOG("spdk_nvmf_transport_poll_group_create() failed\n");
|
|
|
|
free(ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_INIT(&ctrlr->qpairs);
|
|
|
|
ctrlr->kato = connect_cmd->kato;
|
|
|
|
ctrlr->async_event_config.raw = 0;
|
|
|
|
ctrlr->num_qpairs = 0;
|
|
|
|
ctrlr->subsys = subsystem;
|
2017-08-18 22:26:41 +00:00
|
|
|
ctrlr->max_qpairs_allowed = tgt->opts.max_qpairs_per_ctrlr;
|
2017-08-16 21:03:42 +00:00
|
|
|
|
|
|
|
memcpy(ctrlr->hostid, connect_data->hostid, sizeof(ctrlr->hostid));
|
2017-07-13 21:18:08 +00:00
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
if (spdk_nvmf_poll_group_add(ctrlr->group, admin_qpair)) {
|
|
|
|
spdk_nvmf_poll_group_destroy(ctrlr->group);
|
2017-08-16 21:03:42 +00:00
|
|
|
free(ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-19 18:13:25 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cap.raw = 0;
|
|
|
|
ctrlr->vcprop.cap.bits.cqr = 1; /* NVMe-oF specification required */
|
2017-08-18 22:26:41 +00:00
|
|
|
ctrlr->vcprop.cap.bits.mqes = tgt->opts.max_queue_depth - 1; /* max queue depth */
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cap.bits.ams = 0; /* optional arb mechanisms */
|
2017-08-16 21:03:42 +00:00
|
|
|
ctrlr->vcprop.cap.bits.to = 1; /* ready timeout - 500 msec units */
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cap.bits.dstrd = 0; /* fixed to 0 for NVMe-oF */
|
|
|
|
ctrlr->vcprop.cap.bits.css_nvm = 1; /* NVM command set */
|
|
|
|
ctrlr->vcprop.cap.bits.mpsmin = 0; /* 2 ^ (12 + mpsmin) == 4k */
|
|
|
|
ctrlr->vcprop.cap.bits.mpsmax = 0; /* 2 ^ (12 + mpsmax) == 4k */
|
2016-06-22 23:23:36 +00:00
|
|
|
|
2016-07-25 23:29:57 +00:00
|
|
|
/* Version Supported: 1.2.1 */
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.vs.bits.mjr = 1;
|
|
|
|
ctrlr->vcprop.vs.bits.mnr = 2;
|
|
|
|
ctrlr->vcprop.vs.bits.ter = 1;
|
2016-06-22 23:23:36 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.raw = 0;
|
2017-08-16 21:03:42 +00:00
|
|
|
ctrlr->vcprop.cc.bits.en = 0; /* Init controller disabled */
|
2016-06-22 23:23:36 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.csts.raw = 0;
|
|
|
|
ctrlr->vcprop.csts.bits.rdy = 0; /* Init controller as not ready */
|
2016-07-25 21:22:58 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "cap 0x%" PRIx64 "\n", ctrlr->vcprop.cap.raw);
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "vs 0x%x\n", ctrlr->vcprop.vs.raw);
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "cc 0x%x\n", ctrlr->vcprop.cc.raw);
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "csts 0x%x\n", ctrlr->vcprop.csts.raw);
|
2017-07-13 21:18:08 +00:00
|
|
|
|
2017-09-11 23:50:29 +00:00
|
|
|
if (spdk_nvmf_subsystem_add_ctrlr(subsystem, ctrlr)) {
|
|
|
|
SPDK_ERRLOG("Unable to add controller to subsystem\n");
|
|
|
|
spdk_nvmf_poll_group_destroy(ctrlr->group);
|
|
|
|
free(ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:03:42 +00:00
|
|
|
return ctrlr;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
static void ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-07-07 23:08:48 +00:00
|
|
|
{
|
2017-09-11 23:50:29 +00:00
|
|
|
spdk_nvmf_subsystem_remove_ctrlr(ctrlr->subsys, ctrlr);
|
2017-08-28 23:24:33 +00:00
|
|
|
spdk_nvmf_poll_group_destroy(ctrlr->group);
|
2017-07-28 18:21:45 +00:00
|
|
|
free(ctrlr);
|
2016-09-12 05:13:12 +00:00
|
|
|
}
|
2016-07-11 21:08:31 +00:00
|
|
|
|
2016-09-12 05:13:12 +00:00
|
|
|
void
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-09-12 05:13:12 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
while (!TAILQ_EMPTY(&ctrlr->qpairs)) {
|
|
|
|
struct spdk_nvmf_qpair *qpair = TAILQ_FIRST(&ctrlr->qpairs);
|
2016-07-11 21:08:31 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&ctrlr->qpairs, qpair, link);
|
|
|
|
ctrlr->num_qpairs--;
|
2017-07-25 20:47:41 +00:00
|
|
|
spdk_nvmf_transport_qpair_fini(qpair);
|
2016-07-11 21:08:31 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr_destruct(ctrlr);
|
2016-07-07 23:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
static inline void
|
|
|
|
spdk_nvmf_invalid_connect_response(struct spdk_nvmf_fabric_connect_rsp *rsp,
|
|
|
|
uint8_t iattr, uint16_t ipo)
|
|
|
|
{
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
|
|
|
rsp->status_code_specific.invalid.iattr = iattr;
|
|
|
|
rsp->status_code_specific.invalid.ipo = ipo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPDK_NVMF_INVALID_CONNECT_CMD(rsp, field) \
|
|
|
|
spdk_nvmf_invalid_connect_response(rsp, 0, offsetof(struct spdk_nvmf_fabric_connect_cmd, field))
|
|
|
|
#define SPDK_NVMF_INVALID_CONNECT_DATA(rsp, field) \
|
|
|
|
spdk_nvmf_invalid_connect_response(rsp, 1, offsetof(struct spdk_nvmf_fabric_connect_data, field))
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
void
|
2017-09-12 01:24:46 +00:00
|
|
|
spdk_nvmf_ctrlr_connect(struct spdk_nvmf_request *req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-09-12 01:24:46 +00:00
|
|
|
struct spdk_nvmf_fabric_connect_data *data = req->data;
|
|
|
|
struct spdk_nvmf_fabric_connect_cmd *cmd = &req->cmd->connect_cmd;
|
|
|
|
struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
|
|
|
|
struct spdk_nvmf_qpair *qpair = req->qpair;
|
|
|
|
struct spdk_nvmf_tgt *tgt = qpair->transport->tgt;
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr;
|
2016-06-06 21:44:30 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2017-09-12 01:24:46 +00:00
|
|
|
const char *subnqn, *hostnqn;
|
|
|
|
void *end;
|
|
|
|
|
|
|
|
if (req->length < sizeof(struct spdk_nvmf_fabric_connect_data)) {
|
|
|
|
SPDK_ERRLOG("Connect command data length 0x%x too small\n", req->length);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return;
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "recfmt 0x%x qid %u sqsize %u\n",
|
2016-07-14 00:23:23 +00:00
|
|
|
cmd->recfmt, cmd->qid, cmd->sqsize);
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Connect data:\n");
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, " cntlid: 0x%04x\n", data->cntlid);
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, " hostid: %08x-%04x-%04x-%02x%02x-%04x%08x ***\n",
|
2016-07-14 00:23:23 +00:00
|
|
|
ntohl(*(uint32_t *)&data->hostid[0]),
|
|
|
|
ntohs(*(uint16_t *)&data->hostid[4]),
|
|
|
|
ntohs(*(uint16_t *)&data->hostid[6]),
|
|
|
|
data->hostid[8],
|
|
|
|
data->hostid[9],
|
|
|
|
ntohs(*(uint16_t *)&data->hostid[10]),
|
|
|
|
ntohl(*(uint32_t *)&data->hostid[12]));
|
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
if (cmd->recfmt != 0) {
|
|
|
|
SPDK_ERRLOG("Connect command unsupported RECFMT %u\n", cmd->recfmt);
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVMF_FABRIC_SC_INCOMPATIBLE_FORMAT;
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 18:32:09 +00:00
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
/* Ensure that subnqn is null terminated */
|
|
|
|
end = memchr(data->subnqn, '\0', SPDK_NVMF_NQN_MAX_LEN + 1);
|
|
|
|
if (!end) {
|
|
|
|
SPDK_ERRLOG("Connect SUBNQN is not null terminated\n");
|
|
|
|
SPDK_NVMF_INVALID_CONNECT_DATA(rsp, subnqn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
subnqn = data->subnqn;
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, " subnqn: \"%s\"\n", subnqn);
|
2017-08-18 23:05:13 +00:00
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(tgt, subnqn);
|
2016-07-07 23:27:13 +00:00
|
|
|
if (subsystem == NULL) {
|
2017-09-12 01:24:46 +00:00
|
|
|
SPDK_ERRLOG("Could not find subsystem '%s'\n", subnqn);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_DATA(rsp, subnqn);
|
2016-07-14 00:23:23 +00:00
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
/* Ensure that hostnqn is null terminated */
|
|
|
|
end = memchr(data->hostnqn, '\0', SPDK_NVMF_NQN_MAX_LEN + 1);
|
|
|
|
if (!end) {
|
|
|
|
SPDK_ERRLOG("Connect HOSTNQN is not null terminated\n");
|
|
|
|
SPDK_NVMF_INVALID_CONNECT_DATA(rsp, hostnqn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hostnqn = data->hostnqn;
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, " hostnqn: \"%s\"\n", hostnqn);
|
|
|
|
|
|
|
|
if (!spdk_nvmf_subsystem_host_allowed(subsystem, hostnqn)) {
|
|
|
|
SPDK_ERRLOG("Subsystem '%s' does not allow host '%s'\n", subnqn, hostnqn);
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_HOST;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-05 16:41:34 +00:00
|
|
|
/*
|
|
|
|
* SQSIZE is a 0-based value, so it must be at least 1 (minimum queue depth is 2) and
|
|
|
|
* strictly less than max_queue_depth.
|
|
|
|
*/
|
2017-08-18 23:05:13 +00:00
|
|
|
if (cmd->sqsize == 0 || cmd->sqsize >= tgt->opts.max_queue_depth) {
|
2016-08-05 16:41:34 +00:00
|
|
|
SPDK_ERRLOG("Invalid SQSIZE %u (min 1, max %u)\n",
|
2017-08-18 23:05:13 +00:00
|
|
|
cmd->sqsize, tgt->opts.max_queue_depth - 1);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, sqsize);
|
2016-08-05 16:41:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair->sq_head_max = cmd->sqsize;
|
|
|
|
qpair->qid = cmd->qid;
|
2016-08-05 22:06:05 +00:00
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
if (cmd->qid == 0) {
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair->type = QPAIR_TYPE_AQ;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Connect Admin Queue for controller ID 0x%x\n", data->cntlid);
|
2016-06-30 18:18:52 +00:00
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
if (data->cntlid != 0xFFFF) {
|
2016-06-30 18:18:52 +00:00
|
|
|
/* This NVMf target only supports dynamic mode. */
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_ERRLOG("The NVMf target only supports dynamic mode (CNTLID = 0x%x).\n", data->cntlid);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_DATA(rsp, cntlid);
|
2016-07-14 00:23:23 +00:00
|
|
|
return;
|
2016-06-30 18:18:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
/* Establish a new ctrlr */
|
2017-08-16 21:03:42 +00:00
|
|
|
ctrlr = spdk_nvmf_ctrlr_create(subsystem, qpair, cmd, data);
|
2017-07-28 18:21:45 +00:00
|
|
|
if (!ctrlr) {
|
2017-08-16 21:03:42 +00:00
|
|
|
SPDK_ERRLOG("spdk_nvmf_ctrlr_create() failed\n");
|
2017-07-28 18:21:45 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
} else {
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair->type = QPAIR_TYPE_IOQ;
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Connect I/O Queue for controller id 0x%x\n", data->cntlid);
|
2016-07-14 00:23:23 +00:00
|
|
|
|
2017-09-11 23:50:29 +00:00
|
|
|
ctrlr = spdk_nvmf_subsystem_get_ctrlr(subsystem, data->cntlid);
|
2017-07-13 21:18:08 +00:00
|
|
|
if (ctrlr == NULL) {
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_ERRLOG("Unknown controller ID 0x%x\n", data->cntlid);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_DATA(rsp, cntlid);
|
2016-07-14 00:23:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:45:49 +00:00
|
|
|
if (ctrlr->subsys->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
|
|
|
SPDK_ERRLOG("I/O connect not allowed on discovery controller\n");
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
|
2017-08-17 23:45:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
if (!ctrlr->vcprop.cc.bits.en) {
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_ERRLOG("Got I/O connect before ctrlr was enabled\n");
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
|
2016-07-14 00:23:23 +00:00
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-30 18:18:52 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
if (1u << ctrlr->vcprop.cc.bits.iosqes != sizeof(struct spdk_nvme_cmd)) {
|
2016-07-18 18:16:32 +00:00
|
|
|
SPDK_ERRLOG("Got I/O connect with invalid IOSQES %u\n",
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.iosqes);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
|
2016-07-18 18:16:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
if (1u << ctrlr->vcprop.cc.bits.iocqes != sizeof(struct spdk_nvme_cpl)) {
|
2016-07-18 18:16:32 +00:00
|
|
|
SPDK_ERRLOG("Got I/O connect with invalid IOCQES %u\n",
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.iocqes);
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
|
2016-07-18 18:16:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
/* check if we would exceed ctrlr connection limit */
|
2017-07-13 21:30:28 +00:00
|
|
|
if (ctrlr->num_qpairs >= ctrlr->max_qpairs_allowed) {
|
|
|
|
SPDK_ERRLOG("qpair limit %d\n", ctrlr->num_qpairs);
|
2016-07-14 00:23:23 +00:00
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVMF_FABRIC_SC_CONTROLLER_BUSY;
|
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-10-19 18:16:17 +00:00
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
if (spdk_nvmf_poll_group_add(ctrlr->group, qpair)) {
|
2017-08-28 19:36:22 +00:00
|
|
|
SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
|
2016-10-19 18:16:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 01:24:46 +00:00
|
|
|
assert(qpair->thread == NULL);
|
|
|
|
qpair->thread = spdk_get_thread();
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
ctrlr->num_qpairs++;
|
|
|
|
TAILQ_INSERT_HEAD(&ctrlr->qpairs, qpair, link);
|
|
|
|
qpair->ctrlr = ctrlr;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
2017-08-17 02:08:50 +00:00
|
|
|
rsp->status_code_specific.success.cntlid = ctrlr->cntlid;
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "connect capsule response: cntlid = 0x%04x\n",
|
2016-07-14 00:23:23 +00:00
|
|
|
rsp->status_code_specific.success.cntlid);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_ctrlr_disconnect(struct spdk_nvmf_qpair *qpair)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
|
2016-08-25 22:00:50 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
assert(ctrlr != NULL);
|
2017-07-13 21:30:28 +00:00
|
|
|
ctrlr->num_qpairs--;
|
|
|
|
TAILQ_REMOVE(&ctrlr->qpairs, qpair, link);
|
2016-10-19 18:16:17 +00:00
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
spdk_nvmf_poll_group_remove(ctrlr->group, qpair);
|
2017-07-25 20:47:41 +00:00
|
|
|
spdk_nvmf_transport_qpair_fini(qpair);
|
2016-07-22 22:55:59 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (ctrlr->num_qpairs == 0) {
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr_destruct(ctrlr);
|
2016-07-22 22:55:59 +00:00
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_qpair *
|
|
|
|
spdk_nvmf_ctrlr_get_qpair(struct spdk_nvmf_ctrlr *ctrlr, uint16_t qid)
|
2017-06-16 17:06:09 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_qpair *qpair;
|
2017-06-16 17:06:09 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_FOREACH(qpair, &ctrlr->qpairs, link) {
|
|
|
|
if (qpair->qid == qid) {
|
|
|
|
return qpair;
|
2017-06-16 17:06:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static struct spdk_nvmf_request *
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_qpair_get_request(struct spdk_nvmf_qpair *qpair, uint16_t cid)
|
2017-06-16 17:06:09 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
/* TODO: track list of outstanding requests in qpair? */
|
2017-06-16 17:06:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
static uint64_t
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_prop_get_cap(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-07-07 22:32:04 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
return ctrlr->vcprop.cap.raw;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_prop_get_vs(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-07-07 22:32:04 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
return ctrlr->vcprop.vs.raw;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_prop_get_cc(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-07-07 22:32:04 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
return ctrlr->vcprop.cc.raw;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_prop_set_cc(struct spdk_nvmf_ctrlr *ctrlr, uint64_t value)
|
2016-07-07 22:32:04 +00:00
|
|
|
{
|
2016-07-18 17:52:09 +00:00
|
|
|
union spdk_nvme_cc_register cc, diff;
|
2016-07-07 22:32:04 +00:00
|
|
|
|
|
|
|
cc.raw = (uint32_t)value;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "cur CC: 0x%08x\n", ctrlr->vcprop.cc.raw);
|
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "new CC: 0x%08x\n", cc.raw);
|
2016-07-18 17:52:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate which bits changed between the current and new CC.
|
|
|
|
* Mark each bit as 0 once it is handled to determine if any unhandled bits were changed.
|
|
|
|
*/
|
2017-07-13 21:18:08 +00:00
|
|
|
diff.raw = cc.raw ^ ctrlr->vcprop.cc.raw;
|
2016-07-18 17:52:09 +00:00
|
|
|
|
|
|
|
if (diff.bits.en) {
|
2016-07-18 16:13:15 +00:00
|
|
|
if (cc.bits.en) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Property Set CC Enable!\n");
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.en = 1;
|
|
|
|
ctrlr->vcprop.csts.bits.rdy = 1;
|
2016-07-18 16:13:15 +00:00
|
|
|
} else {
|
2016-11-23 21:04:09 +00:00
|
|
|
SPDK_ERRLOG("CC.EN transition from 1 to 0 (reset) not implemented!\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-07-18 16:13:15 +00:00
|
|
|
}
|
2016-07-18 17:52:09 +00:00
|
|
|
diff.bits.en = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff.bits.shn) {
|
|
|
|
if (cc.bits.shn == SPDK_NVME_SHN_NORMAL ||
|
|
|
|
cc.bits.shn == SPDK_NVME_SHN_ABRUPT) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Property Set CC Shutdown %u%ub!\n",
|
2016-07-18 17:52:09 +00:00
|
|
|
cc.bits.shn >> 1, cc.bits.shn & 1);
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.shn = cc.bits.shn;
|
|
|
|
ctrlr->vcprop.cc.bits.en = 0;
|
|
|
|
ctrlr->vcprop.csts.bits.rdy = 0;
|
|
|
|
ctrlr->vcprop.csts.bits.shst = SPDK_NVME_SHST_COMPLETE;
|
2016-07-18 17:52:09 +00:00
|
|
|
} else if (cc.bits.shn == 0) {
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.shn = 0;
|
2016-07-18 17:52:09 +00:00
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Prop Set CC: Invalid SHN value %u%ub\n",
|
|
|
|
cc.bits.shn >> 1, cc.bits.shn & 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
diff.bits.shn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff.bits.iosqes) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Prop Set IOSQES = %u (%u bytes)\n",
|
2016-07-18 17:52:09 +00:00
|
|
|
cc.bits.iosqes, 1u << cc.bits.iosqes);
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.iosqes = cc.bits.iosqes;
|
2016-07-18 17:52:09 +00:00
|
|
|
diff.bits.iosqes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff.bits.iocqes) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Prop Set IOCQES = %u (%u bytes)\n",
|
2016-07-18 17:52:09 +00:00
|
|
|
cc.bits.iocqes, 1u << cc.bits.iocqes);
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->vcprop.cc.bits.iocqes = cc.bits.iocqes;
|
2016-07-18 17:52:09 +00:00
|
|
|
diff.bits.iocqes = 0;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 17:52:09 +00:00
|
|
|
if (diff.raw != 0) {
|
|
|
|
SPDK_ERRLOG("Prop Set CC toggled reserved bits 0x%x!\n", diff.raw);
|
|
|
|
return false;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_prop_get_csts(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-07-07 22:32:04 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
return ctrlr->vcprop.csts.raw;
|
2016-07-07 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nvmf_prop {
|
|
|
|
uint32_t ofst;
|
|
|
|
uint8_t size;
|
|
|
|
char name[11];
|
2017-07-13 21:18:08 +00:00
|
|
|
uint64_t (*get_cb)(struct spdk_nvmf_ctrlr *ctrlr);
|
|
|
|
bool (*set_cb)(struct spdk_nvmf_ctrlr *ctrlr, uint64_t value);
|
2016-07-07 22:32:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PROP(field, size, get_cb, set_cb) \
|
|
|
|
{ \
|
|
|
|
offsetof(struct spdk_nvme_registers, field), \
|
|
|
|
SPDK_NVMF_PROP_SIZE_##size, \
|
|
|
|
#field, \
|
|
|
|
get_cb, set_cb \
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct nvmf_prop nvmf_props[] = {
|
|
|
|
PROP(cap, 8, nvmf_prop_get_cap, NULL),
|
|
|
|
PROP(vs, 4, nvmf_prop_get_vs, NULL),
|
|
|
|
PROP(cc, 4, nvmf_prop_get_cc, nvmf_prop_set_cc),
|
|
|
|
PROP(csts, 4, nvmf_prop_get_csts, NULL),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nvmf_prop *
|
|
|
|
find_prop(uint32_t ofst)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2017-03-03 20:44:04 +00:00
|
|
|
for (i = 0; i < SPDK_COUNTOF(nvmf_props); i++) {
|
2016-07-07 22:32:04 +00:00
|
|
|
const struct nvmf_prop *prop = &nvmf_props[i];
|
|
|
|
|
|
|
|
if (prop->ofst == ofst) {
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
void
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_property_get(struct spdk_nvmf_ctrlr *ctrlr,
|
2016-09-23 02:05:45 +00:00
|
|
|
struct spdk_nvmf_fabric_prop_get_cmd *cmd,
|
|
|
|
struct spdk_nvmf_fabric_prop_get_rsp *response)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-07-07 22:32:04 +00:00
|
|
|
const struct nvmf_prop *prop;
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
response->status.sc = 0;
|
|
|
|
response->value.u64 = 0;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "size %d, offset 0x%x\n",
|
2016-07-07 22:32:04 +00:00
|
|
|
cmd->attrib.size, cmd->ofst);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
if (cmd->attrib.size != SPDK_NVMF_PROP_SIZE_4 &&
|
|
|
|
cmd->attrib.size != SPDK_NVMF_PROP_SIZE_8) {
|
|
|
|
SPDK_ERRLOG("Invalid size value %d\n", cmd->attrib.size);
|
2016-06-06 21:44:30 +00:00
|
|
|
response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
prop = find_prop(cmd->ofst);
|
|
|
|
if (prop == NULL || prop->get_cb == NULL) {
|
|
|
|
/* Reserved properties return 0 when read */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "name: %s\n", prop->name);
|
2016-07-07 22:32:04 +00:00
|
|
|
if (cmd->attrib.size != prop->size) {
|
|
|
|
SPDK_ERRLOG("offset 0x%x size mismatch: cmd %u, prop %u\n",
|
|
|
|
cmd->ofst, cmd->attrib.size, prop->size);
|
2016-06-06 21:44:30 +00:00
|
|
|
response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
2016-07-07 22:32:04 +00:00
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-07 22:32:04 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
response->value.u64 = prop->get_cb(ctrlr);
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "response value: 0x%" PRIx64 "\n", response->value.u64);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_property_set(struct spdk_nvmf_ctrlr *ctrlr,
|
2016-09-23 02:05:45 +00:00
|
|
|
struct spdk_nvmf_fabric_prop_set_cmd *cmd,
|
|
|
|
struct spdk_nvme_cpl *response)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-07-07 22:32:04 +00:00
|
|
|
const struct nvmf_prop *prop;
|
|
|
|
uint64_t value;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "size %d, offset 0x%x, value 0x%" PRIx64 "\n",
|
2016-07-07 22:32:04 +00:00
|
|
|
cmd->attrib.size, cmd->ofst, cmd->value.u64);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
prop = find_prop(cmd->ofst);
|
|
|
|
if (prop == NULL || prop->set_cb == NULL) {
|
|
|
|
SPDK_ERRLOG("Invalid offset 0x%x\n", cmd->ofst);
|
2016-06-06 21:44:30 +00:00
|
|
|
response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "name: %s\n", prop->name);
|
2016-07-07 22:32:04 +00:00
|
|
|
if (cmd->attrib.size != prop->size) {
|
|
|
|
SPDK_ERRLOG("offset 0x%x size mismatch: cmd %u, prop %u\n",
|
|
|
|
cmd->ofst, cmd->attrib.size, prop->size);
|
|
|
|
response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
value = cmd->value.u64;
|
|
|
|
if (prop->size == SPDK_NVMF_PROP_SIZE_4) {
|
|
|
|
value = (uint32_t)value;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-07 22:32:04 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
if (!prop->set_cb(ctrlr, value)) {
|
2016-07-07 22:32:04 +00:00
|
|
|
SPDK_ERRLOG("prop set_cb failed\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
|
2016-07-07 22:32:04 +00:00
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 17:58:42 +00:00
|
|
|
|
2016-07-15 18:34:11 +00:00
|
|
|
int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_poll(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-06-24 17:58:42 +00:00
|
|
|
{
|
2017-08-28 23:24:33 +00:00
|
|
|
return spdk_nvmf_poll_group_poll(ctrlr->group);
|
2016-06-24 17:58:42 +00:00
|
|
|
}
|
2016-11-22 22:20:47 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_set_features_host_identifier(struct spdk_nvmf_request *req)
|
2016-11-22 22:20:47 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
SPDK_ERRLOG("Set Features - Host Identifier not allowed\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_get_features_host_identifier(struct spdk_nvmf_request *req)
|
2016-11-22 22:20:47 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2016-11-22 22:20:47 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get Features - Host Identifier\n");
|
2016-11-22 22:20:47 +00:00
|
|
|
if (!(cmd->cdw11 & 1)) {
|
|
|
|
/* NVMe over Fabrics requires EXHID=1 (128-bit/16-byte host ID) */
|
|
|
|
SPDK_ERRLOG("Get Features - Host Identifier with EXHID=0 not allowed\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
if (req->data == NULL || req->length < sizeof(ctrlr->hostid)) {
|
2016-11-22 22:20:47 +00:00
|
|
|
SPDK_ERRLOG("Invalid data buffer for Get Features - Host Identifier\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
memcpy(req->data, ctrlr->hostid, sizeof(ctrlr->hostid));
|
2016-11-22 22:20:47 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2016-11-22 22:54:42 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_set_features_keep_alive_timer(struct spdk_nvmf_request *req)
|
2016-11-22 22:54:42 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2016-11-22 22:54:42 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Set Features - Keep Alive Timer (%u ms)\n", cmd->cdw11);
|
2016-11-22 22:54:42 +00:00
|
|
|
|
|
|
|
if (cmd->cdw11 == 0) {
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_KEEP_ALIVE_INVALID;
|
|
|
|
} else if (cmd->cdw11 < MIN_KEEP_ALIVE_TIMEOUT) {
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->kato = MIN_KEEP_ALIVE_TIMEOUT;
|
2016-11-22 22:54:42 +00:00
|
|
|
} else {
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->kato = cmd->cdw11;
|
2016-11-22 22:54:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Set Features - Keep Alive Timer set to %u ms\n", ctrlr->kato);
|
2016-11-22 22:54:42 +00:00
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_get_features_keep_alive_timer(struct spdk_nvmf_request *req)
|
2016-11-22 22:54:42 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2016-11-22 22:54:42 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get Features - Keep Alive Timer\n");
|
2017-07-13 21:18:08 +00:00
|
|
|
rsp->cdw0 = ctrlr->kato;
|
2016-11-22 22:54:42 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2016-11-22 23:08:50 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_set_features_number_of_queues(struct spdk_nvmf_request *req)
|
2016-11-22 23:08:50 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2016-11-22 23:08:50 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
uint32_t nr_io_queues;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Set Features - Number of Queues, cdw11 0x%x\n",
|
2016-11-22 23:08:50 +00:00
|
|
|
req->cmd->nvme_cmd.cdw11);
|
|
|
|
|
|
|
|
/* Extra 1 connection for Admin queue */
|
2017-07-13 21:30:28 +00:00
|
|
|
nr_io_queues = ctrlr->max_qpairs_allowed - 1;
|
2016-11-22 23:08:50 +00:00
|
|
|
|
|
|
|
/* verify that the contoller is ready to process commands */
|
2017-07-13 21:30:28 +00:00
|
|
|
if (ctrlr->num_qpairs > 1) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Queue pairs already active!\n");
|
2016-11-22 23:08:50 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
|
|
|
|
} else {
|
|
|
|
/* Number of IO queues has a zero based value */
|
|
|
|
rsp->cdw0 = ((nr_io_queues - 1) << 16) |
|
|
|
|
(nr_io_queues - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_get_features_number_of_queues(struct spdk_nvmf_request *req)
|
2016-11-22 23:08:50 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2016-11-22 23:08:50 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
uint32_t nr_io_queues;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get Features - Number of Queues\n");
|
2016-11-22 23:08:50 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
nr_io_queues = ctrlr->max_qpairs_allowed - 1;
|
2016-11-22 23:08:50 +00:00
|
|
|
|
|
|
|
/* Number of IO queues has a zero based value */
|
|
|
|
rsp->cdw0 = ((nr_io_queues - 1) << 16) |
|
|
|
|
(nr_io_queues - 1);
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2017-02-14 23:56:29 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_get_features_write_cache(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get Features - Write Cache\n");
|
2017-08-17 23:28:00 +00:00
|
|
|
rsp->cdw0 = 1;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_set_features_async_event_configuration(struct spdk_nvmf_request *req)
|
2017-02-14 23:56:29 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2017-02-14 23:56:29 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Set Features - Async Event Configuration, cdw11 0x%08x\n",
|
2017-02-14 23:56:29 +00:00
|
|
|
cmd->cdw11);
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->async_event_config.raw = cmd->cdw11;
|
2017-02-14 23:56:29 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_get_features_async_event_configuration(struct spdk_nvmf_request *req)
|
2017-02-14 23:56:29 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2017-02-14 23:56:29 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get Features - Async Event Configuration\n");
|
2017-07-13 21:18:08 +00:00
|
|
|
rsp->cdw0 = ctrlr->async_event_config.raw;
|
2017-02-14 23:56:29 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2017-03-01 17:53:18 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_ctrlr_async_event_request(struct spdk_nvmf_request *req)
|
2017-03-01 17:53:18 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
2017-03-01 17:56:26 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
2017-03-01 17:53:18 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Async Event Request\n");
|
2017-03-01 17:53:18 +00:00
|
|
|
|
2017-08-17 02:08:50 +00:00
|
|
|
/* Only one asynchronous event is supported for now */
|
2017-07-13 21:18:08 +00:00
|
|
|
if (ctrlr->aer_req != NULL) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "AERL exceeded\n");
|
2017-03-01 17:56:26 +00:00
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_ASYNC_EVENT_REQUEST_LIMIT_EXCEEDED;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
ctrlr->aer_req = req;
|
2017-03-01 17:53:18 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
|
|
|
|
}
|
2017-08-17 01:13:49 +00:00
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-08-17 01:13:49 +00:00
|
|
|
spdk_nvmf_ctrlr_get_log_page(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem = req->qpair->ctrlr->subsys;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
uint64_t offset, len;
|
|
|
|
uint32_t numdl, numdu;
|
|
|
|
uint8_t lid;
|
|
|
|
|
|
|
|
if (req->data == NULL) {
|
|
|
|
SPDK_ERRLOG("get log command with no buffer\n");
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = (uint64_t)cmd->cdw12 | ((uint64_t)cmd->cdw13 << 32);
|
|
|
|
if (offset & 3) {
|
|
|
|
SPDK_ERRLOG("Invalid log page offset 0x%" PRIx64 "\n", offset);
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
numdl = (cmd->cdw10 >> 16) & 0xFFFFu;
|
|
|
|
numdu = (cmd->cdw11) & 0xFFFFu;
|
|
|
|
len = ((numdu << 16) + numdl + (uint64_t)1) * 4;
|
|
|
|
if (len > req->length) {
|
|
|
|
SPDK_ERRLOG("Get log page: len (%" PRIu64 ") > buf size (%u)\n",
|
|
|
|
len, req->length);
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lid = cmd->cdw10 & 0xFF;
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Get log page: LID=0x%02X offset=0x%" PRIx64 " len=0x%" PRIx64 "\n",
|
2017-08-17 01:13:49 +00:00
|
|
|
lid, offset, len);
|
|
|
|
|
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
|
|
|
switch (lid) {
|
|
|
|
case SPDK_NVME_LOG_DISCOVERY:
|
2017-08-21 20:58:04 +00:00
|
|
|
spdk_nvmf_get_discovery_log_page(subsystem->tgt, req->data, offset, len);
|
2017-08-17 01:13:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
default:
|
|
|
|
goto invalid_log_page;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (lid) {
|
|
|
|
case SPDK_NVME_LOG_ERROR:
|
|
|
|
case SPDK_NVME_LOG_HEALTH_INFORMATION:
|
|
|
|
case SPDK_NVME_LOG_FIRMWARE_SLOT:
|
|
|
|
/* TODO: actually fill out log page data */
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
default:
|
|
|
|
goto invalid_log_page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid_log_page:
|
|
|
|
SPDK_ERRLOG("Unsupported Get Log Page 0x%02X\n", lid);
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2017-08-17 02:08:50 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
struct spdk_nvme_cmd *cmd,
|
|
|
|
struct spdk_nvme_cpl *rsp,
|
|
|
|
struct spdk_nvme_ns_data *nsdata)
|
|
|
|
{
|
2017-08-18 01:20:49 +00:00
|
|
|
struct spdk_nvmf_ns *ns;
|
2017-08-17 02:08:50 +00:00
|
|
|
|
2017-08-18 01:20:49 +00:00
|
|
|
ns = _spdk_nvmf_subsystem_get_ns(subsystem, cmd->nsid);
|
|
|
|
if (ns == NULL || ns->bdev == NULL) {
|
2017-08-17 02:08:50 +00:00
|
|
|
SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-18 01:20:49 +00:00
|
|
|
return spdk_nvmf_bdev_ctrlr_identify_ns(ns->bdev, nsdata);
|
2017-08-17 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_identify_ctrlr(struct spdk_nvmf_ctrlr *ctrlr, struct spdk_nvme_ctrlr_data *cdata)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
|
2017-08-22 23:29:41 +00:00
|
|
|
struct spdk_nvmf_tgt *tgt = subsystem->tgt;
|
2017-08-17 02:08:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Common fields for discovery and NVM subsystems
|
|
|
|
*/
|
|
|
|
spdk_strcpy_pad(cdata->fr, FW_VERSION, sizeof(cdata->fr), ' ');
|
2017-08-22 23:29:41 +00:00
|
|
|
assert((tgt->opts.max_io_size % 4096) == 0);
|
|
|
|
cdata->mdts = spdk_u32log2(tgt->opts.max_io_size / 4096);
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->cntlid = ctrlr->cntlid;
|
|
|
|
cdata->ver = ctrlr->vcprop.vs;
|
|
|
|
cdata->lpa.edlp = 1;
|
|
|
|
cdata->elpe = 127;
|
2017-08-22 23:29:41 +00:00
|
|
|
cdata->maxcmd = tgt->opts.max_queue_depth;
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->sgls.supported = 1;
|
|
|
|
cdata->sgls.keyed_sgl = 1;
|
|
|
|
cdata->sgls.sgl_offset = 1;
|
|
|
|
spdk_strcpy_pad(cdata->subnqn, subsystem->subnqn, sizeof(cdata->subnqn), '\0');
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ctrlr data: maxcmd 0x%x\n", cdata->maxcmd);
|
2017-09-07 00:17:42 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "sgls data: 0x%x\n", from_le32(&cdata->sgls));
|
2017-08-17 02:08:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NVM subsystem fields (reserved for discovery subsystems)
|
|
|
|
*/
|
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) {
|
|
|
|
spdk_strcpy_pad(cdata->mn, MODEL_NUMBER, sizeof(cdata->mn), ' ');
|
|
|
|
spdk_strcpy_pad(cdata->sn, spdk_nvmf_subsystem_get_sn(subsystem), sizeof(cdata->sn), ' ');
|
|
|
|
cdata->aerl = 0;
|
|
|
|
cdata->kas = 10;
|
|
|
|
|
|
|
|
cdata->rab = 6;
|
|
|
|
cdata->ctratt.host_id_exhid_supported = 1;
|
|
|
|
cdata->aerl = 0;
|
|
|
|
cdata->frmw.slot1_ro = 1;
|
|
|
|
cdata->frmw.num_slots = 1;
|
|
|
|
|
|
|
|
cdata->sqes.min = 6;
|
|
|
|
cdata->sqes.max = 6;
|
|
|
|
cdata->cqes.min = 4;
|
|
|
|
cdata->cqes.max = 4;
|
2017-08-18 01:20:49 +00:00
|
|
|
cdata->nn = subsystem->max_nsid;
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->vwc.present = 1;
|
|
|
|
|
|
|
|
cdata->nvmf_specific.ioccsz = sizeof(struct spdk_nvme_cmd) / 16;
|
|
|
|
cdata->nvmf_specific.iorcsz = sizeof(struct spdk_nvme_cpl) / 16;
|
|
|
|
cdata->nvmf_specific.icdoff = 0; /* offset starts directly after SQE */
|
|
|
|
cdata->nvmf_specific.ctrattr.ctrlr_model = SPDK_NVMF_CTRLR_MODEL_DYNAMIC;
|
|
|
|
cdata->nvmf_specific.msdbd = 1; /* target supports single SGL in capsule */
|
|
|
|
|
|
|
|
/* TODO: this should be set by the transport */
|
2017-08-22 23:29:41 +00:00
|
|
|
cdata->nvmf_specific.ioccsz += tgt->opts.in_capsule_data_size / 16;
|
2017-08-17 02:08:50 +00:00
|
|
|
|
|
|
|
cdata->oncs.dsm = spdk_nvmf_ctrlr_dsm_supported(ctrlr);
|
2017-09-06 00:26:14 +00:00
|
|
|
cdata->oncs.write_zeroes = spdk_nvmf_ctrlr_write_zeroes_supported(ctrlr);
|
2017-08-17 02:08:50 +00:00
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ext ctrlr data: ioccsz 0x%x\n",
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->nvmf_specific.ioccsz);
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ext ctrlr data: iorcsz 0x%x\n",
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->nvmf_specific.iorcsz);
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ext ctrlr data: icdoff 0x%x\n",
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->nvmf_specific.icdoff);
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ext ctrlr data: ctrattr 0x%x\n",
|
2017-08-17 02:08:50 +00:00
|
|
|
*(uint8_t *)&cdata->nvmf_specific.ctrattr);
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "ext ctrlr data: msdbd 0x%x\n",
|
2017-08-17 02:08:50 +00:00
|
|
|
cdata->nvmf_specific.msdbd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
struct spdk_nvme_cmd *cmd,
|
|
|
|
struct spdk_nvme_cpl *rsp,
|
|
|
|
struct spdk_nvme_ns_list *ns_list)
|
|
|
|
{
|
2017-08-18 01:20:49 +00:00
|
|
|
struct spdk_nvmf_ns *ns;
|
|
|
|
uint32_t count = 0;
|
2017-08-17 02:08:50 +00:00
|
|
|
|
|
|
|
if (cmd->nsid >= 0xfffffffeUL) {
|
|
|
|
SPDK_ERRLOG("Identify Active Namespace List with invalid NSID %u\n", cmd->nsid);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-18 01:20:49 +00:00
|
|
|
for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
|
|
|
|
ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
|
|
|
|
if (ns->id <= cmd->nsid) {
|
2017-08-17 02:08:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-18 01:20:49 +00:00
|
|
|
|
|
|
|
ns_list->ns_list[count++] = ns->id;
|
2017-08-17 02:08:50 +00:00
|
|
|
if (count == SPDK_COUNTOF(ns_list->ns_list)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
static int
|
2017-08-17 02:08:50 +00:00
|
|
|
spdk_nvmf_ctrlr_identify(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
uint8_t cns;
|
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
|
|
|
|
|
|
|
|
if (req->data == NULL || req->length < 4096) {
|
|
|
|
SPDK_ERRLOG("identify command with invalid buffer\n");
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cns = cmd->cdw10 & 0xFF;
|
|
|
|
|
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY &&
|
|
|
|
cns != SPDK_NVME_IDENTIFY_CTRLR) {
|
|
|
|
/* Discovery controllers only support Identify Controller */
|
|
|
|
goto invalid_cns;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cns) {
|
|
|
|
case SPDK_NVME_IDENTIFY_NS:
|
|
|
|
return spdk_nvmf_ctrlr_identify_ns(subsystem, cmd, rsp, req->data);
|
|
|
|
case SPDK_NVME_IDENTIFY_CTRLR:
|
|
|
|
return spdk_nvmf_ctrlr_identify_ctrlr(ctrlr, req->data);
|
|
|
|
case SPDK_NVME_IDENTIFY_ACTIVE_NS_LIST:
|
|
|
|
return spdk_nvmf_ctrlr_identify_active_ns_list(subsystem, cmd, rsp, req->data);
|
|
|
|
default:
|
|
|
|
goto invalid_cns;
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid_cns:
|
|
|
|
SPDK_ERRLOG("Identify command with unsupported CNS 0x%02x\n", cns);
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2017-08-17 23:28:00 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_abort(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
|
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
uint32_t cdw10 = cmd->cdw10;
|
|
|
|
uint16_t cid = cdw10 >> 16;
|
|
|
|
uint16_t sqid = cdw10 & 0xFFFFu;
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_request *req_to_abort;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "abort sqid=%u cid=%u\n", sqid, cid);
|
2017-08-17 23:28:00 +00:00
|
|
|
|
|
|
|
rsp->cdw0 = 1; /* Command not aborted */
|
|
|
|
|
|
|
|
qpair = spdk_nvmf_ctrlr_get_qpair(ctrlr, sqid);
|
|
|
|
if (qpair == NULL) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "sqid %u not found\n", sqid);
|
2017-08-17 23:28:00 +00:00
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: This relies on the assumption that all connections for a ctrlr will be handled
|
|
|
|
* on the same thread. If this assumption becomes untrue, this will need to pass a message
|
|
|
|
* to the thread handling qpair, and the abort will need to be asynchronous.
|
|
|
|
*/
|
|
|
|
req_to_abort = spdk_nvmf_qpair_get_request(qpair, cid);
|
|
|
|
if (req_to_abort == NULL) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "cid %u not found\n", cid);
|
2017-08-17 23:28:00 +00:00
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_request_abort(req_to_abort) == 0) {
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "abort ctrlr=%p req=%p sqid=%u cid=%u successful\n",
|
2017-08-17 23:28:00 +00:00
|
|
|
ctrlr, req_to_abort, sqid, cid);
|
|
|
|
rsp->cdw0 = 0; /* Command successfully aborted */
|
|
|
|
}
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_get_features(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
uint8_t feature;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
feature = cmd->cdw10 & 0xff; /* mask out the FID value */
|
|
|
|
switch (feature) {
|
|
|
|
case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
|
|
|
|
return spdk_nvmf_ctrlr_get_features_number_of_queues(req);
|
|
|
|
case SPDK_NVME_FEAT_VOLATILE_WRITE_CACHE:
|
|
|
|
return spdk_nvmf_ctrlr_get_features_write_cache(req);
|
|
|
|
case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
|
|
|
|
return spdk_nvmf_ctrlr_get_features_keep_alive_timer(req);
|
|
|
|
case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
|
|
|
|
return spdk_nvmf_ctrlr_get_features_async_event_configuration(req);
|
|
|
|
case SPDK_NVME_FEAT_HOST_IDENTIFIER:
|
|
|
|
return spdk_nvmf_ctrlr_get_features_host_identifier(req);
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Get Features command with unsupported feature ID 0x%02x\n", feature);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_set_features(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
uint8_t feature;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
feature = cmd->cdw10 & 0xff; /* mask out the FID value */
|
|
|
|
switch (feature) {
|
|
|
|
case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
|
|
|
|
return spdk_nvmf_ctrlr_set_features_number_of_queues(req);
|
|
|
|
case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
|
|
|
|
return spdk_nvmf_ctrlr_set_features_keep_alive_timer(req);
|
|
|
|
case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
|
|
|
|
return spdk_nvmf_ctrlr_set_features_async_event_configuration(req);
|
|
|
|
case SPDK_NVME_FEAT_HOST_IDENTIFIER:
|
|
|
|
return spdk_nvmf_ctrlr_set_features_host_identifier(req);
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Set Features command with unsupported feature ID 0x%02x\n", feature);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_ctrlr_keep_alive(struct spdk_nvmf_request *req)
|
|
|
|
{
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Keep Alive\n");
|
2017-08-17 23:28:00 +00:00
|
|
|
/*
|
|
|
|
* To handle keep alive just clear or reset the
|
|
|
|
* ctrlr based keep alive duration counter.
|
|
|
|
* When added, a separate timer based process
|
|
|
|
* will monitor if the time since last recorded
|
|
|
|
* keep alive has exceeded the max duration and
|
|
|
|
* take appropriate action.
|
|
|
|
*/
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem = req->qpair->ctrlr->subsys;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-08-28 20:02:12 +00:00
|
|
|
if (req->data && spdk_nvme_opc_get_data_transfer(cmd->opc) == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
|
|
|
memset(req->data, 0, req->length);
|
|
|
|
}
|
|
|
|
|
2017-08-17 23:28:00 +00:00
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
|
|
|
/* Discovery controllers only support Get Log Page and Identify */
|
|
|
|
switch (cmd->opc) {
|
|
|
|
case SPDK_NVME_OPC_IDENTIFY:
|
|
|
|
case SPDK_NVME_OPC_GET_LOG_PAGE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_opcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd->opc) {
|
|
|
|
case SPDK_NVME_OPC_GET_LOG_PAGE:
|
|
|
|
return spdk_nvmf_ctrlr_get_log_page(req);
|
|
|
|
case SPDK_NVME_OPC_IDENTIFY:
|
|
|
|
return spdk_nvmf_ctrlr_identify(req);
|
|
|
|
case SPDK_NVME_OPC_ABORT:
|
|
|
|
return spdk_nvmf_ctrlr_abort(req);
|
|
|
|
case SPDK_NVME_OPC_GET_FEATURES:
|
|
|
|
return spdk_nvmf_ctrlr_get_features(req);
|
|
|
|
case SPDK_NVME_OPC_SET_FEATURES:
|
|
|
|
return spdk_nvmf_ctrlr_set_features(req);
|
|
|
|
case SPDK_NVME_OPC_ASYNC_EVENT_REQUEST:
|
|
|
|
return spdk_nvmf_ctrlr_async_event_request(req);
|
|
|
|
case SPDK_NVME_OPC_KEEP_ALIVE:
|
|
|
|
return spdk_nvmf_ctrlr_keep_alive(req);
|
|
|
|
|
|
|
|
case SPDK_NVME_OPC_CREATE_IO_SQ:
|
|
|
|
case SPDK_NVME_OPC_CREATE_IO_CQ:
|
|
|
|
case SPDK_NVME_OPC_DELETE_IO_SQ:
|
|
|
|
case SPDK_NVME_OPC_DELETE_IO_CQ:
|
|
|
|
/* Create and Delete I/O CQ/SQ not allowed in NVMe-oF */
|
|
|
|
goto invalid_opcode;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto invalid_opcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid_opcode:
|
|
|
|
SPDK_ERRLOG("Unsupported admin opcode 0x%x\n", cmd->opc);
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|