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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <infiniband/verbs.h>
|
|
|
|
#include <rdma/rdma_cma.h>
|
2016-06-07 22:25:28 +00:00
|
|
|
#include <rdma/rdma_verbs.h>
|
2016-06-06 21:44:30 +00:00
|
|
|
#include <unistd.h>
|
2016-06-27 22:22:48 +00:00
|
|
|
#include <stdint.h>
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
#include <rte_config.h>
|
|
|
|
#include <rte_debug.h>
|
|
|
|
#include <rte_cycles.h>
|
|
|
|
#include <rte_timer.h>
|
2016-06-23 22:43:41 +00:00
|
|
|
#include <rte_malloc.h>
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
#include "conn.h"
|
|
|
|
#include "rdma.h"
|
|
|
|
#include "port.h"
|
2016-06-08 23:15:04 +00:00
|
|
|
#include "host.h"
|
2016-06-27 22:22:48 +00:00
|
|
|
#include "spdk/assert.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
|
|
|
|
#define ACCEPT_TIMEOUT (rte_get_timer_hz() >> 10) /* ~1ms */
|
|
|
|
#define MAX_RDMA_DEVICES 4
|
|
|
|
#define MAX_SESSIONS_PER_DEVICE 1 /* for now accept only single session per device */
|
|
|
|
|
2016-06-20 16:43:54 +00:00
|
|
|
/*
|
|
|
|
RDMA Connection Resouce Defaults
|
|
|
|
*/
|
|
|
|
#define NVMF_DEFAULT_TX_SGE 1
|
|
|
|
#define NVMF_DEFAULT_RX_SGE 2
|
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
struct spdk_nvmf_rdma {
|
|
|
|
struct rte_timer acceptor_timer;
|
|
|
|
struct rdma_event_channel *acceptor_event_channel;
|
|
|
|
struct rdma_cm_id *acceptor_listen_id;
|
|
|
|
};
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
static struct spdk_nvmf_rdma g_rdma = { };
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
static inline struct spdk_nvmf_rdma_request *
|
|
|
|
get_rdma_req(struct spdk_nvmf_request *req)
|
2016-06-24 19:42:26 +00:00
|
|
|
{
|
2016-06-27 22:22:48 +00:00
|
|
|
return (struct spdk_nvmf_rdma_request *)((uintptr_t)req + offsetof(struct spdk_nvmf_rdma_request,
|
|
|
|
req));
|
2016-06-24 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
static int
|
2016-06-07 22:21:21 +00:00
|
|
|
nvmf_rdma_queue_init(struct spdk_nvmf_conn *conn,
|
|
|
|
struct ibv_context *verbs)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-06-07 22:21:21 +00:00
|
|
|
int rc;
|
|
|
|
struct ibv_qp_init_attr attr;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-24 19:04:41 +00:00
|
|
|
if (conn->rdma.ctx) {
|
2016-06-07 22:21:21 +00:00
|
|
|
SPDK_ERRLOG("context already set!\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
goto return_error;
|
|
|
|
}
|
2016-06-24 19:04:41 +00:00
|
|
|
conn->rdma.ctx = verbs;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-24 19:04:41 +00:00
|
|
|
conn->rdma.comp_channel = ibv_create_comp_channel(verbs);
|
|
|
|
if (!conn->rdma.comp_channel) {
|
2016-06-07 22:21:21 +00:00
|
|
|
SPDK_ERRLOG("create completion channel error!\n");
|
2016-06-07 22:27:58 +00:00
|
|
|
goto return_error;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = fcntl(conn->rdma.comp_channel->fd, F_SETFL, O_NONBLOCK);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc < 0) {
|
2016-06-07 22:21:21 +00:00
|
|
|
SPDK_ERRLOG("fcntl to set comp channel to non-blocking failed\n");
|
2016-06-07 22:25:28 +00:00
|
|
|
goto cq_error;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-06-27 22:48:43 +00:00
|
|
|
* Size the CQ to handle completions for RECV, SEND, and either READ or WRITE.
|
2016-06-06 21:44:30 +00:00
|
|
|
*/
|
2016-06-27 22:48:43 +00:00
|
|
|
conn->rdma.cq = ibv_create_cq(verbs, (conn->rdma.queue_depth * 3), conn, conn->rdma.comp_channel,
|
|
|
|
0);
|
2016-06-24 19:04:41 +00:00
|
|
|
if (!conn->rdma.cq) {
|
2016-06-07 22:21:21 +00:00
|
|
|
SPDK_ERRLOG("create cq error!\n");
|
|
|
|
goto cq_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&attr, 0, sizeof(struct ibv_qp_init_attr));
|
|
|
|
attr.qp_type = IBV_QPT_RC;
|
2016-06-24 19:04:41 +00:00
|
|
|
attr.send_cq = conn->rdma.cq;
|
|
|
|
attr.recv_cq = conn->rdma.cq;
|
2016-06-27 22:48:43 +00:00
|
|
|
attr.cap.max_send_wr = conn->rdma.queue_depth * 2; /* SEND, READ, and WRITE operations */
|
|
|
|
attr.cap.max_recv_wr = conn->rdma.queue_depth; /* RECV operations */
|
2016-06-07 22:21:21 +00:00
|
|
|
attr.cap.max_send_sge = NVMF_DEFAULT_TX_SGE;
|
|
|
|
attr.cap.max_recv_sge = NVMF_DEFAULT_RX_SGE;
|
|
|
|
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = rdma_create_qp(conn->rdma.cm_id, NULL, &attr);
|
2016-06-07 22:21:21 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("rdma_create_qp failed\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
goto cq_error;
|
|
|
|
}
|
2016-06-24 19:04:41 +00:00
|
|
|
conn->rdma.qp = conn->rdma.cm_id->qp;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cq_error:
|
2016-06-24 19:04:41 +00:00
|
|
|
ibv_destroy_comp_channel(conn->rdma.comp_channel);
|
2016-06-06 21:44:30 +00:00
|
|
|
return_error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-27 22:22:48 +00:00
|
|
|
free_rdma_req(struct spdk_nvmf_rdma_request *rdma_req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-06-27 22:22:48 +00:00
|
|
|
if (rdma_req->cmd_mr && rdma_dereg_mr(rdma_req->cmd_mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register cmd_mr\n");
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
if (rdma_req->rsp_mr && rdma_dereg_mr(rdma_req->rsp_mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register rsp_mr\n");
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
if (rdma_req->bb_mr && rdma_dereg_mr(rdma_req->bb_mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register bb_mr\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
rte_free(rdma_req->bb);
|
|
|
|
rte_free(rdma_req);
|
|
|
|
}
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-28 16:51:15 +00:00
|
|
|
void
|
|
|
|
spdk_nvmf_rdma_free_req(struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req = get_rdma_req(req);
|
|
|
|
|
|
|
|
STAILQ_REMOVE(&req->conn->rdma.rdma_reqs, rdma_req, spdk_nvmf_rdma_request, link);
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
}
|
|
|
|
|
2016-06-28 16:55:28 +00:00
|
|
|
void
|
|
|
|
spdk_nvmf_rdma_free_reqs(struct spdk_nvmf_conn *conn)
|
2016-06-27 22:22:48 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
STAILQ_FOREACH(rdma_req, &conn->rdma.rdma_reqs, link) {
|
|
|
|
STAILQ_REMOVE(&conn->rdma.rdma_reqs, rdma_req, spdk_nvmf_rdma_request, link);
|
|
|
|
free_rdma_req(rdma_req);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 16:15:35 +00:00
|
|
|
static struct spdk_nvmf_rdma_request *
|
|
|
|
alloc_rdma_req(struct spdk_nvmf_conn *conn)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
|
|
|
|
rdma_req = rte_zmalloc("nvmf_rdma_req", sizeof(*rdma_req), 0);
|
|
|
|
if (!rdma_req) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate rdma_req\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdma_req->cmd_mr = rdma_reg_msgs(conn->rdma.cm_id, &rdma_req->cmd, sizeof(rdma_req->cmd));
|
|
|
|
if (rdma_req->cmd_mr == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to register cmd_mr\n");
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdma_req->recv_sgl.addr = (uint64_t)&rdma_req->cmd;
|
|
|
|
rdma_req->recv_sgl.length = sizeof(rdma_req->cmd);
|
|
|
|
rdma_req->recv_sgl.lkey = rdma_req->cmd_mr->lkey;
|
|
|
|
|
|
|
|
if (conn->type == CONN_TYPE_AQ) {
|
|
|
|
/* Admin commands can only send 4k of data maximum */
|
|
|
|
rdma_req->bb_len = SMALL_BB_MAX_SIZE;
|
|
|
|
} else {
|
|
|
|
rdma_req->bb_len = LARGE_BB_MAX_SIZE;
|
|
|
|
}
|
|
|
|
rdma_req->bb = rte_zmalloc("nvmf_bb", rdma_req->bb_len, 0);
|
|
|
|
if (!rdma_req->bb) {
|
|
|
|
SPDK_ERRLOG("Unable to get %u byte bounce buffer\n", rdma_req->bb_len);
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rdma_req->bb_mr = rdma_reg_read(conn->rdma.cm_id,
|
|
|
|
(void *)rdma_req->bb,
|
|
|
|
rdma_req->bb_len);
|
|
|
|
if (rdma_req->bb_mr == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to register bb_mr\n");
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize bb_sgl */
|
|
|
|
rdma_req->bb_sgl.addr = (uint64_t)rdma_req->bb;
|
|
|
|
rdma_req->bb_sgl.length = rdma_req->bb_len;
|
|
|
|
rdma_req->bb_sgl.lkey = rdma_req->bb_mr->lkey;
|
|
|
|
|
|
|
|
rdma_req->rsp_mr = rdma_reg_msgs(conn->rdma.cm_id, &rdma_req->rsp, sizeof(rdma_req->rsp));
|
|
|
|
if (rdma_req->rsp_mr == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to register rsp_mr\n");
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize send_sgl */
|
|
|
|
rdma_req->send_sgl.addr = (uint64_t)&rdma_req->rsp;
|
|
|
|
rdma_req->send_sgl.length = sizeof(rdma_req->rsp);
|
|
|
|
rdma_req->send_sgl.lkey = rdma_req->rsp_mr->lkey;
|
|
|
|
|
|
|
|
rdma_req->req.cmd = &rdma_req->cmd;
|
|
|
|
rdma_req->req.rsp = &rdma_req->rsp;
|
|
|
|
rdma_req->req.conn = conn;
|
|
|
|
|
|
|
|
return rdma_req;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
static void
|
|
|
|
nvmf_drain_cq(struct spdk_nvmf_conn *conn)
|
|
|
|
{
|
|
|
|
struct ibv_wc wc;
|
|
|
|
|
|
|
|
/* drain the cq before destruction */
|
2016-06-24 19:04:41 +00:00
|
|
|
while (ibv_poll_cq(conn->rdma.cq, 1, &wc) > 0) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "drain cq event\n");
|
|
|
|
//ibv_ack_cq_events(conn->cq, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvmf_rdma_conn_cleanup(struct spdk_nvmf_conn *conn)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "Enter\n");
|
|
|
|
|
2016-06-24 19:04:41 +00:00
|
|
|
rdma_destroy_qp(conn->rdma.cm_id);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-28 16:55:28 +00:00
|
|
|
spdk_nvmf_rdma_free_reqs(conn);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
nvmf_drain_cq(conn);
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = ibv_destroy_cq(conn->rdma.cq);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("ibv_destroy_cq error\n");
|
|
|
|
}
|
|
|
|
|
2016-06-24 19:04:41 +00:00
|
|
|
ibv_destroy_comp_channel(conn->rdma.comp_channel);
|
|
|
|
rdma_destroy_id(conn->rdma.cm_id);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 02:16:09 +00:00
|
|
|
static void
|
|
|
|
nvmf_trace_ibv_sge(struct ibv_sge *sg_list)
|
|
|
|
{
|
2016-06-28 16:51:15 +00:00
|
|
|
if (sg_list) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "local addr %p length 0x%x lkey 0x%x\n",
|
|
|
|
(void *)sg_list->addr, sg_list->length, sg_list->lkey);
|
|
|
|
}
|
2016-06-07 02:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_ibv_send_wr_init(struct ibv_send_wr *wr,
|
2016-06-27 17:04:04 +00:00
|
|
|
struct spdk_nvmf_request *req,
|
2016-06-07 02:16:09 +00:00
|
|
|
struct ibv_sge *sg_list,
|
|
|
|
uint64_t wr_id,
|
|
|
|
enum ibv_wr_opcode opcode,
|
|
|
|
int send_flags)
|
|
|
|
{
|
|
|
|
RTE_VERIFY(wr != NULL);
|
|
|
|
RTE_VERIFY(sg_list != NULL);
|
|
|
|
|
|
|
|
memset(wr, 0, sizeof(*wr));
|
|
|
|
wr->wr_id = wr_id;
|
|
|
|
wr->next = NULL;
|
|
|
|
wr->opcode = opcode;
|
|
|
|
wr->send_flags = send_flags;
|
|
|
|
wr->sg_list = sg_list;
|
|
|
|
wr->num_sge = 1;
|
|
|
|
|
|
|
|
if (req != NULL) {
|
2016-06-27 22:57:38 +00:00
|
|
|
struct spdk_nvme_sgl_descriptor *sgl = &req->cmd->nvme_cmd.dptr.sgl1;
|
|
|
|
|
|
|
|
RTE_VERIFY(sgl->generic.type == SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK);
|
|
|
|
|
|
|
|
wr->wr.rdma.rkey = sgl->keyed.key;
|
|
|
|
wr->wr.rdma.remote_addr = sgl->address;
|
2016-06-07 02:16:09 +00:00
|
|
|
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "rkey %x remote_addr %p\n",
|
|
|
|
wr->wr.rdma.rkey, (void *)wr->wr.rdma.remote_addr);
|
2016-06-07 02:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nvmf_trace_ibv_sge(wr->sg_list);
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
int
|
|
|
|
nvmf_post_rdma_read(struct spdk_nvmf_conn *conn,
|
2016-06-27 17:04:04 +00:00
|
|
|
struct spdk_nvmf_request *req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
struct ibv_send_wr wr, *bad_wr = NULL;
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req = get_rdma_req(req);
|
2016-06-06 21:44:30 +00:00
|
|
|
int rc;
|
|
|
|
|
2016-06-23 23:52:56 +00:00
|
|
|
/* temporarily adjust SGE to only copy what the host is prepared to send. */
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req->bb_sgl.length = req->length;
|
2016-06-23 23:52:56 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
nvmf_ibv_send_wr_init(&wr, req, &rdma_req->bb_sgl, (uint64_t)rdma_req,
|
2016-06-07 02:16:09 +00:00
|
|
|
IBV_WR_RDMA_READ, IBV_SEND_SIGNALED);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-23 21:36:30 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_READ_START, 0, 0, (uint64_t)req, 0);
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = ibv_post_send(conn->rdma.qp, &wr, &bad_wr);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failure posting rdma read send, rc = 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2016-06-24 23:39:53 +00:00
|
|
|
static int
|
2016-06-06 21:44:30 +00:00
|
|
|
nvmf_post_rdma_write(struct spdk_nvmf_conn *conn,
|
2016-06-27 17:04:04 +00:00
|
|
|
struct spdk_nvmf_request *req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
struct ibv_send_wr wr, *bad_wr = NULL;
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req = get_rdma_req(req);
|
2016-06-06 21:44:30 +00:00
|
|
|
int rc;
|
|
|
|
|
2016-06-23 23:52:56 +00:00
|
|
|
/* temporarily adjust SGE to only copy what the host is prepared to receive. */
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req->bb_sgl.length = req->length;
|
2016-06-23 23:52:56 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
nvmf_ibv_send_wr_init(&wr, req, &rdma_req->bb_sgl, (uint64_t)rdma_req,
|
2016-06-07 02:16:09 +00:00
|
|
|
IBV_WR_RDMA_WRITE, 0);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-23 21:36:30 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_WRITE_START, 0, 0, (uint64_t)req, 0);
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = ibv_post_send(conn->rdma.qp, &wr, &bad_wr);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failure posting rdma write send, rc = 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2016-06-27 18:23:23 +00:00
|
|
|
static int
|
|
|
|
nvmf_post_rdma_recv(struct spdk_nvmf_conn *conn,
|
2016-06-28 17:57:14 +00:00
|
|
|
struct spdk_nvmf_request *req)
|
2016-06-27 18:23:23 +00:00
|
|
|
{
|
|
|
|
struct ibv_recv_wr wr, *bad_wr = NULL;
|
2016-06-28 17:57:14 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req = get_rdma_req(req);
|
2016-06-27 18:23:23 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Update Connection SQ Tracking, increment
|
|
|
|
the SQ head counter opening up another
|
|
|
|
RX recv slot.
|
|
|
|
*/
|
2016-06-27 22:48:43 +00:00
|
|
|
conn->sq_head < (conn->rdma.queue_depth - 1) ? (conn->sq_head++) : (conn->sq_head = 0);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "sq_head %x, sq_depth %x\n", conn->sq_head, conn->rdma.queue_depth);
|
2016-06-27 18:23:23 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
wr.wr_id = (uintptr_t)rdma_req;
|
2016-06-27 18:23:23 +00:00
|
|
|
wr.next = NULL;
|
2016-06-27 22:22:48 +00:00
|
|
|
wr.sg_list = &rdma_req->recv_sgl;
|
2016-06-27 18:23:23 +00:00
|
|
|
wr.num_sge = 1;
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
nvmf_trace_ibv_sge(&rdma_req->recv_sgl);
|
2016-06-27 18:23:23 +00:00
|
|
|
|
|
|
|
/* for I/O queues we add bb sgl for in-capsule data use */
|
|
|
|
if (conn->type == CONN_TYPE_IOQ) {
|
|
|
|
wr.num_sge = 2;
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "sgl2 local addr %p, length 0x%x, lkey 0x%x\n",
|
|
|
|
(void *)rdma_req->bb_sgl.addr,
|
|
|
|
rdma_req->bb_sgl.length,
|
|
|
|
rdma_req->bb_sgl.lkey);
|
2016-06-27 18:23:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = ibv_post_recv(conn->rdma.qp, &wr, &bad_wr);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failure posting rdma recv, rc = 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2016-06-24 23:39:53 +00:00
|
|
|
static int
|
2016-06-06 21:44:30 +00:00
|
|
|
nvmf_post_rdma_send(struct spdk_nvmf_conn *conn,
|
2016-06-27 17:04:04 +00:00
|
|
|
struct spdk_nvmf_request *req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
struct ibv_send_wr wr, *bad_wr = NULL;
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req = get_rdma_req(req);
|
2016-06-06 21:44:30 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* restore the SGL length that may have been modified */
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req->bb_sgl.length = rdma_req->bb_len;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
nvmf_ibv_send_wr_init(&wr, NULL, &rdma_req->send_sgl, (uint64_t)rdma_req,
|
2016-06-07 02:16:09 +00:00
|
|
|
IBV_WR_SEND, IBV_SEND_SIGNALED);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-23 21:36:30 +00:00
|
|
|
spdk_trace_record(TRACE_NVMF_IO_COMPLETE, 0, 0, (uint64_t)req, 0);
|
2016-06-24 19:04:41 +00:00
|
|
|
rc = ibv_post_send(conn->rdma.qp, &wr, &bad_wr);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failure posting rdma send for NVMf completion, rc = 0x%x\n", rc);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2016-06-24 23:39:53 +00:00
|
|
|
int
|
2016-06-28 17:57:14 +00:00
|
|
|
spdk_nvmf_rdma_request_complete(struct spdk_nvmf_conn *conn,
|
|
|
|
struct spdk_nvmf_request *req)
|
2016-06-24 23:39:53 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Was the command successful? */
|
|
|
|
if (rsp->status.sc == SPDK_NVME_SC_SUCCESS &&
|
|
|
|
req->xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
|
|
|
/* Need to transfer data via RDMA Write */
|
|
|
|
ret = nvmf_post_rdma_write(conn, req);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("Unable to post rdma write tx descriptor\n");
|
2016-06-27 21:29:40 +00:00
|
|
|
return -1;
|
2016-06-24 23:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nvmf_post_rdma_send(conn, req);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("Unable to send response capsule\n");
|
2016-06-27 21:29:40 +00:00
|
|
|
return -1;
|
2016-06-24 23:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-28 17:57:14 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_rdma_request_release(struct spdk_nvmf_conn *conn,
|
|
|
|
struct spdk_nvmf_request *req)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nvmf_post_rdma_recv(req->conn, req)) {
|
|
|
|
SPDK_ERRLOG("Unable to re-post rx descriptor\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-28 16:17:41 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_rdma_alloc_reqs(struct spdk_nvmf_conn *conn)
|
2016-06-27 22:22:48 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
int i;
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
for (i = 0; i < conn->rdma.queue_depth; i++) {
|
2016-06-28 16:15:35 +00:00
|
|
|
rdma_req = alloc_rdma_req(conn);
|
|
|
|
if (rdma_req == NULL) {
|
2016-06-27 22:22:48 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "rdma_req %p: req %p, rsp %p\n",
|
|
|
|
rdma_req, &rdma_req->req,
|
|
|
|
rdma_req->req.rsp);
|
|
|
|
|
2016-06-28 17:57:14 +00:00
|
|
|
if (nvmf_post_rdma_recv(conn, &rdma_req->req)) {
|
2016-06-28 16:08:25 +00:00
|
|
|
SPDK_ERRLOG("Unable to post connection rx desc\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
STAILQ_INSERT_TAIL(&conn->rdma.rdma_reqs, rdma_req, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
STAILQ_FOREACH(rdma_req, &conn->rdma.rdma_reqs, link) {
|
|
|
|
STAILQ_REMOVE(&conn->rdma.rdma_reqs, rdma_req, spdk_nvmf_rdma_request, link);
|
|
|
|
free_rdma_req(rdma_req);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
static int
|
2016-06-24 18:55:06 +00:00
|
|
|
nvmf_rdma_connect(struct rdma_cm_event *event)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-06-08 22:48:02 +00:00
|
|
|
struct spdk_nvmf_host *host;
|
2016-06-06 21:44:30 +00:00
|
|
|
struct spdk_nvmf_fabric_intf *fabric_intf;
|
|
|
|
struct rdma_cm_id *conn_id;
|
|
|
|
struct spdk_nvmf_conn *conn;
|
2016-06-28 16:51:15 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2016-06-06 21:44:30 +00:00
|
|
|
struct ibv_device_attr ibdev_attr;
|
|
|
|
struct sockaddr_in *addr;
|
2016-06-27 22:48:43 +00:00
|
|
|
struct rdma_conn_param *host_event_data = NULL;
|
|
|
|
struct rdma_conn_param ctrlr_event_data;
|
|
|
|
struct spdk_nvmf_rdma_accept_private_data accept_data;
|
2016-06-06 21:44:30 +00:00
|
|
|
uint16_t sts = 0;
|
|
|
|
char addr_str[INET_ADDRSTRLEN];
|
2016-06-27 22:48:43 +00:00
|
|
|
int rc, qp_depth, rw_depth;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Check to make sure we know about this rdma device */
|
|
|
|
if (event->id == NULL) {
|
|
|
|
SPDK_ERRLOG("connect request: missing cm_id\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
conn_id = event->id;
|
|
|
|
|
|
|
|
if (conn_id->verbs == NULL) {
|
|
|
|
SPDK_ERRLOG("connect request: missing cm_id ibv_context\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "Connect Recv on fabric intf name %s, dev_name %s\n",
|
|
|
|
conn_id->verbs->device->name, conn_id->verbs->device->dev_name);
|
|
|
|
addr = (struct sockaddr_in *)rdma_get_local_addr(conn_id);
|
|
|
|
inet_ntop(AF_INET, &(addr->sin_addr), addr_str, INET_ADDRSTRLEN);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Connect Route: local addr %s\n",
|
|
|
|
addr_str);
|
|
|
|
|
|
|
|
fabric_intf = spdk_nvmf_port_find_fabric_intf_by_addr(addr_str);
|
|
|
|
if (fabric_intf == NULL) {
|
|
|
|
SPDK_ERRLOG("connect request: rdma device does not exist!\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Found existing RDMA Device %p\n", fabric_intf);
|
|
|
|
|
|
|
|
/* validate remote address is within a provisioned initiator group */
|
|
|
|
addr = (struct sockaddr_in *)rdma_get_peer_addr(conn_id);
|
|
|
|
inet_ntop(AF_INET, &(addr->sin_addr), addr_str, INET_ADDRSTRLEN);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Connect Route: peer addr %s\n",
|
|
|
|
addr_str);
|
|
|
|
|
2016-06-08 23:00:39 +00:00
|
|
|
host = spdk_nvmf_host_find_by_addr(addr_str);
|
2016-06-08 22:48:02 +00:00
|
|
|
if (host == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_ERRLOG("connect request: remote host addr not provisioned!\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
2016-06-08 22:48:02 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Found approved remote host %p\n", host);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
/* Init the NVMf rdma transport connection */
|
|
|
|
conn = spdk_nvmf_allocate_conn();
|
|
|
|
if (conn == NULL) {
|
|
|
|
SPDK_ERRLOG("Error on nvmf connection creation\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the rdma_cm context id in our fabric connection context. This
|
|
|
|
* ptr can be used to get indirect access to ibv_context (cm_id->verbs)
|
|
|
|
* and also to ibv_device (cm_id->verbs->device)
|
|
|
|
*/
|
2016-06-24 19:04:41 +00:00
|
|
|
conn->rdma.cm_id = conn_id;
|
2016-06-23 18:54:54 +00:00
|
|
|
conn_id->context = conn;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
rc = ibv_query_device(conn_id->verbs, &ibdev_attr);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG(" Failed on query for device attributes\n");
|
2016-06-27 22:48:43 +00:00
|
|
|
goto err1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
host_event_data = &event->param.conn;
|
|
|
|
if (host_event_data->private_data == NULL ||
|
|
|
|
host_event_data->private_data_len < sizeof(struct spdk_nvmf_rdma_request_private_data)) {
|
|
|
|
/* No private data, so use defaults. */
|
|
|
|
qp_depth = nvmf_min(ibdev_attr.max_qp_wr, SPDK_NVMF_DEFAULT_MAX_QUEUE_DEPTH);
|
|
|
|
rw_depth = nvmf_min(ibdev_attr.max_qp_rd_atom, SPDK_NVMF_DEFAULT_MAX_QUEUE_DEPTH);
|
|
|
|
conn->qid = 0;
|
|
|
|
} else {
|
|
|
|
const struct spdk_nvmf_rdma_request_private_data *private_data = host_event_data->private_data;
|
|
|
|
qp_depth = nvmf_min(ibdev_attr.max_qp_wr, nvmf_min(private_data->hrqsize,
|
|
|
|
private_data->hsqsize));
|
|
|
|
rw_depth = nvmf_min(ibdev_attr.max_qp_rd_atom, host_event_data->initiator_depth);
|
|
|
|
conn->qid = private_data->qid;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-27 22:48:43 +00:00
|
|
|
conn->rdma.queue_depth = nvmf_min(qp_depth, rw_depth);
|
|
|
|
if (conn->qid > 0) {
|
|
|
|
conn->type = CONN_TYPE_IOQ;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 22:21:21 +00:00
|
|
|
rc = nvmf_rdma_queue_init(conn, conn_id->verbs);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("connect request: rdma conn init failure!\n");
|
2016-06-27 22:48:43 +00:00
|
|
|
goto err1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "NVMf fabric connection initialized\n");
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
STAILQ_INIT(&conn->rdma.rdma_reqs);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-28 16:51:15 +00:00
|
|
|
/* Allocate 1 buffer suitable for the CONNECT capsule.
|
|
|
|
* Once that is received, the full queue depth will be allocated.
|
|
|
|
*/
|
|
|
|
rdma_req = alloc_rdma_req(conn);
|
|
|
|
if (nvmf_post_rdma_recv(conn, &rdma_req->req)) {
|
|
|
|
SPDK_ERRLOG("Unable to post connection rx desc\n");
|
2016-06-27 22:48:43 +00:00
|
|
|
goto err1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-28 16:51:15 +00:00
|
|
|
STAILQ_INSERT_TAIL(&conn->rdma.rdma_reqs, rdma_req, link);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
rc = spdk_nvmf_startup_conn(conn);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Error on startup connection\n");
|
2016-06-27 22:48:43 +00:00
|
|
|
goto err1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "New Connection Scheduled\n");
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
accept_data.recfmt = 0;
|
|
|
|
accept_data.crqsize = conn->rdma.queue_depth;
|
|
|
|
if (host_event_data != NULL) {
|
|
|
|
memcpy(&ctrlr_event_data, host_event_data, sizeof(ctrlr_event_data));
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-06-27 22:48:43 +00:00
|
|
|
ctrlr_event_data.private_data = &accept_data;
|
|
|
|
ctrlr_event_data.private_data_len = sizeof(accept_data);
|
|
|
|
if (conn_id->ps == RDMA_PS_TCP) {
|
|
|
|
ctrlr_event_data.responder_resources = 0; /* We accept 0 reads from the host */
|
|
|
|
ctrlr_event_data.initiator_depth = conn->rdma.queue_depth;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
rc = rdma_accept(event->id, &ctrlr_event_data);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Error on rdma_accept\n");
|
2016-06-27 22:48:43 +00:00
|
|
|
goto err1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "Sent back the accept\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
err1: {
|
|
|
|
struct spdk_nvmf_rdma_reject_private_data rej_data;
|
|
|
|
|
|
|
|
rej_data.status.sc = sts;
|
|
|
|
rdma_reject(conn_id, &ctrlr_event_data, sizeof(rej_data));
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
err0:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-06-24 18:55:06 +00:00
|
|
|
nvmf_rdma_disconnect(struct rdma_cm_event *event)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
struct rdma_cm_id *conn_id;
|
|
|
|
struct spdk_nvmf_conn *conn;
|
|
|
|
|
|
|
|
/* Check to make sure we know about this rdma device */
|
|
|
|
if (event->id == NULL) {
|
|
|
|
SPDK_ERRLOG("disconnect request: missing cm_id\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
conn_id = event->id;
|
|
|
|
|
2016-06-23 18:54:54 +00:00
|
|
|
conn = conn_id->context;
|
2016-06-06 21:44:30 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
SPDK_ERRLOG("disconnect request: no active connection\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modify connection state to trigger async termination
|
|
|
|
* next time the connection poller executes
|
|
|
|
*/
|
|
|
|
conn->state = CONN_STATE_FABRIC_DISCONNECT;
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "rdma connection %p state set to CONN_STATE_FABRIC_DISCONNECT\n",
|
|
|
|
conn);
|
|
|
|
return 0;
|
|
|
|
err0:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *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"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2016-06-24 18:55:06 +00:00
|
|
|
nvmf_rdma_accept(struct rte_timer *timer, void *arg)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
struct rdma_cm_event *event;
|
|
|
|
int rc;
|
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
if (g_rdma.acceptor_event_channel == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2016-06-24 18:44:10 +00:00
|
|
|
rc = rdma_get_cm_event(g_rdma.acceptor_event_channel, &event);
|
2016-06-24 18:55:06 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Acceptor Event: %s\n", CM_EVENT_STR[event->event]);
|
|
|
|
|
|
|
|
switch (event->event) {
|
|
|
|
case RDMA_CM_EVENT_CONNECT_REQUEST:
|
|
|
|
rc = nvmf_rdma_connect(event);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to process connect event. rc: %d\n", rc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_ESTABLISHED:
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_ADDR_CHANGE:
|
|
|
|
case RDMA_CM_EVENT_DISCONNECTED:
|
|
|
|
case RDMA_CM_EVENT_DEVICE_REMOVAL:
|
|
|
|
case RDMA_CM_EVENT_TIMEWAIT_EXIT:
|
|
|
|
rc = nvmf_rdma_disconnect(event);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to process disconnect event. rc: %d\n", rc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unexpected Acceptor Event [%d]\n", event->event);
|
2016-06-06 21:44:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 18:55:06 +00:00
|
|
|
|
|
|
|
rdma_ack_cm_event(event);
|
2016-06-06 21:44:30 +00:00
|
|
|
} else {
|
|
|
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
2016-06-24 18:55:06 +00:00
|
|
|
SPDK_ERRLOG("Acceptor Event Error: %s\n", strerror(errno));
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int nvmf_acceptor_start(void)
|
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
uint16_t sin_port;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = g_nvmf_tgt.sin_port;
|
|
|
|
|
|
|
|
/* create an event channel with rdmacm to receive
|
|
|
|
connection oriented requests and notifications */
|
2016-06-24 18:44:10 +00:00
|
|
|
g_rdma.acceptor_event_channel = rdma_create_event_channel();
|
|
|
|
if (g_rdma.acceptor_event_channel == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_ERRLOG("rdma_create_event_channel() failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-24 18:44:10 +00:00
|
|
|
rc = fcntl(g_rdma.acceptor_event_channel->fd, F_SETFL, O_NONBLOCK);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("fcntl to set fd to non-blocking failed\n");
|
|
|
|
goto create_id_error;
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
rc = rdma_create_id(g_rdma.acceptor_event_channel, &g_rdma.acceptor_listen_id, NULL, RDMA_PS_TCP);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_create_id() failed\n");
|
|
|
|
goto create_id_error;
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
rc = rdma_bind_addr(g_rdma.acceptor_listen_id, (struct sockaddr *)&addr);
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_bind_addr() failed\n");
|
|
|
|
goto listen_error;
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
rc = rdma_listen(g_rdma.acceptor_listen_id, 10); /* 10 = backlog */
|
2016-06-06 21:44:30 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_listen() failed\n");
|
|
|
|
goto listen_error;
|
|
|
|
}
|
2016-06-24 18:44:10 +00:00
|
|
|
sin_port = ntohs(rdma_get_src_port(g_rdma.acceptor_listen_id));
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_NOTICELOG("*** NVMf Target Listening on port %d ***\n", sin_port);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-06-24 18:44:10 +00:00
|
|
|
rte_timer_init(&g_rdma.acceptor_timer);
|
|
|
|
rte_timer_reset(&g_rdma.acceptor_timer, ACCEPT_TIMEOUT, PERIODICAL,
|
2016-06-24 18:55:06 +00:00
|
|
|
rte_lcore_id(), nvmf_rdma_accept, NULL);
|
2016-06-06 21:44:30 +00:00
|
|
|
return (rc);
|
|
|
|
|
|
|
|
listen_error:
|
2016-06-24 18:44:10 +00:00
|
|
|
rdma_destroy_id(g_rdma.acceptor_listen_id);
|
2016-06-06 21:44:30 +00:00
|
|
|
create_id_error:
|
2016-06-24 18:44:10 +00:00
|
|
|
rdma_destroy_event_channel(g_rdma.acceptor_event_channel);
|
2016-06-06 21:44:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nvmf_acceptor_stop(void)
|
|
|
|
{
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, "nvmf_acceptor_stop: shutdown\n");
|
2016-06-24 18:44:10 +00:00
|
|
|
rte_timer_stop_sync(&g_rdma.acceptor_timer);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Initialize with RDMA transport. Query OFED for device list.
|
|
|
|
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nvmf_rdma_init(void)
|
|
|
|
{
|
|
|
|
struct ibv_device **dev_list;
|
|
|
|
struct ibv_context *ibdev_ctx = NULL;
|
|
|
|
struct ibv_device_attr ibdev_attr;
|
|
|
|
int num_of_rdma_devices;
|
|
|
|
int num_devices_found = 0;
|
|
|
|
int i, ret;
|
|
|
|
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_NOTICELOG("*** RDMA Transport Init ***\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
dev_list = ibv_get_device_list(&num_of_rdma_devices);
|
|
|
|
if (!dev_list) {
|
|
|
|
SPDK_ERRLOG(" No RDMA verbs devices found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " %d RDMA verbs device(s) discovered\n", num_of_rdma_devices);
|
|
|
|
|
|
|
|
/* Look through the list of devices for one we support */
|
|
|
|
for (i = 0; dev_list[i] && num_devices_found < MAX_RDMA_DEVICES; i++, ibdev_ctx = NULL) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, " RDMA Device %d:\n", i);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, " Node type: %d\n", (int)dev_list[i]->node_type);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, " Transport type: %d\n", (int)dev_list[i]->transport_type);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, " Name: %s\n", dev_list[i]->name);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_DEBUG, " Device Name: %s\n", dev_list[i]->dev_name);
|
|
|
|
|
|
|
|
ibdev_ctx = ibv_open_device(dev_list[i]);
|
|
|
|
if (!ibdev_ctx) {
|
|
|
|
SPDK_ERRLOG(" No rdma context returned for device %d\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ibv_query_device(ibdev_ctx, &ibdev_attr);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG(" Failed on query for device %d\n", i);
|
|
|
|
ibv_close_device(ibdev_ctx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* display device specific attributes */
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " RDMA Device Attributes:\n");
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max MR Size: 0x%llx\n", (long long int)ibdev_attr.max_mr_size);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Page Size Cap: 0x%llx\n",
|
|
|
|
(long long int)ibdev_attr.page_size_cap);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max QPs: 0x%x\n", (int)ibdev_attr.max_qp);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max QP WRs: 0x%x\n", (int)ibdev_attr.max_qp_wr);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max SGE: 0x%x\n", (int)ibdev_attr.max_sge);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max CQs: 0x%x\n", (int)ibdev_attr.max_cq);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max CQE per CQ: 0x%x\n", (int)ibdev_attr.max_cqe);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max MR: 0x%x\n", (int)ibdev_attr.max_mr);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max PD: 0x%x\n", (int)ibdev_attr.max_pd);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max QP RD Atom: 0x%x\n", (int)ibdev_attr.max_qp_rd_atom);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max QP Init RD Atom: 0x%x\n",
|
|
|
|
(int)ibdev_attr.max_qp_init_rd_atom);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max Res RD Atom: 0x%x\n", (int)ibdev_attr.max_res_rd_atom);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max EE: 0x%x\n", (int)ibdev_attr.max_ee);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max SRQ: 0x%x\n", (int)ibdev_attr.max_srq);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max SRQ WR: 0x%x\n", (int)ibdev_attr.max_srq_wr);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max SRQ SGE: 0x%x\n", (int)ibdev_attr.max_srq_sge);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Max PKeys: 0x%x\n", (int)ibdev_attr.max_pkeys);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " Phys Port Cnt: %d\n", (int)ibdev_attr.phys_port_cnt);
|
|
|
|
|
|
|
|
num_devices_found++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ibv_free_device_list(dev_list);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, " %d Fabric Intf(s) active\n", num_devices_found);
|
|
|
|
return num_devices_found;
|
|
|
|
}
|
|
|
|
|
2016-06-27 17:14:41 +00:00
|
|
|
static int
|
|
|
|
nvmf_recv(struct spdk_nvmf_conn *conn, struct ibv_wc *wc)
|
|
|
|
{
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2016-06-27 17:14:41 +00:00
|
|
|
struct spdk_nvmf_request *req;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req = (struct spdk_nvmf_rdma_request *)wc->wr_id;
|
2016-06-27 17:14:41 +00:00
|
|
|
|
2016-06-27 19:37:07 +00:00
|
|
|
if (wc->byte_len < sizeof(struct spdk_nvmf_capsule_cmd)) {
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_ERRLOG("recv length %u less than capsule header\n", wc->byte_len);
|
2016-06-27 17:14:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
req = &rdma_req->req;
|
2016-06-27 17:14:41 +00:00
|
|
|
|
|
|
|
ret = spdk_nvmf_request_prep_data(req,
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req->bb, wc->byte_len - sizeof(struct spdk_nvmf_capsule_cmd),
|
|
|
|
rdma_req->bb, rdma_req->bb_sgl.length);
|
2016-06-27 17:14:41 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
SPDK_ERRLOG("prep_data failed\n");
|
2016-06-27 20:56:38 +00:00
|
|
|
return spdk_nvmf_request_complete(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2016-06-27 17:14:41 +00:00
|
|
|
/* Data is available now; execute command immediately. */
|
|
|
|
ret = spdk_nvmf_request_exec(req);
|
|
|
|
if (ret < 0) {
|
|
|
|
SPDK_ERRLOG("Command execution failed\n");
|
2016-06-27 21:14:02 +00:00
|
|
|
return -1;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 21:14:02 +00:00
|
|
|
return 0;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 21:14:02 +00:00
|
|
|
/*
|
|
|
|
* Pending transfer from host to controller; command will continue
|
|
|
|
* once transfer is complete.
|
|
|
|
*/
|
|
|
|
return 0;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvmf_check_rdma_completions(struct spdk_nvmf_conn *conn)
|
|
|
|
{
|
|
|
|
struct ibv_wc wc;
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2016-06-27 17:14:41 +00:00
|
|
|
struct spdk_nvmf_request *req;
|
|
|
|
int rc;
|
|
|
|
int cq_count = 0;
|
|
|
|
int i;
|
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
for (i = 0; i < conn->rdma.queue_depth; i++) {
|
2016-06-27 17:14:41 +00:00
|
|
|
rc = ibv_poll_cq(conn->rdma.cq, 1, &wc);
|
|
|
|
if (rc == 0) // No completions at this time
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Poll CQ error!(%d): %s\n",
|
|
|
|
errno, strerror(errno));
|
2016-06-27 20:09:54 +00:00
|
|
|
return -1;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, process the single successful cq event */
|
|
|
|
cq_count += rc;
|
|
|
|
|
|
|
|
if (wc.status) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "CQ completion error status %d, exiting handler\n",
|
|
|
|
wc.status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (wc.opcode) {
|
|
|
|
case IBV_WC_SEND:
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "CQ send completion\n");
|
2016-06-28 17:57:14 +00:00
|
|
|
rdma_req = (struct spdk_nvmf_rdma_request *)wc.wr_id;
|
|
|
|
req = &rdma_req->req;
|
|
|
|
if (spdk_nvmf_request_release(req)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-27 17:14:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RDMA_WRITE:
|
|
|
|
/*
|
|
|
|
* Will get this event only if we set IBV_SEND_SIGNALED
|
|
|
|
* flag in rdma_write, to trace rdma write latency
|
|
|
|
*/
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "CQ rdma write completion\n");
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req = (struct spdk_nvmf_rdma_request *)wc.wr_id;
|
|
|
|
req = &rdma_req->req;
|
2016-06-27 17:14:41 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_WRITE_COMPLETE, 0, 0, (uint64_t)req, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RDMA_READ:
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "CQ rdma read completion\n");
|
2016-06-27 22:22:48 +00:00
|
|
|
rdma_req = (struct spdk_nvmf_rdma_request *)wc.wr_id;
|
|
|
|
req = &rdma_req->req;
|
2016-06-27 17:14:41 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_READ_COMPLETE, 0, 0, (uint64_t)req, 0);
|
|
|
|
rc = spdk_nvmf_request_exec(req);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("request_exec error %d after RDMA Read completion\n", rc);
|
2016-06-27 20:09:54 +00:00
|
|
|
return -1;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RECV:
|
2016-06-27 23:56:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "CQ recv completion\n");
|
2016-06-27 17:14:41 +00:00
|
|
|
spdk_trace_record(TRACE_NVMF_IO_START, 0, 0, wc.wr_id, 0);
|
|
|
|
rc = nvmf_recv(conn, &wc);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("nvmf_recv processing failure\n");
|
2016-06-27 20:09:54 +00:00
|
|
|
return -1;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Poll cq opcode type unknown!!!!! completion\n");
|
2016-06-27 20:09:54 +00:00
|
|
|
return -1;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cq_count;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_LOG_REGISTER_TRACE_FLAG("rdma", SPDK_TRACE_RDMA)
|