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.
|
|
|
|
*/
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
#include <arpa/inet.h>
|
2016-06-06 21:44:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "session.h"
|
|
|
|
#include "nvmf_internal.h"
|
2016-07-25 15:58:13 +00:00
|
|
|
#include "request.h"
|
2016-07-06 17:50:44 +00:00
|
|
|
#include "subsystem.h"
|
2016-07-14 22:25:23 +00:00
|
|
|
#include "transport.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/trace.h"
|
2016-06-22 23:23:36 +00:00
|
|
|
#include "spdk/nvme_spec.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-22 23:23:36 +00:00
|
|
|
static void
|
|
|
|
nvmf_init_discovery_session_properties(struct nvmf_session *session)
|
|
|
|
{
|
2016-07-21 22:10:09 +00:00
|
|
|
session->vcdata.maxcmd = g_nvmf_tgt.max_queue_depth;
|
2016-06-22 23:23:36 +00:00
|
|
|
/* extended data for get log page supportted */
|
|
|
|
session->vcdata.lpa.edlp = 1;
|
2016-07-07 23:27:13 +00:00
|
|
|
session->vcdata.cntlid = 0; /* There is one controller per subsystem, so its id is 0 */
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.ioccsz = sizeof(struct spdk_nvme_cmd) / 16;
|
|
|
|
session->vcdata.nvmf_specific.iorcsz = sizeof(struct spdk_nvme_cpl) / 16;
|
|
|
|
session->vcdata.nvmf_specific.icdoff = 0; /* offset starts directly after SQE */
|
|
|
|
session->vcdata.nvmf_specific.ctrattr.ctrlr_model = SPDK_NVMF_CTRLR_MODEL_DYNAMIC;
|
|
|
|
session->vcdata.nvmf_specific.msdbd = 1; /* target supports single SGL in capsule */
|
2016-06-22 23:23:36 +00:00
|
|
|
session->vcdata.sgls.keyed_sgl = 1;
|
|
|
|
session->vcdata.sgls.sgl_offset = 1;
|
|
|
|
|
2016-08-19 18:13:25 +00:00
|
|
|
strncpy((char *)session->vcdata.subnqn, SPDK_NVMF_DISCOVERY_NQN, sizeof(session->vcdata.subnqn));
|
|
|
|
|
2016-06-22 23:23:36 +00:00
|
|
|
/* Properties */
|
2016-07-06 22:41:59 +00:00
|
|
|
session->vcprop.cap.raw = 0;
|
|
|
|
session->vcprop.cap.bits.cqr = 1; /* NVMF specification required */
|
|
|
|
session->vcprop.cap.bits.mqes = (session->vcdata.maxcmd - 1); /* max queue depth */
|
|
|
|
session->vcprop.cap.bits.ams = 0; /* optional arb mechanisms */
|
|
|
|
session->vcprop.cap.bits.dstrd = 0; /* fixed to 0 for NVMf */
|
|
|
|
session->vcprop.cap.bits.css_nvm = 1; /* NVM command set */
|
|
|
|
session->vcprop.cap.bits.mpsmin = 0; /* 2 ^ 12 + mpsmin == 4k */
|
|
|
|
session->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 */
|
2016-07-07 22:32:04 +00:00
|
|
|
session->vcprop.vs.bits.mjr = 1;
|
2016-07-25 23:29:57 +00:00
|
|
|
session->vcprop.vs.bits.mnr = 2;
|
|
|
|
session->vcprop.vs.bits.ter = 1;
|
|
|
|
session->vcdata.ver = session->vcprop.vs;
|
2016-06-22 23:23:36 +00:00
|
|
|
|
|
|
|
session->vcprop.cc.raw = 0;
|
|
|
|
|
|
|
|
session->vcprop.csts.raw = 0;
|
|
|
|
session->vcprop.csts.bits.rdy = 0; /* Init controller as not ready */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-07-07 23:05:39 +00:00
|
|
|
nvmf_init_nvme_session_properties(struct nvmf_session *session)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-07-25 21:22:58 +00:00
|
|
|
assert((g_nvmf_tgt.max_io_size % 4096) == 0);
|
|
|
|
|
2016-08-01 06:02:59 +00:00
|
|
|
/* Init the controller details */
|
2016-08-29 08:20:34 +00:00
|
|
|
session->subsys->ops->ctrlr_get_data(session);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
session->vcdata.aerl = 0;
|
2016-07-07 23:27:13 +00:00
|
|
|
session->vcdata.cntlid = 0;
|
2016-06-23 21:27:40 +00:00
|
|
|
session->vcdata.kas = 10;
|
2016-07-21 22:10:09 +00:00
|
|
|
session->vcdata.maxcmd = g_nvmf_tgt.max_queue_depth;
|
2016-07-25 21:22:58 +00:00
|
|
|
session->vcdata.mdts = nvmf_u32log2(g_nvmf_tgt.max_io_size / 4096);
|
2016-07-07 22:42:05 +00:00
|
|
|
session->vcdata.sgls.keyed_sgl = 1;
|
|
|
|
session->vcdata.sgls.sgl_offset = 1;
|
|
|
|
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.ioccsz = sizeof(struct spdk_nvme_cmd) / 16;
|
|
|
|
session->vcdata.nvmf_specific.iorcsz = sizeof(struct spdk_nvme_cpl) / 16;
|
|
|
|
session->vcdata.nvmf_specific.icdoff = 0; /* offset starts directly after SQE */
|
|
|
|
session->vcdata.nvmf_specific.ctrattr.ctrlr_model = SPDK_NVMF_CTRLR_MODEL_DYNAMIC;
|
|
|
|
session->vcdata.nvmf_specific.msdbd = 1; /* target supports single SGL in capsule */
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-21 22:38:32 +00:00
|
|
|
/* TODO: this should be set by the transport */
|
2016-07-28 17:23:52 +00:00
|
|
|
session->vcdata.nvmf_specific.ioccsz += g_nvmf_tgt.in_capsule_data_size / 16;
|
2016-07-21 22:38:32 +00:00
|
|
|
|
2016-08-19 18:13:25 +00:00
|
|
|
strncpy((char *)session->vcdata.subnqn, session->subsys->subnqn, sizeof(session->vcdata.subnqn));
|
|
|
|
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ctrlr data: maxcmd %x\n",
|
2016-06-23 21:27:40 +00:00
|
|
|
session->vcdata.maxcmd);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ext ctrlr data: ioccsz %x\n",
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.ioccsz);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ext ctrlr data: iorcsz %x\n",
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.iorcsz);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ext ctrlr data: icdoff %x\n",
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.icdoff);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ext ctrlr data: ctrattr %x\n",
|
2016-07-25 16:31:08 +00:00
|
|
|
*(uint8_t *)&session->vcdata.nvmf_specific.ctrattr);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " ext ctrlr data: msdbd %x\n",
|
2016-07-25 16:31:08 +00:00
|
|
|
session->vcdata.nvmf_specific.msdbd);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " sgls data: 0x%x\n",
|
2016-06-23 21:27:40 +00:00
|
|
|
*(uint32_t *)&session->vcdata.sgls);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-06 22:41:59 +00:00
|
|
|
session->vcprop.cap.raw = 0;
|
2016-07-25 16:40:50 +00:00
|
|
|
session->vcprop.cap.bits.cqr = 1;
|
2016-07-06 22:41:59 +00:00
|
|
|
session->vcprop.cap.bits.mqes = (session->vcdata.maxcmd - 1); /* max queue depth */
|
|
|
|
session->vcprop.cap.bits.ams = 0; /* optional arb mechanisms */
|
|
|
|
session->vcprop.cap.bits.to = 1; /* ready timeout - 500 msec units */
|
|
|
|
session->vcprop.cap.bits.dstrd = 0; /* fixed to 0 for NVMf */
|
|
|
|
session->vcprop.cap.bits.css_nvm = 1; /* NVM command set */
|
|
|
|
session->vcprop.cap.bits.mpsmin = 0; /* 2 ^ 12 + mpsmin == 4k */
|
|
|
|
session->vcprop.cap.bits.mpsmax = 0; /* 2 ^ 12 + mpsmax == 4k */
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-25 23:29:57 +00:00
|
|
|
/* Report at least version 1.2.1 */
|
|
|
|
if (session->vcprop.vs.raw < SPDK_NVME_VERSION(1, 2, 1)) {
|
|
|
|
session->vcprop.vs.bits.mjr = 1;
|
|
|
|
session->vcprop.vs.bits.mnr = 2;
|
|
|
|
session->vcprop.vs.bits.ter = 1;
|
|
|
|
session->vcdata.ver = session->vcprop.vs;
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
session->vcprop.cc.raw = 0;
|
|
|
|
session->vcprop.cc.bits.en = 0; /* Init controller disabled */
|
|
|
|
|
|
|
|
session->vcprop.csts.raw = 0;
|
|
|
|
session->vcprop.csts.bits.rdy = 0; /* Init controller as not ready */
|
|
|
|
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " cap %" PRIx64 "\n",
|
2016-07-06 22:41:59 +00:00
|
|
|
session->vcprop.cap.raw);
|
2016-07-14 20:32:33 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " vs %x\n", session->vcprop.vs.raw);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " cc %x\n", session->vcprop.cc.raw);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " csts %x\n",
|
2016-06-06 21:44:30 +00:00
|
|
|
session->vcprop.csts.raw);
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:13:12 +00:00
|
|
|
static void session_destruct(struct nvmf_session *session)
|
2016-07-07 23:08:48 +00:00
|
|
|
{
|
2016-07-07 23:32:26 +00:00
|
|
|
session->subsys->session = NULL;
|
2016-09-12 05:13:12 +00:00
|
|
|
session->transport->session_fini(session);
|
|
|
|
free(session);
|
|
|
|
}
|
2016-07-11 21:08:31 +00:00
|
|
|
|
2016-09-12 05:13:12 +00:00
|
|
|
void
|
|
|
|
spdk_nvmf_session_destruct(struct nvmf_session *session)
|
|
|
|
{
|
2016-07-11 21:08:31 +00:00
|
|
|
while (!TAILQ_EMPTY(&session->connections)) {
|
|
|
|
struct spdk_nvmf_conn *conn = TAILQ_FIRST(&session->connections);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&session->connections, conn, link);
|
2016-07-22 22:55:59 +00:00
|
|
|
session->num_connections--;
|
2016-07-15 21:45:26 +00:00
|
|
|
conn->transport->conn_fini(conn);
|
2016-07-11 21:08:31 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 05:13:12 +00:00
|
|
|
session_destruct(session);
|
2016-07-07 23:08:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
static void
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_session_connect(struct spdk_nvmf_conn *conn,
|
|
|
|
struct spdk_nvmf_fabric_connect_cmd *cmd,
|
|
|
|
struct spdk_nvmf_fabric_connect_data *data,
|
|
|
|
struct spdk_nvmf_fabric_connect_rsp *rsp)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-07-14 00:23:23 +00:00
|
|
|
struct nvmf_session *session;
|
2016-06-06 21:44:30 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
#define INVALID_CONNECT_CMD(field) invalid_connect_response(rsp, 0, offsetof(struct spdk_nvmf_fabric_connect_cmd, field))
|
|
|
|
#define INVALID_CONNECT_DATA(field) invalid_connect_response(rsp, 1, offsetof(struct spdk_nvmf_fabric_connect_data, field))
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "recfmt 0x%x qid %u sqsize %u\n",
|
|
|
|
cmd->recfmt, cmd->qid, cmd->sqsize);
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Connect data:\n");
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " cntlid: 0x%04x\n", data->cntlid);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " hostid: %08x-%04x-%04x-%02x%02x-%04x%08x ***\n",
|
|
|
|
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]));
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " subnqn: \"%s\"\n", data->subnqn);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, " hostnqn: \"%s\"\n", data->hostnqn);
|
|
|
|
|
2016-07-15 21:16:59 +00:00
|
|
|
subsystem = nvmf_find_subsystem(data->subnqn, data->hostnqn);
|
2016-07-07 23:27:13 +00:00
|
|
|
if (subsystem == NULL) {
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_ERRLOG("Could not find subsystem '%s'\n", data->subnqn);
|
|
|
|
INVALID_CONNECT_DATA(subnqn);
|
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (cmd->sqsize == 0 || cmd->sqsize >= g_nvmf_tgt.max_queue_depth) {
|
|
|
|
SPDK_ERRLOG("Invalid SQSIZE %u (min 1, max %u)\n",
|
|
|
|
cmd->sqsize, g_nvmf_tgt.max_queue_depth - 1);
|
|
|
|
INVALID_CONNECT_CMD(sqsize);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-05 22:06:05 +00:00
|
|
|
conn->sq_head_max = cmd->sqsize;
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
if (cmd->qid == 0) {
|
|
|
|
conn->type = CONN_TYPE_AQ;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_TRACELOG(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);
|
|
|
|
INVALID_CONNECT_DATA(cntlid);
|
|
|
|
return;
|
2016-06-30 18:18:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
if (subsystem->session) {
|
|
|
|
SPDK_ERRLOG("Cannot connect to already-connected controller\n");
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
rsp->status.sc = SPDK_NVMF_FABRIC_SC_CONTROLLER_BUSY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Establish a new session */
|
|
|
|
subsystem->session = session = calloc(1, sizeof(struct nvmf_session));
|
2016-06-30 18:18:52 +00:00
|
|
|
if (session == NULL) {
|
2016-07-14 00:23:23 +00:00
|
|
|
SPDK_ERRLOG("Memory allocation failure\n");
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_INIT(&session->connections);
|
2016-08-15 01:16:49 +00:00
|
|
|
session->kato = cmd->kato;
|
2016-07-14 00:23:23 +00:00
|
|
|
session->num_connections = 0;
|
|
|
|
session->subsys = subsystem;
|
2016-07-18 22:17:32 +00:00
|
|
|
session->max_connections_allowed = g_nvmf_tgt.max_queues_per_session;
|
2016-07-26 23:34:12 +00:00
|
|
|
if (conn->transport->session_init(session, conn)) {
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
2016-09-12 07:31:17 +00:00
|
|
|
conn->transport->session_fini(session);
|
|
|
|
free(session);
|
|
|
|
subsystem->session = NULL;
|
2016-07-26 23:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-07-14 00:23:23 +00:00
|
|
|
|
2016-07-15 20:10:33 +00:00
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) {
|
2016-07-14 00:23:23 +00:00
|
|
|
nvmf_init_nvme_session_properties(session);
|
|
|
|
} else {
|
|
|
|
nvmf_init_discovery_session_properties(session);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-07-14 00:23:23 +00:00
|
|
|
conn->type = CONN_TYPE_IOQ;
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Connect I/O Queue for controller id 0x%x\n", data->cntlid);
|
|
|
|
|
|
|
|
/* We always return CNTLID 0, so verify that the I/O connect CNTLID matches */
|
|
|
|
if (data->cntlid != 0) {
|
|
|
|
SPDK_ERRLOG("Unknown controller ID 0x%x\n", data->cntlid);
|
|
|
|
INVALID_CONNECT_DATA(cntlid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session = subsystem->session;
|
|
|
|
if (session == NULL || !session->vcprop.cc.bits.en) {
|
|
|
|
SPDK_ERRLOG("Got I/O connect before ctrlr was enabled\n");
|
|
|
|
INVALID_CONNECT_CMD(qid);
|
|
|
|
return;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-30 18:18:52 +00:00
|
|
|
|
2016-07-18 18:16:32 +00:00
|
|
|
if (1u << session->vcprop.cc.bits.iosqes != sizeof(struct spdk_nvme_cmd)) {
|
|
|
|
SPDK_ERRLOG("Got I/O connect with invalid IOSQES %u\n",
|
|
|
|
session->vcprop.cc.bits.iosqes);
|
|
|
|
INVALID_CONNECT_CMD(qid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1u << session->vcprop.cc.bits.iocqes != sizeof(struct spdk_nvme_cpl)) {
|
|
|
|
SPDK_ERRLOG("Got I/O connect with invalid IOCQES %u\n",
|
|
|
|
session->vcprop.cc.bits.iocqes);
|
|
|
|
INVALID_CONNECT_CMD(qid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
/* check if we would exceed session connection limit */
|
|
|
|
if (session->num_connections >= session->max_connections_allowed) {
|
|
|
|
SPDK_ERRLOG("connection limit %d\n", session->num_connections);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session->num_connections++;
|
2016-06-30 18:18:52 +00:00
|
|
|
TAILQ_INSERT_HEAD(&session->connections, conn, link);
|
2016-07-14 00:23:23 +00:00
|
|
|
conn->sess = session;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-14 00:23:23 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
rsp->status_code_specific.success.cntlid = 0;
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "connect capsule response: cntlid = 0x%04x\n",
|
|
|
|
rsp->status_code_specific.success.cntlid);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-12 05:13:12 +00:00
|
|
|
spdk_nvmf_session_disconnect(struct spdk_nvmf_conn *conn)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-08-25 22:00:50 +00:00
|
|
|
struct nvmf_session *session = conn->sess;
|
|
|
|
|
2016-09-12 05:13:12 +00:00
|
|
|
assert(session != NULL);
|
2016-07-11 21:08:31 +00:00
|
|
|
session->num_connections--;
|
|
|
|
TAILQ_REMOVE(&session->connections, conn, link);
|
2016-07-22 22:55:59 +00:00
|
|
|
conn->transport->conn_fini(conn);
|
|
|
|
|
|
|
|
if (session->num_connections == 0) {
|
2016-09-12 05:13:12 +00:00
|
|
|
session_destruct(session);
|
2016-07-22 22:55:59 +00:00
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
static uint64_t
|
|
|
|
nvmf_prop_get_cap(struct nvmf_session *session)
|
|
|
|
{
|
|
|
|
return session->vcprop.cap.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
nvmf_prop_get_vs(struct nvmf_session *session)
|
|
|
|
{
|
|
|
|
return session->vcprop.vs.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
nvmf_prop_get_cc(struct nvmf_session *session)
|
|
|
|
{
|
|
|
|
return session->vcprop.cc.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
nvmf_prop_set_cc(struct nvmf_session *session, uint64_t value)
|
|
|
|
{
|
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;
|
|
|
|
|
2016-07-18 17:52:09 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "cur CC: 0x%08x\n", session->vcprop.cc.raw);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "new CC: 0x%08x\n", cc.raw);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
diff.raw = cc.raw ^ session->vcprop.cc.raw;
|
|
|
|
|
|
|
|
if (diff.bits.en) {
|
2016-07-18 16:13:15 +00:00
|
|
|
if (cc.bits.en) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Property Set CC Enable!\n");
|
2016-07-18 17:52:09 +00:00
|
|
|
session->vcprop.cc.bits.en = 1;
|
2016-07-18 16:13:15 +00:00
|
|
|
session->vcprop.csts.bits.rdy = 1;
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("CC.EN transition from 1 to 0 (reset) not implemented!\n");
|
|
|
|
/* TODO: reset */
|
|
|
|
}
|
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) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Property Set CC Shutdown %u%ub!\n",
|
|
|
|
cc.bits.shn >> 1, cc.bits.shn & 1);
|
|
|
|
session->vcprop.cc.bits.shn = cc.bits.shn;
|
|
|
|
session->vcprop.cc.bits.en = 0;
|
|
|
|
session->vcprop.csts.bits.rdy = 0;
|
|
|
|
session->vcprop.csts.bits.shst = SPDK_NVME_SHST_COMPLETE;
|
|
|
|
} else if (cc.bits.shn == 0) {
|
|
|
|
session->vcprop.cc.bits.shn = 0;
|
|
|
|
} 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) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Prop Set IOSQES = %u (%u bytes)\n",
|
|
|
|
cc.bits.iosqes, 1u << cc.bits.iosqes);
|
|
|
|
session->vcprop.cc.bits.iosqes = cc.bits.iosqes;
|
|
|
|
diff.bits.iosqes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff.bits.iocqes) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Prop Set IOCQES = %u (%u bytes)\n",
|
|
|
|
cc.bits.iocqes, 1u << cc.bits.iocqes);
|
|
|
|
session->vcprop.cc.bits.iocqes = cc.bits.iocqes;
|
|
|
|
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
|
|
|
|
nvmf_prop_get_csts(struct nvmf_session *session)
|
|
|
|
{
|
|
|
|
return session->vcprop.csts.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nvmf_prop {
|
|
|
|
uint32_t ofst;
|
|
|
|
uint8_t size;
|
|
|
|
char name[11];
|
|
|
|
uint64_t (*get_cb)(struct nvmf_session *session);
|
|
|
|
bool (*set_cb)(struct nvmf_session *session, uint64_t value);
|
|
|
|
};
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(nvmf_props) / sizeof(*nvmf_props); i++) {
|
|
|
|
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
|
2016-09-23 02:05:45 +00:00
|
|
|
spdk_nvmf_property_get(struct nvmf_session *session,
|
|
|
|
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;
|
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "size %d, offset 0x%x\n",
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "name: %s\n", prop->name);
|
|
|
|
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
|
|
|
|
|
|
|
response->value.u64 = prop->get_cb(session);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "response value: 0x%" PRIx64 "\n", response->value.u64);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-23 02:05:45 +00:00
|
|
|
spdk_nvmf_property_set(struct nvmf_session *session,
|
|
|
|
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
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "size %d, offset 0x%x, value 0x%" PRIx64 "\n",
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:32:04 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "name: %s\n", prop->name);
|
|
|
|
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
|
|
|
|
|
|
|
if (!prop->set_cb(session, value)) {
|
|
|
|
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
|
|
|
|
spdk_nvmf_session_poll(struct nvmf_session *session)
|
2016-06-24 17:58:42 +00:00
|
|
|
{
|
2016-07-15 18:34:11 +00:00
|
|
|
struct spdk_nvmf_conn *conn, *tmp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(conn, &session->connections, link, tmp) {
|
2016-07-14 22:25:23 +00:00
|
|
|
if (conn->transport->conn_poll(conn) < 0) {
|
|
|
|
SPDK_ERRLOG("Transport poll failed for conn %p; closing connection\n", conn);
|
2016-09-12 05:13:12 +00:00
|
|
|
spdk_nvmf_session_disconnect(conn);
|
2016-07-15 18:34:11 +00:00
|
|
|
}
|
2016-06-24 17:58:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 18:34:11 +00:00
|
|
|
return 0;
|
2016-06-24 17:58:42 +00:00
|
|
|
}
|