2016-11-15 05:42:59 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NVMe over RDMA transport
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
#include <infiniband/verbs.h>
|
|
|
|
#include <rdma/rdma_cma.h>
|
|
|
|
#include <rdma/rdma_verbs.h>
|
|
|
|
|
|
|
|
#include "spdk/assert.h"
|
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
#include "spdk/event.h"
|
|
|
|
#include "spdk/queue.h"
|
|
|
|
#include "spdk/nvme.h"
|
|
|
|
#include "spdk/nvmf_spec.h"
|
2016-11-21 22:11:59 +00:00
|
|
|
#include "spdk/string.h"
|
2017-06-12 23:30:17 +00:00
|
|
|
#include "spdk/endian.h"
|
2018-06-12 20:03:49 +00:00
|
|
|
#include "spdk/likely.h"
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
#include "nvme_internal.h"
|
|
|
|
|
|
|
|
#define NVME_RDMA_TIME_OUT_IN_MS 2000
|
|
|
|
#define NVME_RDMA_RW_BUFFER_SIZE 131072
|
|
|
|
|
|
|
|
/*
|
2018-08-24 09:09:27 +00:00
|
|
|
NVME RDMA qpair Resource Defaults
|
2016-11-15 05:42:59 +00:00
|
|
|
*/
|
|
|
|
#define NVME_RDMA_DEFAULT_TX_SGE 2
|
|
|
|
#define NVME_RDMA_DEFAULT_RX_SGE 1
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
/* Mapping from virtual address to ibv_mr pointer for a protection domain */
|
|
|
|
struct spdk_nvme_rdma_mr_map {
|
|
|
|
struct ibv_pd *pd;
|
|
|
|
struct spdk_mem_map *map;
|
|
|
|
uint64_t ref;
|
|
|
|
LIST_ENTRY(spdk_nvme_rdma_mr_map) link;
|
|
|
|
};
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
/* NVMe RDMA transport extensions for spdk_nvme_ctrlr */
|
|
|
|
struct nvme_rdma_ctrlr {
|
|
|
|
struct spdk_nvme_ctrlr ctrlr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* NVMe RDMA qpair extensions for spdk_nvme_qpair */
|
|
|
|
struct nvme_rdma_qpair {
|
|
|
|
struct spdk_nvme_qpair qpair;
|
|
|
|
|
|
|
|
struct rdma_event_channel *cm_channel;
|
|
|
|
|
|
|
|
struct rdma_cm_id *cm_id;
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
struct ibv_cq *cq;
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_reqs;
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
uint16_t num_entries;
|
|
|
|
|
|
|
|
/* Parallel arrays of response buffers + response SGLs of size num_entries */
|
2016-11-28 22:04:51 +00:00
|
|
|
struct ibv_sge *rsp_sgls;
|
|
|
|
struct spdk_nvme_cpl *rsps;
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_recv_wr *rsp_recv_wrs;
|
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
/* Memory region describing all rsps for this qpair */
|
|
|
|
struct ibv_mr *rsp_mr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-14 22:48:24 +00:00
|
|
|
/*
|
2017-01-05 16:54:00 +00:00
|
|
|
* Array of num_entries NVMe commands registered as RDMA message buffers.
|
2016-12-14 22:48:24 +00:00
|
|
|
* Indexed by rdma_req->id.
|
|
|
|
*/
|
|
|
|
struct spdk_nvme_cmd *cmds;
|
|
|
|
|
|
|
|
/* Memory region describing all cmds for this qpair */
|
|
|
|
struct ibv_mr *cmd_mr;
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvme_rdma_req) free_reqs;
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvme_rdma_req) outstanding_reqs;
|
2016-11-15 05:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct spdk_nvme_rdma_req {
|
|
|
|
int id;
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_send_wr send_wr;
|
|
|
|
|
2018-03-02 19:49:36 +00:00
|
|
|
struct nvme_request *req;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
struct ibv_sge send_sgl[NVME_RDMA_DEFAULT_TX_SGE];
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_ENTRY(spdk_nvme_rdma_req) link;
|
2016-11-15 05:42:59 +00:00
|
|
|
};
|
|
|
|
|
2017-11-24 07:17:22 +00:00
|
|
|
static const char *rdma_cm_event_str[] = {
|
|
|
|
"RDMA_CM_EVENT_ADDR_RESOLVED",
|
|
|
|
"RDMA_CM_EVENT_ADDR_ERROR",
|
|
|
|
"RDMA_CM_EVENT_ROUTE_RESOLVED",
|
|
|
|
"RDMA_CM_EVENT_ROUTE_ERROR",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_REQUEST",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_RESPONSE",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_ERROR",
|
|
|
|
"RDMA_CM_EVENT_UNREACHABLE",
|
|
|
|
"RDMA_CM_EVENT_REJECTED",
|
|
|
|
"RDMA_CM_EVENT_ESTABLISHED",
|
|
|
|
"RDMA_CM_EVENT_DISCONNECTED",
|
|
|
|
"RDMA_CM_EVENT_DEVICE_REMOVAL",
|
|
|
|
"RDMA_CM_EVENT_MULTICAST_JOIN",
|
|
|
|
"RDMA_CM_EVENT_MULTICAST_ERROR",
|
|
|
|
"RDMA_CM_EVENT_ADDR_CHANGE",
|
|
|
|
"RDMA_CM_EVENT_TIMEWAIT_EXIT"
|
|
|
|
};
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
static LIST_HEAD(, spdk_nvme_rdma_mr_map) g_rdma_mr_maps = LIST_HEAD_INITIALIZER(&g_rdma_mr_maps);
|
|
|
|
static pthread_mutex_t g_rdma_mr_maps_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2016-11-28 22:25:05 +00:00
|
|
|
static int nvme_rdma_qpair_destroy(struct spdk_nvme_qpair *qpair);
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static inline struct nvme_rdma_qpair *
|
|
|
|
nvme_rdma_qpair(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
assert(qpair->trtype == SPDK_NVME_TRANSPORT_RDMA);
|
2018-07-05 22:04:43 +00:00
|
|
|
return SPDK_CONTAINEROF(qpair, struct nvme_rdma_qpair, qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct nvme_rdma_ctrlr *
|
|
|
|
nvme_rdma_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
assert(ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_RDMA);
|
2018-07-05 22:04:43 +00:00
|
|
|
return SPDK_CONTAINEROF(ctrlr, struct nvme_rdma_ctrlr, ctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvme_rdma_req *
|
|
|
|
nvme_rdma_req_get(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
rdma_req = TAILQ_FIRST(&rqpair->free_reqs);
|
2016-11-28 21:28:40 +00:00
|
|
|
if (rdma_req) {
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_REMOVE(&rqpair->free_reqs, rdma_req, link);
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rqpair->outstanding_reqs, rdma_req, link);
|
2016-11-28 21:28:40 +00:00
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
return rdma_req;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-11-28 21:13:21 +00:00
|
|
|
nvme_rdma_req_put(struct nvme_rdma_qpair *rqpair, struct spdk_nvme_rdma_req *rdma_req)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_REMOVE(&rqpair->outstanding_reqs, rdma_req, link);
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_INSERT_HEAD(&rqpair->free_reqs, rdma_req, link);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_req_complete(struct nvme_request *req,
|
|
|
|
struct spdk_nvme_cpl *rsp)
|
|
|
|
{
|
2018-05-17 17:16:42 +00:00
|
|
|
nvme_complete_request(req, rsp);
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_free_request(req);
|
|
|
|
}
|
|
|
|
|
2017-11-24 07:17:22 +00:00
|
|
|
static const char *
|
|
|
|
nvme_rdma_cm_event_str_get(uint32_t event)
|
|
|
|
{
|
|
|
|
if (event < SPDK_COUNTOF(rdma_cm_event_str)) {
|
|
|
|
return rdma_cm_event_str[event];
|
|
|
|
} else {
|
|
|
|
return "Undefined";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
static struct rdma_cm_event *
|
2016-12-15 21:09:03 +00:00
|
|
|
nvme_rdma_get_event(struct rdma_event_channel *channel,
|
|
|
|
enum rdma_cm_event_type evt)
|
|
|
|
{
|
|
|
|
struct rdma_cm_event *event;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = rdma_get_cm_event(channel, &event);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to get event from CM event channel. Error %d (%s)\n",
|
2017-11-07 12:56:52 +00:00
|
|
|
errno, spdk_strerror(errno));
|
2016-12-15 22:22:58 +00:00
|
|
|
return NULL;
|
2016-12-15 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event->event != evt) {
|
2018-04-05 18:14:27 +00:00
|
|
|
SPDK_ERRLOG("Expected %s but received %s (%d) from CM event channel (status = %d)\n",
|
|
|
|
nvme_rdma_cm_event_str_get(evt),
|
|
|
|
nvme_rdma_cm_event_str_get(event->event), event->event, event->status);
|
2017-01-25 04:34:53 +00:00
|
|
|
rdma_ack_cm_event(event);
|
2016-12-15 22:22:58 +00:00
|
|
|
return NULL;
|
2016-12-15 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
return event;
|
2016-12-15 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_init(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct ibv_qp_init_attr attr;
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
rqpair->cq = ibv_create_cq(rqpair->cm_id->verbs, rqpair->num_entries * 2, rqpair, NULL, 0);
|
|
|
|
if (!rqpair->cq) {
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_ERRLOG("Unable to create completion queue: errno %d: %s\n", errno, spdk_strerror(errno));
|
2017-03-08 17:30:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
memset(&attr, 0, sizeof(struct ibv_qp_init_attr));
|
|
|
|
attr.qp_type = IBV_QPT_RC;
|
2017-03-08 17:30:49 +00:00
|
|
|
attr.send_cq = rqpair->cq;
|
|
|
|
attr.recv_cq = rqpair->cq;
|
2017-01-05 16:54:00 +00:00
|
|
|
attr.cap.max_send_wr = rqpair->num_entries; /* SEND operations */
|
|
|
|
attr.cap.max_recv_wr = rqpair->num_entries; /* RECV operations */
|
2016-11-15 05:42:59 +00:00
|
|
|
attr.cap.max_send_sge = NVME_RDMA_DEFAULT_TX_SGE;
|
|
|
|
attr.cap.max_recv_sge = NVME_RDMA_DEFAULT_RX_SGE;
|
|
|
|
|
|
|
|
rc = rdma_create_qp(rqpair->cm_id, NULL, &attr);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("rdma_create_qp failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->cm_id->context = &rqpair->qpair;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:39:08 +00:00
|
|
|
#define nvme_rdma_trace_ibv_sge(sg_list) \
|
|
|
|
if (sg_list) { \
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "local addr %p length 0x%x lkey 0x%x\n", \
|
2016-11-28 22:39:08 +00:00
|
|
|
(void *)(sg_list)->addr, (sg_list)->length, (sg_list)->lkey); \
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-11-28 22:04:51 +00:00
|
|
|
nvme_rdma_post_recv(struct nvme_rdma_qpair *rqpair, uint16_t rsp_idx)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_recv_wr *wr, *bad_wr = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
wr = &rqpair->rsp_recv_wrs[rsp_idx];
|
|
|
|
nvme_rdma_trace_ibv_sge(wr->sg_list);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
rc = ibv_post_recv(rqpair->cm_id->qp, wr, &bad_wr);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failure posting rdma recv, rc = 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_free_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2016-11-28 22:04:51 +00:00
|
|
|
if (rqpair->rsp_mr && rdma_dereg_mr(rqpair->rsp_mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register rsp_mr\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2016-11-28 22:04:51 +00:00
|
|
|
rqpair->rsp_mr = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
free(rqpair->rsps);
|
|
|
|
rqpair->rsps = NULL;
|
|
|
|
free(rqpair->rsp_sgls);
|
|
|
|
rqpair->rsp_sgls = NULL;
|
2016-12-08 06:54:53 +00:00
|
|
|
free(rqpair->rsp_recv_wrs);
|
|
|
|
rqpair->rsp_recv_wrs = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_alloc_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2016-11-28 22:04:51 +00:00
|
|
|
uint16_t i;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
rqpair->rsp_mr = NULL;
|
|
|
|
rqpair->rsps = NULL;
|
2016-12-08 06:54:53 +00:00
|
|
|
rqpair->rsp_recv_wrs = NULL;
|
2016-11-28 22:04:51 +00:00
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->rsp_sgls = calloc(rqpair->num_entries, sizeof(*rqpair->rsp_sgls));
|
2016-11-28 22:04:51 +00:00
|
|
|
if (!rqpair->rsp_sgls) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rsp_sgls\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->rsp_recv_wrs = calloc(rqpair->num_entries,
|
2016-12-08 06:54:53 +00:00
|
|
|
sizeof(*rqpair->rsp_recv_wrs));
|
|
|
|
if (!rqpair->rsp_recv_wrs) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rsp_recv_wrs\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->rsps = calloc(rqpair->num_entries, sizeof(*rqpair->rsps));
|
2016-11-28 22:04:51 +00:00
|
|
|
if (!rqpair->rsps) {
|
2016-11-15 05:42:59 +00:00
|
|
|
SPDK_ERRLOG("can not allocate rdma rsps\n");
|
2016-11-28 22:04:51 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->rsp_mr = rdma_reg_msgs(rqpair->cm_id, rqpair->rsps,
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->num_entries * sizeof(*rqpair->rsps));
|
2016-11-28 22:04:51 +00:00
|
|
|
if (rqpair->rsp_mr == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to register rsp_mr\n");
|
|
|
|
goto fail;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
for (i = 0; i < rqpair->num_entries; i++) {
|
2016-11-28 22:04:51 +00:00
|
|
|
struct ibv_sge *rsp_sgl = &rqpair->rsp_sgls[i];
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
rsp_sgl->addr = (uint64_t)&rqpair->rsps[i];
|
|
|
|
rsp_sgl->length = sizeof(rqpair->rsps[i]);
|
|
|
|
rsp_sgl->lkey = rqpair->rsp_mr->lkey;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-02-22 03:00:17 +00:00
|
|
|
rqpair->rsp_recv_wrs[i].wr_id = i;
|
|
|
|
rqpair->rsp_recv_wrs[i].next = NULL;
|
|
|
|
rqpair->rsp_recv_wrs[i].sg_list = rsp_sgl;
|
|
|
|
rqpair->rsp_recv_wrs[i].num_sge = 1;
|
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
if (nvme_rdma_post_recv(rqpair, i)) {
|
2016-11-15 05:42:59 +00:00
|
|
|
SPDK_ERRLOG("Unable to post connection rx desc\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-11-28 22:04:51 +00:00
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
fail:
|
|
|
|
nvme_rdma_free_rsps(rqpair);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_free_reqs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
if (!rqpair->rdma_reqs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-14 22:48:24 +00:00
|
|
|
if (rqpair->cmd_mr && rdma_dereg_mr(rqpair->cmd_mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register cmd_mr\n");
|
|
|
|
}
|
|
|
|
rqpair->cmd_mr = NULL;
|
|
|
|
|
|
|
|
free(rqpair->cmds);
|
|
|
|
rqpair->cmds = NULL;
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
free(rqpair->rdma_reqs);
|
2016-12-14 22:48:24 +00:00
|
|
|
rqpair->rdma_reqs = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_alloc_reqs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->rdma_reqs = calloc(rqpair->num_entries, sizeof(struct spdk_nvme_rdma_req));
|
2016-12-15 01:06:23 +00:00
|
|
|
if (rqpair->rdma_reqs == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rdma_reqs\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->cmds = calloc(rqpair->num_entries, sizeof(*rqpair->cmds));
|
2016-12-14 22:48:24 +00:00
|
|
|
if (!rqpair->cmds) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate RDMA cmds\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->cmd_mr = rdma_reg_msgs(rqpair->cm_id, rqpair->cmds,
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->num_entries * sizeof(*rqpair->cmds));
|
2016-12-14 22:48:24 +00:00
|
|
|
if (!rqpair->cmd_mr) {
|
|
|
|
SPDK_ERRLOG("Unable to register cmd_mr\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_INIT(&rqpair->free_reqs);
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_INIT(&rqpair->outstanding_reqs);
|
2017-01-05 16:54:00 +00:00
|
|
|
for (i = 0; i < rqpair->num_entries; i++) {
|
2016-12-15 21:21:57 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
|
|
|
struct spdk_nvme_cmd *cmd;
|
|
|
|
|
|
|
|
rdma_req = &rqpair->rdma_reqs[i];
|
|
|
|
cmd = &rqpair->cmds[i];
|
|
|
|
|
|
|
|
rdma_req->id = i;
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_sgl[0].addr = (uint64_t)cmd;
|
|
|
|
rdma_req->send_sgl[0].length = sizeof(*cmd);
|
|
|
|
rdma_req->send_sgl[0].lkey = rqpair->cmd_mr->lkey;
|
2016-12-15 21:21:57 +00:00
|
|
|
|
2017-02-22 10:35:52 +00:00
|
|
|
rdma_req->send_wr.wr_id = (uint64_t)rdma_req;
|
|
|
|
rdma_req->send_wr.next = NULL;
|
|
|
|
rdma_req->send_wr.opcode = IBV_WR_SEND;
|
|
|
|
rdma_req->send_wr.send_flags = IBV_SEND_SIGNALED;
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_wr.sg_list = &rdma_req->send_sgl[0];
|
|
|
|
rdma_req->send_wr.num_sge = 1; /* Need to increment if inline */
|
2017-02-22 10:35:52 +00:00
|
|
|
rdma_req->send_wr.imm_data = 0;
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rqpair->free_reqs, rdma_req, link);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
nvme_rdma_free_reqs(rqpair);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-20 19:10:08 +00:00
|
|
|
nvme_rdma_recv(struct nvme_rdma_qpair *rqpair, uint64_t rsp_idx)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2016-12-08 18:35:53 +00:00
|
|
|
struct spdk_nvme_qpair *qpair = &rqpair->qpair;
|
2016-11-15 05:42:59 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
2016-11-28 22:04:51 +00:00
|
|
|
struct spdk_nvme_cpl *rsp;
|
2016-11-15 05:42:59 +00:00
|
|
|
struct nvme_request *req;
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
assert(rsp_idx < rqpair->num_entries);
|
2016-11-28 22:04:51 +00:00
|
|
|
rsp = &rqpair->rsps[rsp_idx];
|
|
|
|
rdma_req = &rqpair->rdma_reqs[rsp->cid];
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
req = rdma_req->req;
|
2016-11-28 22:04:51 +00:00
|
|
|
nvme_rdma_req_complete(req, rsp);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-01 06:14:07 +00:00
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2016-11-28 22:04:51 +00:00
|
|
|
if (nvme_rdma_post_recv(rqpair, rsp_idx)) {
|
2016-11-15 05:42:59 +00:00
|
|
|
SPDK_ERRLOG("Unable to re-post rx descriptor\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-08 18:35:53 +00:00
|
|
|
if (!STAILQ_EMPTY(&qpair->queued_req) && !qpair->ctrlr->is_resetting) {
|
|
|
|
req = STAILQ_FIRST(&qpair->queued_req);
|
|
|
|
STAILQ_REMOVE_HEAD(&qpair->queued_req, stailq);
|
|
|
|
nvme_qpair_submit_request(qpair, req);
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-15 21:10:12 +00:00
|
|
|
nvme_rdma_resolve_addr(struct nvme_rdma_qpair *rqpair,
|
2017-08-25 22:05:01 +00:00
|
|
|
struct sockaddr *src_addr,
|
|
|
|
struct sockaddr *dst_addr,
|
2016-12-15 21:10:12 +00:00
|
|
|
struct rdma_event_channel *cm_channel)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2016-12-15 22:22:58 +00:00
|
|
|
struct rdma_cm_event *event;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
ret = rdma_resolve_addr(rqpair->cm_id, src_addr, dst_addr,
|
2016-11-15 05:42:59 +00:00
|
|
|
NVME_RDMA_TIME_OUT_IN_MS);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("rdma_resolve_addr, %d\n", errno);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
event = nvme_rdma_get_event(cm_channel, RDMA_CM_EVENT_ADDR_RESOLVED);
|
|
|
|
if (event == NULL) {
|
2016-12-15 21:09:03 +00:00
|
|
|
SPDK_ERRLOG("RDMA address resolution error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-15 22:22:58 +00:00
|
|
|
rdma_ack_cm_event(event);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
ret = rdma_resolve_route(rqpair->cm_id, NVME_RDMA_TIME_OUT_IN_MS);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("rdma_resolve_route\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2016-12-15 21:09:03 +00:00
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
event = nvme_rdma_get_event(cm_channel, RDMA_CM_EVENT_ROUTE_RESOLVED);
|
|
|
|
if (event == NULL) {
|
2016-12-15 21:09:03 +00:00
|
|
|
SPDK_ERRLOG("RDMA route resolution error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-15 22:22:58 +00:00
|
|
|
rdma_ack_cm_event(event);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_connect(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2016-12-15 22:22:58 +00:00
|
|
|
struct rdma_conn_param param = {};
|
2018-03-02 19:49:36 +00:00
|
|
|
struct spdk_nvmf_rdma_request_private_data request_data = {};
|
2016-12-15 22:22:58 +00:00
|
|
|
struct spdk_nvmf_rdma_accept_private_data *accept_data;
|
2018-03-02 19:49:36 +00:00
|
|
|
struct ibv_device_attr attr;
|
|
|
|
int ret;
|
|
|
|
struct rdma_cm_event *event;
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-08 13:45:25 +00:00
|
|
|
ret = ibv_query_device(rqpair->cm_id->verbs, &attr);
|
|
|
|
if (ret != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to query RDMA device attributes.\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-02 17:07:12 +00:00
|
|
|
param.responder_resources = spdk_min(rqpair->num_entries, attr.max_qp_rd_atom);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-01-13 21:44:25 +00:00
|
|
|
ctrlr = rqpair->qpair.ctrlr;
|
|
|
|
if (!ctrlr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
request_data.qid = rqpair->qpair.id;
|
2017-01-05 16:54:00 +00:00
|
|
|
request_data.hrqsize = rqpair->num_entries;
|
|
|
|
request_data.hsqsize = rqpair->num_entries - 1;
|
2018-06-22 21:20:31 +00:00
|
|
|
request_data.cntlid = ctrlr->cntlid;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
param.private_data = &request_data;
|
|
|
|
param.private_data_len = sizeof(request_data);
|
2017-10-11 05:03:41 +00:00
|
|
|
param.retry_count = 7;
|
2016-12-15 22:22:58 +00:00
|
|
|
|
|
|
|
ret = rdma_connect(rqpair->cm_id, ¶m);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (ret) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("nvme rdma connect error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-12-15 20:57:50 +00:00
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
event = nvme_rdma_get_event(rqpair->cm_channel, RDMA_CM_EVENT_ESTABLISHED);
|
|
|
|
if (event == NULL) {
|
2016-12-15 21:09:03 +00:00
|
|
|
SPDK_ERRLOG("RDMA connect error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
accept_data = (struct spdk_nvmf_rdma_accept_private_data *)event->param.conn.private_data;
|
|
|
|
if (accept_data == NULL) {
|
2017-01-25 04:34:53 +00:00
|
|
|
rdma_ack_cm_event(event);
|
2016-12-15 22:22:58 +00:00
|
|
|
SPDK_ERRLOG("NVMe-oF target did not return accept data\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "Requested queue depth %d. Actually got queue depth %d.\n",
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->num_entries, accept_data->crqsize);
|
2016-12-15 22:22:58 +00:00
|
|
|
|
2017-02-02 17:07:12 +00:00
|
|
|
rqpair->num_entries = spdk_min(rqpair->num_entries, accept_data->crqsize);
|
2016-12-15 22:22:58 +00:00
|
|
|
|
|
|
|
rdma_ack_cm_event(event);
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-12 22:30:16 +00:00
|
|
|
nvme_rdma_parse_addr(struct sockaddr_storage *sa, int family, const char *addr, const char *service)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct addrinfo *res;
|
2016-12-12 22:30:16 +00:00
|
|
|
struct addrinfo hints;
|
2016-11-15 05:42:59 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-12-12 22:30:16 +00:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = family;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
|
|
|
|
ret = getaddrinfo(addr, service, &hints, &res);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (ret) {
|
2017-07-14 17:16:03 +00:00
|
|
|
SPDK_ERRLOG("getaddrinfo failed: %s (%d)\n", gai_strerror(ret), ret);
|
2016-11-15 05:42:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:14:47 +00:00
|
|
|
if (res->ai_addrlen > sizeof(*sa)) {
|
|
|
|
SPDK_ERRLOG("getaddrinfo() ai_addrlen %zu too large\n", (size_t)res->ai_addrlen);
|
|
|
|
ret = EINVAL;
|
|
|
|
} else {
|
|
|
|
memcpy(sa, res->ai_addr, res->ai_addrlen);
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
freeaddrinfo(res);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:54:37 +00:00
|
|
|
static int
|
2017-03-08 18:40:15 +00:00
|
|
|
nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map,
|
|
|
|
enum spdk_mem_map_notify_action action,
|
|
|
|
void *vaddr, size_t size)
|
|
|
|
{
|
|
|
|
struct ibv_pd *pd = cb_ctx;
|
|
|
|
struct ibv_mr *mr;
|
2017-08-08 10:54:37 +00:00
|
|
|
int rc;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_REGISTER:
|
|
|
|
mr = ibv_reg_mr(pd, vaddr, size,
|
|
|
|
IBV_ACCESS_LOCAL_WRITE |
|
|
|
|
IBV_ACCESS_REMOTE_READ |
|
|
|
|
IBV_ACCESS_REMOTE_WRITE);
|
|
|
|
if (mr == NULL) {
|
|
|
|
SPDK_ERRLOG("ibv_reg_mr() failed\n");
|
2017-08-08 10:54:37 +00:00
|
|
|
return -EFAULT;
|
2017-03-08 18:40:15 +00:00
|
|
|
} else {
|
2017-08-08 10:54:37 +00:00
|
|
|
rc = spdk_mem_map_set_translation(map, (uint64_t)vaddr, size, (uint64_t)mr);
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
|
2018-09-06 20:07:42 +00:00
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, NULL);
|
2017-08-08 10:54:37 +00:00
|
|
|
rc = spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size);
|
2017-03-08 18:40:15 +00:00
|
|
|
if (mr) {
|
|
|
|
ibv_dereg_mr(mr);
|
|
|
|
}
|
|
|
|
break;
|
2017-08-08 10:54:37 +00:00
|
|
|
default:
|
|
|
|
SPDK_UNREACHABLE();
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
2017-08-08 10:54:37 +00:00
|
|
|
|
|
|
|
return rc;
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
struct ibv_pd *pd = rqpair->cm_id->qp->pd;
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
2018-09-11 22:03:31 +00:00
|
|
|
const struct spdk_mem_map_ops nvme_rdma_map_ops = {
|
|
|
|
.notify_cb = nvme_rdma_mr_map_notify
|
|
|
|
};
|
2018-03-28 21:12:38 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&g_rdma_mr_maps_mutex);
|
|
|
|
|
|
|
|
/* Look up existing mem map registration for this pd */
|
|
|
|
LIST_FOREACH(mr_map, &g_rdma_mr_maps, link) {
|
|
|
|
if (mr_map->pd == pd) {
|
|
|
|
mr_map->ref++;
|
|
|
|
rqpair->mr_map = mr_map;
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
mr_map = calloc(1, sizeof(*mr_map));
|
|
|
|
if (mr_map == NULL) {
|
|
|
|
SPDK_ERRLOG("calloc() failed\n");
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
mr_map->ref = 1;
|
|
|
|
mr_map->pd = pd;
|
2018-09-11 22:03:31 +00:00
|
|
|
mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, &nvme_rdma_map_ops, pd);
|
2018-08-16 14:29:50 +00:00
|
|
|
if (mr_map->map == NULL) {
|
2017-03-08 18:40:15 +00:00
|
|
|
SPDK_ERRLOG("spdk_mem_map_alloc() failed\n");
|
2018-03-28 21:12:38 +00:00
|
|
|
free(mr_map);
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->mr_map = mr_map;
|
2018-03-28 21:12:38 +00:00
|
|
|
LIST_INSERT_HEAD(&g_rdma_mr_maps, mr_map, link);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_unregister_mem(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
|
|
|
|
|
|
|
mr_map = rqpair->mr_map;
|
|
|
|
rqpair->mr_map = NULL;
|
|
|
|
|
|
|
|
if (mr_map == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&g_rdma_mr_maps_mutex);
|
|
|
|
|
|
|
|
assert(mr_map->ref > 0);
|
|
|
|
mr_map->ref--;
|
|
|
|
if (mr_map->ref == 0) {
|
|
|
|
LIST_REMOVE(mr_map, link);
|
|
|
|
spdk_mem_map_free(&mr_map->map);
|
|
|
|
free(mr_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_connect(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2017-08-25 22:05:01 +00:00
|
|
|
struct sockaddr_storage dst_addr;
|
|
|
|
struct sockaddr_storage src_addr;
|
|
|
|
bool src_addr_specified;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
2016-11-21 22:11:59 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2016-12-12 22:30:16 +00:00
|
|
|
int family;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-15 20:26:09 +00:00
|
|
|
rqpair->cm_channel = rdma_create_event_channel();
|
|
|
|
if (rqpair->cm_channel == NULL) {
|
|
|
|
SPDK_ERRLOG("rdma_create_event_channel() failed\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 22:11:59 +00:00
|
|
|
ctrlr = rqpair->qpair.ctrlr;
|
2016-12-12 22:30:16 +00:00
|
|
|
|
|
|
|
switch (ctrlr->trid.adrfam) {
|
|
|
|
case SPDK_NVMF_ADRFAM_IPV4:
|
|
|
|
family = AF_INET;
|
|
|
|
break;
|
|
|
|
case SPDK_NVMF_ADRFAM_IPV6:
|
|
|
|
family = AF_INET6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unhandled ADRFAM %d\n", ctrlr->trid.adrfam);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "adrfam %d ai_family %d\n", ctrlr->trid.adrfam, family);
|
2016-12-12 22:30:16 +00:00
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
memset(&dst_addr, 0, sizeof(dst_addr));
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "trsvcid is %s\n", ctrlr->trid.trsvcid);
|
2017-08-25 22:05:01 +00:00
|
|
|
rc = nvme_rdma_parse_addr(&dst_addr, family, ctrlr->trid.traddr, ctrlr->trid.trsvcid);
|
2016-11-23 18:14:47 +00:00
|
|
|
if (rc != 0) {
|
2017-08-25 22:05:01 +00:00
|
|
|
SPDK_ERRLOG("dst_addr nvme_rdma_parse_addr() failed\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
if (ctrlr->opts.src_addr[0] || ctrlr->opts.src_svcid[0]) {
|
|
|
|
memset(&src_addr, 0, sizeof(src_addr));
|
|
|
|
rc = nvme_rdma_parse_addr(&src_addr, family, ctrlr->opts.src_addr, ctrlr->opts.src_svcid);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("src_addr nvme_rdma_parse_addr() failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
src_addr_specified = true;
|
|
|
|
} else {
|
|
|
|
src_addr_specified = false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
rc = rdma_create_id(rqpair->cm_channel, &rqpair->cm_id, rqpair, RDMA_PS_TCP);
|
|
|
|
if (rc < 0) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("rdma_create_id() failed\n");
|
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
rc = nvme_rdma_resolve_addr(rqpair,
|
|
|
|
src_addr_specified ? (struct sockaddr *)&src_addr : NULL,
|
|
|
|
(struct sockaddr *)&dst_addr, rqpair->cm_channel);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
2016-12-15 21:10:12 +00:00
|
|
|
SPDK_ERRLOG("nvme_rdma_resolve_addr() failed\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = nvme_rdma_qpair_init(rqpair);
|
|
|
|
if (rc < 0) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("nvme_rdma_qpair_init() failed\n");
|
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2016-12-15 21:23:41 +00:00
|
|
|
|
|
|
|
rc = nvme_rdma_connect(rqpair);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to connect the rqpair\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
rc = nvme_rdma_alloc_reqs(rqpair);
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "rc =%d\n", rc);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate rqpair RDMA requests\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "RDMA requests allocated\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
rc = nvme_rdma_alloc_rsps(rqpair);
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "rc =%d\n", rc);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate rqpair RDMA responses\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "RDMA responses allocated\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
rc = nvme_rdma_register_mem(rqpair);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to register memory for RDMA\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-22 21:19:53 +00:00
|
|
|
rc = nvme_fabric_qpair_connect(&rqpair->qpair, rqpair->num_entries);
|
2016-12-15 21:33:18 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to send an NVMe-oF Fabric CONNECT command\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
/*
|
|
|
|
* Build SGL describing empty payload.
|
2016-12-01 06:14:07 +00:00
|
|
|
*/
|
2016-12-15 01:29:22 +00:00
|
|
|
static int
|
2017-03-08 18:40:15 +00:00
|
|
|
nvme_rdma_build_null_request(struct nvme_request *req)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvme_sgl_descriptor *nvme_sgl;
|
|
|
|
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
nvme_sgl = &req->cmd.dptr.sgl1;
|
|
|
|
nvme_sgl->keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
nvme_sgl->keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
|
|
|
nvme_sgl->keyed.length = 0;
|
|
|
|
nvme_sgl->keyed.key = 0;
|
|
|
|
nvme_sgl->address = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
/*
|
|
|
|
* Build inline SGL describing contiguous payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nvme_rdma_build_contig_inline_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
|
|
|
struct ibv_sge *sge_inline = &rdma_req->send_sgl[1];
|
|
|
|
struct nvme_request *req = rdma_req->req;
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
void *payload;
|
|
|
|
|
|
|
|
|
|
|
|
payload = req->payload.contig_or_cb_arg + req->payload_offset;
|
|
|
|
assert(req->payload_size != 0);
|
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
|
|
|
|
|
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map,
|
2018-09-06 20:07:42 +00:00
|
|
|
(uint64_t)payload, NULL);
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
if (mr == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sge_inline->addr = (uint64_t)payload;
|
|
|
|
sge_inline->length = (uint32_t)req->payload_size;
|
|
|
|
sge_inline->lkey = mr->lkey;
|
|
|
|
|
|
|
|
rdma_req->send_wr.num_sge = 2;
|
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.length = (uint32_t)req->payload_size;
|
2018-09-11 23:14:07 +00:00
|
|
|
/* Inline only supported for icdoff == 0 currently. This function will
|
|
|
|
* not get called for controllers with other values. */
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)0;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
/*
|
|
|
|
* Build SGL describing contiguous payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
2018-08-11 05:50:25 +00:00
|
|
|
nvme_rdma_build_contig_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
2017-03-08 18:40:15 +00:00
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2018-06-01 00:52:54 +00:00
|
|
|
void *payload = req->payload.contig_or_cb_arg + req->payload_offset;
|
2017-03-08 18:40:15 +00:00
|
|
|
struct ibv_mr *mr;
|
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
2018-06-01 00:51:16 +00:00
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-05-31 21:44:49 +00:00
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)payload,
|
2018-09-06 20:07:42 +00:00
|
|
|
NULL);
|
2017-03-08 18:40:15 +00:00
|
|
|
if (mr == NULL) {
|
2016-12-01 06:14:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_wr.num_sge = 1;
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2017-03-08 18:40:15 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
|
|
|
req->cmd.dptr.sgl1.keyed.length = req->payload_size;
|
|
|
|
req->cmd.dptr.sgl1.keyed.key = mr->rkey;
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)payload;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build SGL describing scattered payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
2018-08-11 05:50:25 +00:00
|
|
|
nvme_rdma_build_sgl_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
2017-03-08 18:40:15 +00:00
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2017-03-08 18:40:15 +00:00
|
|
|
struct ibv_mr *mr;
|
2018-08-11 05:50:25 +00:00
|
|
|
void *virt_addr;
|
2017-03-08 18:40:15 +00:00
|
|
|
uint32_t length;
|
2018-08-11 05:50:25 +00:00
|
|
|
int rc;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
2018-06-01 00:51:16 +00:00
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL);
|
2018-06-01 00:52:54 +00:00
|
|
|
assert(req->payload.reset_sgl_fn != NULL);
|
|
|
|
assert(req->payload.next_sge_fn != NULL);
|
|
|
|
req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
/* TODO: for now, we only support a single SGL entry */
|
2018-06-01 00:52:54 +00:00
|
|
|
rc = req->payload.next_sge_fn(req->payload.contig_or_cb_arg, &virt_addr, &length);
|
2017-03-08 18:40:15 +00:00
|
|
|
if (rc) {
|
2016-12-15 01:29:22 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 18:13:18 +00:00
|
|
|
if (length < req->payload_size) {
|
2017-03-08 18:40:15 +00:00
|
|
|
SPDK_ERRLOG("multi-element SGL currently not supported for RDMA\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-01 06:14:07 +00:00
|
|
|
|
2018-05-31 21:44:49 +00:00
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr,
|
2018-09-06 20:07:42 +00:00
|
|
|
NULL);
|
2017-03-08 18:40:15 +00:00
|
|
|
if (mr == NULL) {
|
|
|
|
return -1;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_wr.num_sge = 1;
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2017-03-08 18:40:15 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
2017-08-02 18:13:18 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.length = req->payload_size;
|
2017-03-08 18:40:15 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.key = mr->rkey;
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)virt_addr;
|
|
|
|
|
2016-12-01 06:14:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
/*
|
|
|
|
* Build inline SGL describing sgl payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nvme_rdma_build_sgl_inline_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
|
|
|
struct ibv_sge *sge_inline = &rdma_req->send_sgl[1];
|
|
|
|
struct nvme_request *req = rdma_req->req;
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
uint32_t length;
|
|
|
|
void *virt_addr;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL);
|
|
|
|
assert(req->payload.reset_sgl_fn != NULL);
|
|
|
|
assert(req->payload.next_sge_fn != NULL);
|
|
|
|
req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset);
|
|
|
|
|
|
|
|
/* TODO: for now, we only support a single SGL entry */
|
|
|
|
rc = req->payload.next_sge_fn(req->payload.contig_or_cb_arg, &virt_addr, &length);
|
|
|
|
if (rc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length < req->payload_size) {
|
|
|
|
SPDK_ERRLOG("multi-element SGL currently not supported for RDMA\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr,
|
2018-09-06 20:07:42 +00:00
|
|
|
NULL);
|
2018-08-11 05:50:25 +00:00
|
|
|
if (mr == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sge_inline->addr = (uint64_t)virt_addr;
|
|
|
|
sge_inline->length = (uint32_t)req->payload_size;
|
|
|
|
sge_inline->lkey = mr->lkey;
|
|
|
|
|
|
|
|
rdma_req->send_wr.num_sge = 2;
|
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.length = (uint32_t)req->payload_size;
|
2018-09-11 23:14:07 +00:00
|
|
|
/* Inline only supported for icdoff == 0 currently. This function will
|
|
|
|
* not get called for controllers with other values. */
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)0;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
nvme_rdma_icdsz_bytes(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
return (ctrlr->cdata.nvmf_specific.ioccsz * 16 - sizeof(struct spdk_nvme_cmd));
|
|
|
|
}
|
|
|
|
|
2016-12-01 06:14:07 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr = rqpair->qpair.ctrlr;
|
2017-03-08 18:40:15 +00:00
|
|
|
int rc;
|
2016-12-01 06:14:07 +00:00
|
|
|
|
|
|
|
rdma_req->req = req;
|
|
|
|
req->cmd.cid = rdma_req->id;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
if (req->payload_size == 0) {
|
|
|
|
rc = nvme_rdma_build_null_request(req);
|
2018-06-01 00:51:16 +00:00
|
|
|
} else if (nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG) {
|
2018-08-11 05:50:25 +00:00
|
|
|
/*
|
|
|
|
* Check if icdoff is non zero, to avoid interop conflicts with
|
2018-09-11 23:14:07 +00:00
|
|
|
* targets with non-zero icdoff. Both SPDK and the Linux kernel
|
|
|
|
* targets use icdoff = 0. For targets with non-zero icdoff, we
|
|
|
|
* will currently just not use inline data for now.
|
2018-08-11 05:50:25 +00:00
|
|
|
*/
|
|
|
|
if (req->cmd.opc == SPDK_NVME_OPC_WRITE &&
|
|
|
|
req->payload_size <= nvme_rdma_icdsz_bytes(ctrlr) &&
|
|
|
|
(ctrlr->cdata.nvmf_specific.icdoff == 0)) {
|
|
|
|
rc = nvme_rdma_build_contig_inline_request(rqpair, rdma_req);
|
|
|
|
} else {
|
|
|
|
rc = nvme_rdma_build_contig_request(rqpair, rdma_req);
|
|
|
|
}
|
2018-06-01 00:51:16 +00:00
|
|
|
} else if (nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL) {
|
2018-08-11 05:50:25 +00:00
|
|
|
if (req->cmd.opc == SPDK_NVME_OPC_WRITE &&
|
|
|
|
req->payload_size <= nvme_rdma_icdsz_bytes(ctrlr) &&
|
|
|
|
ctrlr->cdata.nvmf_specific.icdoff == 0) {
|
|
|
|
rc = nvme_rdma_build_sgl_inline_request(rqpair, rdma_req);
|
|
|
|
} else {
|
|
|
|
rc = nvme_rdma_build_sgl_request(rqpair, rdma_req);
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
} else {
|
2017-03-08 18:40:15 +00:00
|
|
|
rc = -1;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 22:48:24 +00:00
|
|
|
memcpy(&rqpair->cmds[rdma_req->id], &req->cmd, sizeof(req->cmd));
|
2016-12-15 01:29:22 +00:00
|
|
|
return 0;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvme_qpair *
|
2016-12-15 23:39:54 +00:00
|
|
|
nvme_rdma_ctrlr_create_qpair(struct spdk_nvme_ctrlr *ctrlr,
|
|
|
|
uint16_t qid, uint32_t qsize,
|
2017-04-03 22:52:53 +00:00
|
|
|
enum spdk_nvme_qprio qprio,
|
|
|
|
uint32_t num_requests)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rqpair = calloc(1, sizeof(struct nvme_rdma_qpair));
|
|
|
|
if (!rqpair) {
|
|
|
|
SPDK_ERRLOG("failed to get create rqpair\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->num_entries = qsize;
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
qpair = &rqpair->qpair;
|
|
|
|
|
2017-04-03 22:52:53 +00:00
|
|
|
rc = nvme_qpair_init(qpair, qid, ctrlr, qprio, num_requests);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-15 21:36:19 +00:00
|
|
|
rc = nvme_rdma_qpair_connect(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
2016-11-28 22:25:05 +00:00
|
|
|
nvme_rdma_qpair_destroy(qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qpair;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:25:05 +00:00
|
|
|
static int
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_qpair_destroy(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
|
2016-11-23 17:43:58 +00:00
|
|
|
if (!qpair) {
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2018-05-28 04:34:28 +00:00
|
|
|
nvme_qpair_deinit(qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-11-23 17:43:58 +00:00
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
nvme_rdma_unregister_mem(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_free_reqs(rqpair);
|
|
|
|
nvme_rdma_free_rsps(rqpair);
|
|
|
|
|
|
|
|
if (rqpair->cm_id) {
|
|
|
|
if (rqpair->cm_id->qp) {
|
|
|
|
rdma_destroy_qp(rqpair->cm_id);
|
|
|
|
}
|
|
|
|
rdma_destroy_id(rqpair->cm_id);
|
|
|
|
}
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
if (rqpair->cq) {
|
|
|
|
ibv_destroy_cq(rqpair->cq);
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rqpair->cm_channel) {
|
|
|
|
rdma_destroy_event_channel(rqpair->cm_channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(rqpair);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct spdk_nvme_qpair *
|
|
|
|
nvme_rdma_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
|
2017-07-14 23:08:05 +00:00
|
|
|
const struct spdk_nvme_io_qpair_opts *opts)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2017-07-14 23:08:05 +00:00
|
|
|
return nvme_rdma_ctrlr_create_qpair(ctrlr, qid, opts->io_queue_size, opts->qprio,
|
|
|
|
opts->io_queue_requests);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
/* do nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function must only be called while holding g_spdk_nvme_driver->lock */
|
|
|
|
int
|
2016-12-09 22:09:28 +00:00
|
|
|
nvme_rdma_ctrlr_scan(const struct spdk_nvme_transport_id *discovery_trid,
|
2016-12-06 17:36:34 +00:00
|
|
|
void *cb_ctx,
|
|
|
|
spdk_nvme_probe_cb probe_cb,
|
2017-07-21 03:01:03 +00:00
|
|
|
spdk_nvme_remove_cb remove_cb,
|
|
|
|
bool direct_connect)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2016-11-28 23:26:04 +00:00
|
|
|
struct spdk_nvme_ctrlr_opts discovery_opts;
|
2016-11-15 05:42:59 +00:00
|
|
|
struct spdk_nvme_ctrlr *discovery_ctrlr;
|
2016-11-23 21:04:09 +00:00
|
|
|
union spdk_nvme_cc_register cc;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
2017-06-01 07:30:46 +00:00
|
|
|
struct nvme_completion_poll_status status;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-06-25 20:42:03 +00:00
|
|
|
if (strcmp(discovery_trid->subnqn, SPDK_NVMF_DISCOVERY_NQN) != 0) {
|
|
|
|
/* It is not a discovery_ctrlr info and try to directly connect it */
|
|
|
|
rc = nvme_ctrlr_probe(discovery_trid, NULL, probe_cb, cb_ctx);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-09-29 16:29:05 +00:00
|
|
|
spdk_nvme_ctrlr_get_default_ctrlr_opts(&discovery_opts, sizeof(discovery_opts));
|
2016-12-07 15:26:25 +00:00
|
|
|
/* For discovery_ctrlr set the timeout to 0 */
|
|
|
|
discovery_opts.keep_alive_timeout_ms = 0;
|
2016-11-28 23:26:04 +00:00
|
|
|
|
2016-12-09 22:14:45 +00:00
|
|
|
discovery_ctrlr = nvme_rdma_ctrlr_construct(discovery_trid, &discovery_opts, NULL);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (discovery_ctrlr == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:04:09 +00:00
|
|
|
/* TODO: this should be using the normal NVMe controller initialization process */
|
|
|
|
cc.raw = 0;
|
|
|
|
cc.bits.en = 1;
|
2016-12-07 10:29:47 +00:00
|
|
|
cc.bits.iosqes = 6; /* SQ entry size == 64 == 2^6 */
|
|
|
|
cc.bits.iocqes = 4; /* CQ entry size == 16 == 2^4 */
|
2016-11-23 21:04:09 +00:00
|
|
|
rc = nvme_transport_ctrlr_set_reg_4(discovery_ctrlr, offsetof(struct spdk_nvme_registers, cc.raw),
|
|
|
|
cc.raw);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to set cc\n");
|
|
|
|
nvme_ctrlr_destruct(discovery_ctrlr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-06-01 07:30:46 +00:00
|
|
|
/* get the cdata info */
|
2018-03-21 23:18:24 +00:00
|
|
|
rc = nvme_ctrlr_cmd_identify(discovery_ctrlr, SPDK_NVME_IDENTIFY_CTRLR, 0, 0,
|
|
|
|
&discovery_ctrlr->cdata, sizeof(discovery_ctrlr->cdata),
|
|
|
|
nvme_completion_poll_cb, &status);
|
2017-06-01 07:30:46 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to identify cdata\n");
|
2017-01-12 05:21:53 +00:00
|
|
|
return rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2018-05-25 20:23:09 +00:00
|
|
|
if (spdk_nvme_wait_for_completion(discovery_ctrlr->adminq, &status)) {
|
2017-06-01 07:30:46 +00:00
|
|
|
SPDK_ERRLOG("nvme_identify_controller failed!\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2017-07-21 03:01:03 +00:00
|
|
|
/* Direct attach through spdk_nvme_connect() API */
|
|
|
|
if (direct_connect == true) {
|
|
|
|
/* Set the ready state to skip the normal init process */
|
|
|
|
discovery_ctrlr->state = NVME_CTRLR_STATE_READY;
|
2017-11-22 22:26:26 +00:00
|
|
|
nvme_ctrlr_connected(discovery_ctrlr);
|
2017-07-21 03:01:03 +00:00
|
|
|
nvme_ctrlr_add_process(discovery_ctrlr, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-22 21:01:51 +00:00
|
|
|
rc = nvme_fabric_ctrlr_discover(discovery_ctrlr, cb_ctx, probe_cb);
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_ctrlr_destruct(discovery_ctrlr);
|
2018-06-22 21:01:51 +00:00
|
|
|
return rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 22:14:45 +00:00
|
|
|
struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
|
|
|
|
const struct spdk_nvme_ctrlr_opts *opts,
|
|
|
|
void *devhandle)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2016-11-18 22:21:04 +00:00
|
|
|
union spdk_nvme_cap_register cap;
|
2018-04-24 21:13:14 +00:00
|
|
|
union spdk_nvme_vs_register vs;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rctrlr = calloc(1, sizeof(struct nvme_rdma_ctrlr));
|
|
|
|
if (rctrlr == NULL) {
|
|
|
|
SPDK_ERRLOG("could not allocate ctrlr\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-09 22:09:28 +00:00
|
|
|
rctrlr->ctrlr.trid.trtype = SPDK_NVME_TRANSPORT_RDMA;
|
2016-11-28 23:26:04 +00:00
|
|
|
rctrlr->ctrlr.opts = *opts;
|
2016-12-09 22:09:28 +00:00
|
|
|
memcpy(&rctrlr->ctrlr.trid, trid, sizeof(rctrlr->ctrlr.trid));
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
rc = nvme_ctrlr_construct(&rctrlr->ctrlr);
|
|
|
|
if (rc != 0) {
|
2018-07-30 02:17:27 +00:00
|
|
|
free(rctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-15 23:39:54 +00:00
|
|
|
rctrlr->ctrlr.adminq = nvme_rdma_ctrlr_create_qpair(&rctrlr->ctrlr, 0,
|
2017-04-03 22:52:53 +00:00
|
|
|
SPDK_NVMF_MIN_ADMIN_QUEUE_ENTRIES, 0, SPDK_NVMF_MIN_ADMIN_QUEUE_ENTRIES);
|
2016-12-15 23:36:08 +00:00
|
|
|
if (!rctrlr->ctrlr.adminq) {
|
|
|
|
SPDK_ERRLOG("failed to create admin qpair\n");
|
2018-07-30 02:17:27 +00:00
|
|
|
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-18 22:21:04 +00:00
|
|
|
if (nvme_ctrlr_get_cap(&rctrlr->ctrlr, &cap)) {
|
|
|
|
SPDK_ERRLOG("get_cap() failed\n");
|
|
|
|
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-24 21:13:14 +00:00
|
|
|
if (nvme_ctrlr_get_vs(&rctrlr->ctrlr, &vs)) {
|
|
|
|
SPDK_ERRLOG("get_vs() failed\n");
|
|
|
|
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-11 22:57:19 +00:00
|
|
|
if (nvme_ctrlr_add_process(&rctrlr->ctrlr, 0) != 0) {
|
|
|
|
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
|
|
|
|
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-24 21:13:14 +00:00
|
|
|
nvme_ctrlr_init_cap(&rctrlr->ctrlr, &cap, &vs);
|
2016-11-18 22:21:04 +00:00
|
|
|
|
2018-08-24 09:09:27 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "successfully initialized the nvmf ctrlr\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return &rctrlr->ctrlr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_ctrlr *rctrlr = nvme_rdma_ctrlr(ctrlr);
|
|
|
|
|
2016-11-28 22:25:05 +00:00
|
|
|
if (ctrlr->adminq) {
|
|
|
|
nvme_rdma_qpair_destroy(ctrlr->adminq);
|
|
|
|
}
|
|
|
|
|
2018-02-13 12:33:57 +00:00
|
|
|
nvme_ctrlr_destruct_finish(ctrlr);
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
free(rctrlr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value)
|
|
|
|
{
|
2018-06-22 20:54:04 +00:00
|
|
|
return nvme_fabric_ctrlr_set_reg_4(ctrlr, offset, value);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value)
|
|
|
|
{
|
2018-06-22 20:54:04 +00:00
|
|
|
return nvme_fabric_ctrlr_set_reg_8(ctrlr, offset, value);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value)
|
|
|
|
{
|
2018-06-22 20:54:04 +00:00
|
|
|
return nvme_fabric_ctrlr_get_reg_4(ctrlr, offset, value);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value)
|
|
|
|
{
|
2018-06-22 20:54:04 +00:00
|
|
|
return nvme_fabric_ctrlr_get_reg_8(ctrlr, offset, value);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair,
|
|
|
|
struct nvme_request *req)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_send_wr *wr, *bad_wr = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
2016-12-01 06:14:07 +00:00
|
|
|
assert(rqpair != NULL);
|
|
|
|
assert(req != NULL);
|
2016-12-15 01:29:22 +00:00
|
|
|
|
|
|
|
rdma_req = nvme_rdma_req_get(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (!rdma_req) {
|
2016-12-08 18:35:53 +00:00
|
|
|
/*
|
|
|
|
* No rdma_req is available. Queue the request to be processed later.
|
|
|
|
*/
|
|
|
|
STAILQ_INSERT_TAIL(&qpair->queued_req, req, stailq);
|
|
|
|
return 0;
|
2016-12-15 01:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nvme_rdma_req_init(rqpair, req, rdma_req)) {
|
|
|
|
SPDK_ERRLOG("nvme_rdma_req_init() failed\n");
|
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-20 20:02:45 +00:00
|
|
|
req->timed_out = false;
|
|
|
|
if (spdk_unlikely(rqpair->qpair.ctrlr->timeout_enabled)) {
|
|
|
|
req->submit_tick = spdk_get_ticks();
|
|
|
|
} else {
|
|
|
|
req->submit_tick = 0;
|
|
|
|
}
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
wr = &rdma_req->send_wr;
|
2016-11-28 20:50:36 +00:00
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
nvme_rdma_trace_ibv_sge(wr->sg_list);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
rc = ibv_post_send(rqpair->cm_id->qp, wr, &bad_wr);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc) {
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_ERRLOG("Failure posting rdma send for NVMf completion: %d (%s)\n", rc, spdk_strerror(rc));
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-11-28 22:25:05 +00:00
|
|
|
return nvme_rdma_qpair_destroy(qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_reinit_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-12-15 21:36:19 +00:00
|
|
|
return nvme_rdma_qpair_connect(nvme_rdma_qpair(qpair));
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_qpair_enable(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
/* Currently, doing nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_qpair_disable(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
/* Currently, doing nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_qpair_reset(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
/* Currently, doing nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_qpair_fail(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
/* Currently, doing nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:03:49 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_qpair_check_timeout(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
uint64_t t02;
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req, *tmp;
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr = qpair->ctrlr;
|
|
|
|
struct spdk_nvme_ctrlr_process *active_proc;
|
|
|
|
|
|
|
|
/* Don't check timeouts during controller initialization. */
|
|
|
|
if (ctrlr->state != NVME_CTRLR_STATE_READY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvme_qpair_is_admin_queue(qpair)) {
|
|
|
|
active_proc = spdk_nvme_ctrlr_get_current_process(ctrlr);
|
|
|
|
} else {
|
|
|
|
active_proc = qpair->active_proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only check timeouts if the current process has a timeout callback. */
|
|
|
|
if (active_proc == NULL || active_proc->timeout_cb_fn == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t02 = spdk_get_ticks();
|
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rqpair->outstanding_reqs, link, tmp) {
|
|
|
|
assert(rdma_req->req != NULL);
|
|
|
|
|
|
|
|
if (nvme_request_check_timeout(rdma_req->req, rdma_req->id, active_proc, t02)) {
|
|
|
|
/*
|
|
|
|
* The requests are in order, so as soon as one has not timed out,
|
|
|
|
* stop iterating.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
#define MAX_COMPLETIONS_PER_POLL 128
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
int
|
|
|
|
nvme_rdma_qpair_process_completions(struct spdk_nvme_qpair *qpair,
|
|
|
|
uint32_t max_completions)
|
|
|
|
{
|
2018-03-02 19:49:36 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct ibv_wc wc[MAX_COMPLETIONS_PER_POLL];
|
2016-12-20 19:18:30 +00:00
|
|
|
int i, rc, batch_size;
|
2018-03-02 19:49:36 +00:00
|
|
|
uint32_t reaped;
|
2017-03-08 17:30:49 +00:00
|
|
|
struct ibv_cq *cq;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
if (max_completions == 0) {
|
|
|
|
max_completions = rqpair->num_entries;
|
|
|
|
} else {
|
2017-02-02 17:07:12 +00:00
|
|
|
max_completions = spdk_min(max_completions, rqpair->num_entries);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
cq = rqpair->cq;
|
2016-12-20 19:18:30 +00:00
|
|
|
|
|
|
|
reaped = 0;
|
|
|
|
do {
|
2017-02-02 17:07:12 +00:00
|
|
|
batch_size = spdk_min((max_completions - reaped),
|
2016-12-20 19:18:30 +00:00
|
|
|
MAX_COMPLETIONS_PER_POLL);
|
2017-03-08 17:30:49 +00:00
|
|
|
rc = ibv_poll_cq(cq, batch_size, wc);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
2016-12-20 19:18:30 +00:00
|
|
|
SPDK_ERRLOG("Error polling CQ! (%d): %s\n",
|
2017-11-07 12:56:52 +00:00
|
|
|
errno, spdk_strerror(errno));
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
2016-12-20 19:18:30 +00:00
|
|
|
} else if (rc == 0) {
|
|
|
|
/* Ran out of completions */
|
2016-11-15 05:42:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
for (i = 0; i < rc; i++) {
|
|
|
|
if (wc[i].status) {
|
|
|
|
SPDK_ERRLOG("CQ error on Queue Pair %p, Response Index %lu (%d): %s\n",
|
|
|
|
qpair, wc[i].wr_id, wc[i].status, ibv_wc_status_str(wc[i].status));
|
2016-12-20 19:10:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
switch (wc[i].opcode) {
|
|
|
|
case IBV_WC_RECV:
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "CQ recv completion\n");
|
2017-03-08 17:30:49 +00:00
|
|
|
|
|
|
|
reaped++;
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
if (wc[i].byte_len < sizeof(struct spdk_nvme_cpl)) {
|
|
|
|
SPDK_ERRLOG("recv length %u less than expected response size\n", wc[i].byte_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvme_rdma_recv(rqpair, wc[i].wr_id)) {
|
|
|
|
SPDK_ERRLOG("nvme_rdma_recv processing failure\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
case IBV_WC_SEND:
|
|
|
|
break;
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Received an unexpected opcode on the CQ: %d\n", wc[i].opcode);
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 19:18:30 +00:00
|
|
|
} while (reaped < max_completions);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-06-12 20:03:49 +00:00
|
|
|
if (spdk_unlikely(rqpair->qpair.ctrlr->timeout_enabled)) {
|
|
|
|
nvme_rdma_qpair_check_timeout(qpair);
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
return reaped;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nvme_rdma_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
/* Todo, which should get from the NVMF target */
|
2016-11-18 22:45:47 +00:00
|
|
|
return NVME_RDMA_RW_BUFFER_SIZE;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2016-12-15 00:03:39 +00:00
|
|
|
|
2017-08-02 19:03:06 +00:00
|
|
|
uint16_t
|
|
|
|
nvme_rdma_ctrlr_get_max_sges(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We do not support >1 SGE in the initiator currently,
|
|
|
|
* so we can only return 1 here. Once that support is
|
|
|
|
* added, this should return ctrlr->cdata.nvmf_specific.msdbd
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-21 23:35:11 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
nvme_rdma_ctrlr_alloc_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, size_t size)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_rdma_ctrlr_free_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|