2016-06-06 21:44:30 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
#include <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
|
|
|
|
2016-07-15 21:45:26 +00:00
|
|
|
#include "nvmf_internal.h"
|
2016-07-11 22:24:49 +00:00
|
|
|
#include "request.h"
|
2017-07-13 21:18:08 +00:00
|
|
|
#include "ctrlr.h"
|
2016-07-15 18:34:11 +00:00
|
|
|
#include "subsystem.h"
|
2016-07-14 22:25:23 +00:00
|
|
|
#include "transport.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2016-06-27 22:22:48 +00:00
|
|
|
#include "spdk/assert.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
#include "spdk/nvmf.h"
|
2016-07-15 18:18:37 +00:00
|
|
|
#include "spdk/nvmf_spec.h"
|
2016-08-19 17:48:02 +00:00
|
|
|
#include "spdk/string.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/trace.h"
|
2017-03-13 22:14:12 +00:00
|
|
|
#include "spdk/util.h"
|
2017-05-05 06:59:58 +00:00
|
|
|
#include "spdk/likely.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-11-07 22:10:28 +00:00
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
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-07-28 17:23:52 +00:00
|
|
|
struct spdk_nvmf_rdma_buf {
|
|
|
|
SLIST_ENTRY(spdk_nvmf_rdma_buf) link;
|
|
|
|
};
|
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
/* This structure holds commands as they are received off the wire.
|
|
|
|
* It must be dynamically paired with a full request object
|
|
|
|
* (spdk_nvmf_rdma_request) to service a request. It is separate
|
|
|
|
* from the request because RDMA does not appear to order
|
|
|
|
* completions, so occasionally we'll get a new incoming
|
|
|
|
* command when there aren't any free request objects.
|
|
|
|
*/
|
|
|
|
struct spdk_nvmf_rdma_recv {
|
|
|
|
struct ibv_recv_wr wr;
|
|
|
|
struct ibv_sge sgl[NVMF_DEFAULT_RX_SGE];
|
|
|
|
|
|
|
|
/* In-capsule data buffer */
|
|
|
|
uint8_t *buf;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(spdk_nvmf_rdma_recv) link;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool in_use;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-07-22 23:16:25 +00:00
|
|
|
struct spdk_nvmf_rdma_request {
|
2016-07-27 22:30:42 +00:00
|
|
|
struct spdk_nvmf_request req;
|
2017-03-15 22:06:27 +00:00
|
|
|
bool data_from_pool;
|
2016-07-22 23:16:25 +00:00
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
struct spdk_nvmf_rdma_recv *recv;
|
2016-10-19 17:23:40 +00:00
|
|
|
|
2017-02-27 01:32:00 +00:00
|
|
|
struct {
|
|
|
|
struct ibv_send_wr wr;
|
|
|
|
struct ibv_sge sgl[NVMF_DEFAULT_TX_SGE];
|
|
|
|
} rsp;
|
|
|
|
|
2017-02-27 02:25:01 +00:00
|
|
|
struct {
|
|
|
|
struct ibv_send_wr wr;
|
|
|
|
struct ibv_sge sgl[NVMF_DEFAULT_TX_SGE];
|
|
|
|
} data;
|
2017-02-27 02:50:32 +00:00
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
TAILQ_ENTRY(spdk_nvmf_rdma_request) link;
|
2016-07-22 23:16:25 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair {
|
|
|
|
struct spdk_nvmf_qpair qpair;
|
2016-07-11 22:24:49 +00:00
|
|
|
|
|
|
|
struct rdma_cm_id *cm_id;
|
2016-09-15 22:10:23 +00:00
|
|
|
struct ibv_cq *cq;
|
2016-07-11 22:24:49 +00:00
|
|
|
|
2016-07-25 21:36:06 +00:00
|
|
|
/* The maximum number of I/O outstanding on this connection at one time */
|
2016-07-27 22:30:42 +00:00
|
|
|
uint16_t max_queue_depth;
|
2016-07-25 21:36:06 +00:00
|
|
|
|
|
|
|
/* The maximum number of active RDMA READ and WRITE operations at one time */
|
2016-07-27 22:30:42 +00:00
|
|
|
uint16_t max_rw_depth;
|
|
|
|
|
|
|
|
/* The current number of I/O outstanding on this connection. This number
|
|
|
|
* includes all I/O from the time the capsule is first received until it is
|
|
|
|
* completed.
|
|
|
|
*/
|
|
|
|
uint16_t cur_queue_depth;
|
2016-07-25 21:36:06 +00:00
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
/* The number of RDMA READ and WRITE requests that are outstanding */
|
|
|
|
uint16_t cur_rdma_rw_depth;
|
2016-07-14 20:52:03 +00:00
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
/* Receives that are waiting for a request object */
|
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_recv) incoming_queue;
|
|
|
|
|
|
|
|
/* Requests that are not in use */
|
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_request) free_queue;
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
/* Requests that are waiting to obtain a data buffer */
|
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_request) pending_data_buf_queue;
|
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
/* Requests that are waiting to perform an RDMA READ or WRITE */
|
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_request) pending_rdma_rw_queue;
|
|
|
|
|
|
|
|
/* Array of size "max_queue_depth" containing RDMA requests. */
|
2016-07-25 16:38:02 +00:00
|
|
|
struct spdk_nvmf_rdma_request *reqs;
|
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
/* Array of size "max_queue_depth" containing RDMA recvs. */
|
|
|
|
struct spdk_nvmf_rdma_recv *recvs;
|
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
/* Array of size "max_queue_depth" containing 64 byte capsules
|
2016-07-25 16:38:02 +00:00
|
|
|
* used for receive.
|
|
|
|
*/
|
|
|
|
union nvmf_h2c_msg *cmds;
|
|
|
|
struct ibv_mr *cmds_mr;
|
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
/* Array of size "max_queue_depth" containing 16 byte completions
|
2016-07-25 16:38:02 +00:00
|
|
|
* to be sent back to the user.
|
|
|
|
*/
|
|
|
|
union nvmf_c2h_msg *cpls;
|
|
|
|
struct ibv_mr *cpls_mr;
|
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
/* Array of size "max_queue_depth * InCapsuleDataSize" containing
|
2016-07-28 17:23:52 +00:00
|
|
|
* buffers to be used for in capsule data.
|
2016-07-25 16:38:02 +00:00
|
|
|
*/
|
|
|
|
void *bufs;
|
|
|
|
struct ibv_mr *bufs_mr;
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_ENTRY(spdk_nvmf_rdma_qpair) link;
|
2016-07-11 22:24:49 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 20:52:03 +00:00
|
|
|
/* List of RDMA connections that have not yet received a CONNECT capsule */
|
2017-07-13 21:30:28 +00:00
|
|
|
static TAILQ_HEAD(, spdk_nvmf_rdma_qpair) g_pending_conns = TAILQ_HEAD_INITIALIZER(g_pending_conns);
|
2016-07-14 20:52:03 +00:00
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_poll_group {
|
|
|
|
struct spdk_nvmf_poll_group group;
|
2016-10-19 19:41:11 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
SLIST_HEAD(, spdk_nvmf_rdma_buf) data_buf_pool;
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_device *device;
|
2016-10-19 18:16:17 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
uint8_t *buf;
|
|
|
|
struct ibv_mr *buf_mr;
|
2016-07-26 23:34:12 +00:00
|
|
|
};
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
/* Assuming rdma_cm uses just one protection domain per ibv_context. */
|
|
|
|
struct spdk_nvmf_rdma_device {
|
|
|
|
struct ibv_device_attr attr;
|
|
|
|
struct ibv_context *context;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(spdk_nvmf_rdma_device) link;
|
|
|
|
};
|
|
|
|
|
2016-08-18 02:58:15 +00:00
|
|
|
struct spdk_nvmf_rdma_listen_addr {
|
2017-07-13 20:13:05 +00:00
|
|
|
struct spdk_nvme_transport_id trid;
|
2016-08-18 02:58:15 +00:00
|
|
|
struct rdma_cm_id *id;
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_device *device;
|
2016-09-07 17:06:40 +00:00
|
|
|
struct ibv_comp_channel *comp_channel;
|
2017-01-25 11:51:35 +00:00
|
|
|
uint32_t ref;
|
2016-08-18 02:58:15 +00:00
|
|
|
TAILQ_ENTRY(spdk_nvmf_rdma_listen_addr) link;
|
|
|
|
};
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport {
|
|
|
|
struct spdk_nvmf_transport transport;
|
|
|
|
|
2016-09-16 22:29:13 +00:00
|
|
|
struct rdma_event_channel *event_channel;
|
|
|
|
|
|
|
|
pthread_mutex_t lock;
|
2016-07-25 21:28:44 +00:00
|
|
|
|
2016-09-16 22:29:13 +00:00
|
|
|
uint16_t max_queue_depth;
|
|
|
|
uint32_t max_io_size;
|
|
|
|
uint32_t in_capsule_data_size;
|
2016-08-18 02:58:15 +00:00
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_device) devices;
|
2016-08-18 02:58:15 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvmf_rdma_listen_addr) listen_addrs;
|
2016-06-24 18:44:10 +00:00
|
|
|
};
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-22 23:16:25 +00:00
|
|
|
static void
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(struct spdk_nvmf_rdma_qpair *rdma_qpair)
|
2016-07-22 23:16:25 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cmds_mr) {
|
|
|
|
ibv_dereg_mr(rdma_qpair->cmds_mr);
|
2016-07-22 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cpls_mr) {
|
|
|
|
ibv_dereg_mr(rdma_qpair->cpls_mr);
|
2016-07-22 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->bufs_mr) {
|
|
|
|
ibv_dereg_mr(rdma_qpair->bufs_mr);
|
2016-07-22 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cm_id) {
|
|
|
|
rdma_destroy_qp(rdma_qpair->cm_id);
|
|
|
|
rdma_destroy_id(rdma_qpair->cm_id);
|
2016-07-22 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cq) {
|
|
|
|
ibv_destroy_cq(rdma_qpair->cq);
|
2016-09-15 22:10:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:38:02 +00:00
|
|
|
/* Free all memory */
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_dma_free(rdma_qpair->cmds);
|
|
|
|
spdk_dma_free(rdma_qpair->cpls);
|
|
|
|
spdk_dma_free(rdma_qpair->bufs);
|
|
|
|
free(rdma_qpair->reqs);
|
|
|
|
free(rdma_qpair);
|
2016-07-22 23:16:25 +00:00
|
|
|
}
|
2016-07-22 17:36:02 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
static struct spdk_nvmf_rdma_qpair *
|
2017-07-24 23:30:07 +00:00
|
|
|
spdk_nvmf_rdma_qpair_create(struct spdk_nvmf_transport *transport,
|
|
|
|
struct rdma_cm_id *id, struct ibv_comp_channel *channel,
|
2017-07-13 21:30:28 +00:00
|
|
|
uint16_t max_queue_depth, uint16_t max_rw_depth, uint32_t subsystem_id)
|
2016-07-11 21:26:09 +00:00
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
2016-07-22 17:36:02 +00:00
|
|
|
int rc, i;
|
2016-07-22 16:59:10 +00:00
|
|
|
struct ibv_qp_init_attr attr;
|
2017-03-15 16:28:05 +00:00
|
|
|
struct spdk_nvmf_rdma_recv *rdma_recv;
|
2016-07-22 17:36:02 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2016-07-11 21:26:09 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair = calloc(1, sizeof(struct spdk_nvmf_rdma_qpair));
|
|
|
|
if (rdma_qpair == NULL) {
|
2016-07-11 21:26:09 +00:00
|
|
|
SPDK_ERRLOG("Could not allocate new connection.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->max_queue_depth = max_queue_depth;
|
|
|
|
rdma_qpair->max_rw_depth = max_rw_depth;
|
|
|
|
TAILQ_INIT(&rdma_qpair->incoming_queue);
|
|
|
|
TAILQ_INIT(&rdma_qpair->free_queue);
|
|
|
|
TAILQ_INIT(&rdma_qpair->pending_data_buf_queue);
|
|
|
|
TAILQ_INIT(&rdma_qpair->pending_rdma_rw_queue);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cq = ibv_create_cq(id->verbs, max_queue_depth * 3, rdma_qpair, channel, 0);
|
|
|
|
if (!rdma_qpair->cq) {
|
2016-09-15 22:10:23 +00:00
|
|
|
SPDK_ERRLOG("Unable to create completion queue\n");
|
2016-09-07 17:06:40 +00:00
|
|
|
SPDK_ERRLOG("Completion Channel: %p Id: %p Verbs: %p\n", channel, id, id->verbs);
|
2016-09-15 22:10:23 +00:00
|
|
|
SPDK_ERRLOG("Errno %d: %s\n", errno, strerror(errno));
|
2016-11-02 03:11:30 +00:00
|
|
|
rdma_destroy_id(id);
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-09-15 22:10:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-07 22:21:21 +00:00
|
|
|
memset(&attr, 0, sizeof(struct ibv_qp_init_attr));
|
|
|
|
attr.qp_type = IBV_QPT_RC;
|
2017-07-13 21:30:28 +00:00
|
|
|
attr.send_cq = rdma_qpair->cq;
|
|
|
|
attr.recv_cq = rdma_qpair->cq;
|
2017-03-15 18:19:08 +00:00
|
|
|
attr.cap.max_send_wr = max_queue_depth * 2; /* SEND, READ, and WRITE operations */
|
2017-03-15 17:47:32 +00:00
|
|
|
attr.cap.max_recv_wr = max_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-10-19 16:15:52 +00:00
|
|
|
rc = rdma_create_qp(id, NULL, &attr);
|
2016-06-07 22:21:21 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("rdma_create_qp failed\n");
|
2016-09-07 17:06:40 +00:00
|
|
|
SPDK_ERRLOG("Errno %d: %s\n", errno, strerror(errno));
|
2016-11-02 03:11:30 +00:00
|
|
|
rdma_destroy_id(id);
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-25 16:20:48 +00:00
|
|
|
return NULL;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-27 16:38:34 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair = &rdma_qpair->qpair;
|
2017-07-24 23:30:07 +00:00
|
|
|
qpair->transport = transport;
|
2017-07-13 21:30:28 +00:00
|
|
|
id->context = qpair;
|
|
|
|
rdma_qpair->cm_id = id;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "New RDMA Connection: %p\n", qpair);
|
2016-07-22 22:30:55 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->reqs = calloc(max_queue_depth, sizeof(*rdma_qpair->reqs));
|
|
|
|
rdma_qpair->recvs = calloc(max_queue_depth, sizeof(*rdma_qpair->recvs));
|
|
|
|
rdma_qpair->cmds = spdk_dma_zmalloc(max_queue_depth * sizeof(*rdma_qpair->cmds),
|
|
|
|
0x1000, NULL);
|
|
|
|
rdma_qpair->cpls = spdk_dma_zmalloc(max_queue_depth * sizeof(*rdma_qpair->cpls),
|
|
|
|
0x1000, NULL);
|
2017-07-28 18:43:18 +00:00
|
|
|
rdma_qpair->bufs = spdk_dma_zmalloc(max_queue_depth * rtransport->in_capsule_data_size,
|
2017-07-13 21:30:28 +00:00
|
|
|
0x1000, NULL);
|
|
|
|
if (!rdma_qpair->reqs || !rdma_qpair->recvs || !rdma_qpair->cmds ||
|
|
|
|
!rdma_qpair->cpls || !rdma_qpair->bufs) {
|
2016-07-25 16:38:02 +00:00
|
|
|
SPDK_ERRLOG("Unable to allocate sufficient memory for RDMA queue.\n");
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-25 16:38:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-22 17:36:02 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cmds_mr = ibv_reg_mr(id->pd, rdma_qpair->cmds,
|
|
|
|
max_queue_depth * sizeof(*rdma_qpair->cmds),
|
|
|
|
IBV_ACCESS_LOCAL_WRITE);
|
|
|
|
rdma_qpair->cpls_mr = ibv_reg_mr(id->pd, rdma_qpair->cpls,
|
|
|
|
max_queue_depth * sizeof(*rdma_qpair->cpls),
|
|
|
|
0);
|
|
|
|
rdma_qpair->bufs_mr = ibv_reg_mr(id->pd, rdma_qpair->bufs,
|
2017-07-28 18:43:18 +00:00
|
|
|
max_queue_depth * rtransport->in_capsule_data_size,
|
2017-07-13 21:30:28 +00:00
|
|
|
IBV_ACCESS_LOCAL_WRITE |
|
|
|
|
IBV_ACCESS_REMOTE_WRITE);
|
|
|
|
if (!rdma_qpair->cmds_mr || !rdma_qpair->cpls_mr || !rdma_qpair->bufs_mr) {
|
2016-07-25 16:38:02 +00:00
|
|
|
SPDK_ERRLOG("Unable to register required memory for RDMA queue.\n");
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-25 16:38:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Command Array: %p Length: %lx LKey: %x\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cmds, max_queue_depth * sizeof(*rdma_qpair->cmds), rdma_qpair->cmds_mr->lkey);
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Completion Array: %p Length: %lx LKey: %x\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cpls, max_queue_depth * sizeof(*rdma_qpair->cpls), rdma_qpair->cpls_mr->lkey);
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "In Capsule Data Array: %p Length: %x LKey: %x\n",
|
2017-07-28 18:43:18 +00:00
|
|
|
rdma_qpair->bufs, max_queue_depth * rtransport->in_capsule_data_size, rdma_qpair->bufs_mr->lkey);
|
2016-07-25 16:38:02 +00:00
|
|
|
|
2016-07-27 22:30:42 +00:00
|
|
|
for (i = 0; i < max_queue_depth; i++) {
|
2017-03-15 19:55:21 +00:00
|
|
|
struct ibv_recv_wr *bad_wr = NULL;
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_recv = &rdma_qpair->recvs[i];
|
2016-07-22 17:36:02 +00:00
|
|
|
|
2017-02-27 02:50:32 +00:00
|
|
|
/* Set up memory to receive commands */
|
2017-07-28 18:43:18 +00:00
|
|
|
rdma_recv->buf = (void *)((uintptr_t)rdma_qpair->bufs + (i * rtransport->in_capsule_data_size));
|
2017-02-27 02:50:32 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_recv->sgl[0].addr = (uintptr_t)&rdma_qpair->cmds[i];
|
|
|
|
rdma_recv->sgl[0].length = sizeof(rdma_qpair->cmds[i]);
|
|
|
|
rdma_recv->sgl[0].lkey = rdma_qpair->cmds_mr->lkey;
|
2017-02-27 02:50:32 +00:00
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
rdma_recv->sgl[1].addr = (uintptr_t)rdma_recv->buf;
|
2017-07-28 18:43:18 +00:00
|
|
|
rdma_recv->sgl[1].length = rtransport->in_capsule_data_size;
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_recv->sgl[1].lkey = rdma_qpair->bufs_mr->lkey;
|
2017-02-27 02:50:32 +00:00
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
rdma_recv->wr.wr_id = (uintptr_t)rdma_recv;
|
|
|
|
rdma_recv->wr.sg_list = rdma_recv->sgl;
|
|
|
|
rdma_recv->wr.num_sge = SPDK_COUNTOF(rdma_recv->sgl);
|
|
|
|
#ifdef DEBUG
|
|
|
|
rdma_recv->in_use = false;
|
|
|
|
#endif
|
2017-02-27 02:50:32 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = ibv_post_recv(rdma_qpair->cm_id->qp, &rdma_recv->wr, &bad_wr);
|
2017-03-15 19:55:21 +00:00
|
|
|
if (rc) {
|
2016-07-25 16:38:02 +00:00
|
|
|
SPDK_ERRLOG("Unable to post capsule for RDMA RECV\n");
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-25 16:20:48 +00:00
|
|
|
return NULL;
|
2016-07-22 17:36:02 +00:00
|
|
|
}
|
2017-03-15 16:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < max_queue_depth; i++) {
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req = &rdma_qpair->reqs[i];
|
2017-03-15 16:28:05 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req->req.qpair = &rdma_qpair->qpair;
|
2017-03-15 16:28:05 +00:00
|
|
|
rdma_req->req.cmd = NULL;
|
2017-02-27 01:32:00 +00:00
|
|
|
|
|
|
|
/* Set up memory to send responses */
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req->req.rsp = &rdma_qpair->cpls[i];
|
2017-02-27 01:32:00 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req->rsp.sgl[0].addr = (uintptr_t)&rdma_qpair->cpls[i];
|
|
|
|
rdma_req->rsp.sgl[0].length = sizeof(rdma_qpair->cpls[i]);
|
|
|
|
rdma_req->rsp.sgl[0].lkey = rdma_qpair->cpls_mr->lkey;
|
2017-02-27 01:32:00 +00:00
|
|
|
|
|
|
|
rdma_req->rsp.wr.wr_id = (uintptr_t)rdma_req;
|
|
|
|
rdma_req->rsp.wr.next = NULL;
|
|
|
|
rdma_req->rsp.wr.opcode = IBV_WR_SEND;
|
|
|
|
rdma_req->rsp.wr.send_flags = IBV_SEND_SIGNALED;
|
|
|
|
rdma_req->rsp.wr.sg_list = rdma_req->rsp.sgl;
|
2017-03-13 22:14:12 +00:00
|
|
|
rdma_req->rsp.wr.num_sge = SPDK_COUNTOF(rdma_req->rsp.sgl);
|
2017-02-27 02:25:01 +00:00
|
|
|
|
|
|
|
/* Set up memory for data buffers */
|
|
|
|
rdma_req->data.wr.wr_id = (uint64_t)rdma_req;
|
|
|
|
rdma_req->data.wr.next = NULL;
|
|
|
|
rdma_req->data.wr.send_flags = IBV_SEND_SIGNALED;
|
|
|
|
rdma_req->data.wr.sg_list = rdma_req->data.sgl;
|
2017-03-13 22:14:12 +00:00
|
|
|
rdma_req->data.wr.num_sge = SPDK_COUNTOF(rdma_req->data.sgl);
|
2017-03-15 16:28:05 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->free_queue, rdma_req, link);
|
2016-07-22 17:36:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
return rdma_qpair;
|
2016-07-22 16:59:10 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 22:25:23 +00:00
|
|
|
static int
|
2017-03-15 18:19:08 +00:00
|
|
|
request_transfer_in(struct spdk_nvmf_request *req)
|
2016-06-24 23:39:53 +00:00
|
|
|
{
|
2017-03-15 20:55:29 +00:00
|
|
|
int rc;
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
2017-03-15 20:55:29 +00:00
|
|
|
struct ibv_send_wr *bad_wr = NULL;
|
2016-06-24 23:39:53 +00:00
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
qpair = req->qpair;
|
|
|
|
rdma_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_rdma_request, req);
|
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
assert(req->xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER);
|
2016-07-27 17:11:28 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_rdma_rw_depth++;
|
2017-03-15 18:19:08 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA READ POSTED. Request: %p Connection: %p\n", req, qpair);
|
2017-03-15 20:55:29 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_READ_START, 0, 0, (uintptr_t)req, 0);
|
|
|
|
|
|
|
|
rdma_req->data.wr.opcode = IBV_WR_RDMA_READ;
|
2017-03-15 21:30:15 +00:00
|
|
|
rdma_req->data.wr.next = NULL;
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = ibv_post_send(rdma_qpair->cm_id->qp, &rdma_req->data.wr, &bad_wr);
|
2017-03-15 18:19:08 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to transfer data from host to target\n");
|
|
|
|
return -1;
|
2016-07-27 22:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-06-24 23:39:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 23:54:37 +00:00
|
|
|
static int
|
2017-03-15 18:19:08 +00:00
|
|
|
request_transfer_out(struct spdk_nvmf_request *req)
|
2016-06-28 17:57:14 +00:00
|
|
|
{
|
2017-03-15 18:19:08 +00:00
|
|
|
int rc;
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
|
|
|
struct spdk_nvme_cpl *rsp;
|
2017-03-15 20:55:29 +00:00
|
|
|
struct ibv_recv_wr *bad_recv_wr = NULL;
|
2017-03-15 21:30:15 +00:00
|
|
|
struct ibv_send_wr *send_wr, *bad_send_wr = NULL;
|
2016-07-27 17:11:28 +00:00
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
qpair = req->qpair;
|
|
|
|
rsp = &req->rsp->nvme_cpl;
|
|
|
|
rdma_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_rdma_request, req);
|
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
|
|
|
|
2016-07-27 17:11:28 +00:00
|
|
|
/* Advance our sq_head pointer */
|
2017-07-13 21:30:28 +00:00
|
|
|
if (qpair->sq_head == qpair->sq_head_max) {
|
|
|
|
qpair->sq_head = 0;
|
2016-08-05 22:06:05 +00:00
|
|
|
} else {
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair->sq_head++;
|
2016-07-27 17:11:28 +00:00
|
|
|
}
|
2017-07-13 21:30:28 +00:00
|
|
|
rsp->sqhd = qpair->sq_head;
|
2016-07-22 22:42:24 +00:00
|
|
|
|
2016-07-27 17:11:28 +00:00
|
|
|
/* Post the capsule to the recv buffer */
|
2017-03-15 16:28:05 +00:00
|
|
|
assert(rdma_req->recv != NULL);
|
|
|
|
#ifdef DEBUG
|
|
|
|
assert(rdma_req->recv->in_use == true);
|
|
|
|
rdma_req->recv->in_use = false;
|
|
|
|
#endif
|
2017-03-15 19:55:21 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA RECV POSTED. Recv: %p Connection: %p\n", rdma_req->recv,
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair);
|
|
|
|
rc = ibv_post_recv(rdma_qpair->cm_id->qp, &rdma_req->recv->wr, &bad_recv_wr);
|
2016-07-27 17:11:28 +00:00
|
|
|
if (rc) {
|
2016-06-28 17:57:14 +00:00
|
|
|
SPDK_ERRLOG("Unable to re-post rx descriptor\n");
|
2016-07-27 17:11:28 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2017-03-15 16:28:05 +00:00
|
|
|
rdma_req->recv = NULL;
|
2016-07-27 17:11:28 +00:00
|
|
|
|
2017-03-15 21:30:15 +00:00
|
|
|
/* Build the response which consists of an optional
|
|
|
|
* RDMA WRITE to transfer data, plus an RDMA SEND
|
|
|
|
* containing the response.
|
|
|
|
*/
|
|
|
|
send_wr = &rdma_req->rsp.wr;
|
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
if (rsp->status.sc == SPDK_NVME_SC_SUCCESS &&
|
|
|
|
req->xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
2017-07-13 21:30:28 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA WRITE POSTED. Request: %p Connection: %p\n", req, qpair);
|
2017-03-15 20:55:29 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_WRITE_START, 0, 0, (uintptr_t)req, 0);
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_rdma_rw_depth++;
|
2017-03-15 20:55:29 +00:00
|
|
|
rdma_req->data.wr.opcode = IBV_WR_RDMA_WRITE;
|
2017-03-15 21:30:15 +00:00
|
|
|
|
|
|
|
rdma_req->data.wr.next = send_wr;
|
|
|
|
send_wr = &rdma_req->data.wr;
|
2017-03-15 18:19:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA SEND POSTED. Request: %p Connection: %p\n", req, qpair);
|
2017-03-15 20:58:16 +00:00
|
|
|
spdk_trace_record(TRACE_NVMF_IO_COMPLETE, 0, 0, (uintptr_t)req, 0);
|
2017-03-15 21:30:15 +00:00
|
|
|
|
|
|
|
/* Send the completion */
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = ibv_post_send(rdma_qpair->cm_id->qp, send_wr, &bad_send_wr);
|
2016-07-27 17:11:28 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to send response capsule\n");
|
2016-06-28 17:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 17:11:28 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_rdma_request_transfer_data(struct spdk_nvmf_request *req)
|
|
|
|
{
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
|
|
|
|
|
|
|
qpair = req->qpair;
|
|
|
|
rdma_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_rdma_request, req);
|
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
2017-03-15 18:19:08 +00:00
|
|
|
|
|
|
|
if (req->xfer == SPDK_NVME_DATA_NONE) {
|
|
|
|
/* If no data transfer, this can bypass the queue */
|
|
|
|
return request_transfer_out(req);
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cur_rdma_rw_depth < rdma_qpair->max_rw_depth) {
|
2017-03-15 18:19:08 +00:00
|
|
|
if (req->xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
|
|
|
return request_transfer_out(req);
|
|
|
|
} else if (req->xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
|
|
|
|
return request_transfer_in(req);
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->pending_rdma_rw_queue, rdma_req, link);
|
2017-03-15 18:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
static int
|
2017-07-24 23:30:07 +00:00
|
|
|
nvmf_rdma_connect(struct spdk_nvmf_transport *transport, struct rdma_cm_event *event)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair = NULL;
|
2016-09-16 22:29:13 +00:00
|
|
|
struct spdk_nvmf_rdma_listen_addr *addr;
|
2016-07-22 16:48:01 +00:00
|
|
|
struct rdma_conn_param *rdma_param = NULL;
|
2016-06-27 22:48:43 +00:00
|
|
|
struct rdma_conn_param ctrlr_event_data;
|
2016-07-22 16:48:01 +00:00
|
|
|
const struct spdk_nvmf_rdma_request_private_data *private_data = NULL;
|
2016-06-27 22:48:43 +00:00
|
|
|
struct spdk_nvmf_rdma_accept_private_data accept_data;
|
2016-06-06 21:44:30 +00:00
|
|
|
uint16_t sts = 0;
|
2016-07-27 22:30:42 +00:00
|
|
|
uint16_t max_queue_depth;
|
|
|
|
uint16_t max_rw_depth;
|
2017-03-03 04:24:16 +00:00
|
|
|
uint32_t subsystem_id = 0;
|
2016-07-22 16:48:01 +00:00
|
|
|
int rc;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
if (event->id == NULL) {
|
|
|
|
SPDK_ERRLOG("connect request: missing cm_id\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
|
2016-07-22 16:43:08 +00:00
|
|
|
if (event->id->verbs == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_ERRLOG("connect request: missing cm_id ibv_context\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
2017-01-13 22:49:36 +00:00
|
|
|
|
|
|
|
rdma_param = &event->param.conn;
|
|
|
|
if (rdma_param->private_data == NULL ||
|
|
|
|
rdma_param->private_data_len < sizeof(struct spdk_nvmf_rdma_request_private_data)) {
|
|
|
|
SPDK_ERRLOG("connect request: no private data provided\n");
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
private_data = rdma_param->private_data;
|
|
|
|
|
2016-07-15 22:35:01 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Connect Recv on fabric intf name %s, dev_name %s\n",
|
2016-07-22 16:43:08 +00:00
|
|
|
event->id->verbs->device->name, event->id->verbs->device->dev_name);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-09-16 22:29:13 +00:00
|
|
|
addr = event->listen_id->context;
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Listen Id was %p with verbs %p. ListenAddr: %p\n",
|
|
|
|
event->listen_id, event->listen_id->verbs, addr);
|
|
|
|
|
2016-07-22 16:48:01 +00:00
|
|
|
/* Figure out the supported queue depth. This is a multi-step process
|
|
|
|
* that takes into account hardware maximums, host provided values,
|
|
|
|
* and our target's internal memory limits */
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Calculating Queue Depth\n");
|
|
|
|
|
|
|
|
/* Start with the maximum queue depth allowed by the target */
|
2017-07-28 18:43:18 +00:00
|
|
|
max_queue_depth = rtransport->max_queue_depth;
|
|
|
|
max_rw_depth = rtransport->max_queue_depth;
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Target Max Queue Depth: %d\n", rtransport->max_queue_depth);
|
2016-07-22 16:48:01 +00:00
|
|
|
|
|
|
|
/* Next check the local NIC's hardware limitations */
|
2016-07-21 22:19:19 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA,
|
|
|
|
"Local NIC Max Send/Recv Queue Depth: %d Max Read/Write Queue Depth: %d\n",
|
2017-08-02 23:00:18 +00:00
|
|
|
addr->device->attr.max_qp_wr, addr->device->attr.max_qp_rd_atom);
|
|
|
|
max_queue_depth = spdk_min(max_queue_depth, addr->device->attr.max_qp_wr);
|
|
|
|
max_rw_depth = spdk_min(max_rw_depth, addr->device->attr.max_qp_rd_atom);
|
2016-07-22 16:48:01 +00:00
|
|
|
|
|
|
|
/* Next check the remote NIC's hardware limitations */
|
2016-07-25 21:36:06 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA,
|
2016-12-15 20:53:11 +00:00
|
|
|
"Host (Initiator) NIC Max Incoming RDMA R/W operations: %d Max Outgoing RDMA R/W operations: %d\n",
|
2016-07-25 21:36:06 +00:00
|
|
|
rdma_param->initiator_depth, rdma_param->responder_resources);
|
2016-10-20 20:36:38 +00:00
|
|
|
if (rdma_param->initiator_depth > 0) {
|
2017-02-02 17:07:12 +00:00
|
|
|
max_rw_depth = spdk_min(max_rw_depth, rdma_param->initiator_depth);
|
2016-10-20 20:36:38 +00:00
|
|
|
}
|
2016-07-22 16:48:01 +00:00
|
|
|
|
|
|
|
/* Finally check for the host software requested values, which are
|
|
|
|
* optional. */
|
|
|
|
if (rdma_param->private_data != NULL &&
|
|
|
|
rdma_param->private_data_len >= sizeof(struct spdk_nvmf_rdma_request_private_data)) {
|
2016-07-21 22:19:19 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Host Receive Queue Size: %d\n", private_data->hrqsize);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Host Send Queue Size: %d\n", private_data->hsqsize);
|
2017-02-02 17:07:12 +00:00
|
|
|
max_queue_depth = spdk_min(max_queue_depth, private_data->hrqsize);
|
2017-03-08 22:10:21 +00:00
|
|
|
max_queue_depth = spdk_min(max_queue_depth, private_data->hsqsize + 1);
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-22 16:48:01 +00:00
|
|
|
|
2016-07-25 21:36:06 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Final Negotiated Queue Depth: %d R/W Depth: %d\n",
|
2016-07-27 22:30:42 +00:00
|
|
|
max_queue_depth, max_rw_depth);
|
2016-07-25 21:36:06 +00:00
|
|
|
|
2016-07-22 16:59:10 +00:00
|
|
|
/* Init the NVMf rdma transport connection */
|
2017-07-24 23:30:07 +00:00
|
|
|
rdma_qpair = spdk_nvmf_rdma_qpair_create(transport, event->id, addr->comp_channel, max_queue_depth,
|
2017-07-13 21:30:28 +00:00
|
|
|
max_rw_depth, subsystem_id);
|
|
|
|
if (rdma_qpair == NULL) {
|
2016-07-22 16:59:10 +00:00
|
|
|
SPDK_ERRLOG("Error on nvmf connection creation\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
|
|
|
accept_data.recfmt = 0;
|
2016-07-27 22:30:42 +00:00
|
|
|
accept_data.crqsize = max_queue_depth;
|
2016-07-22 16:48:01 +00:00
|
|
|
ctrlr_event_data = *rdma_param;
|
2016-06-27 22:48:43 +00:00
|
|
|
ctrlr_event_data.private_data = &accept_data;
|
|
|
|
ctrlr_event_data.private_data_len = sizeof(accept_data);
|
2016-07-22 16:43:08 +00:00
|
|
|
if (event->id->ps == RDMA_PS_TCP) {
|
2016-06-27 22:48:43 +00:00
|
|
|
ctrlr_event_data.responder_resources = 0; /* We accept 0 reads from the host */
|
2016-07-27 22:30:42 +00:00
|
|
|
ctrlr_event_data.initiator_depth = max_rw_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-10-13 04:36:04 +00:00
|
|
|
goto err2;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-15 22:35:01 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Sent back the accept\n");
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-10-13 04:36:04 +00:00
|
|
|
/* Add this RDMA connection to the global list until a CONNECT capsule
|
|
|
|
* is received. */
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_pending_conns, rdma_qpair, link);
|
2016-10-13 04:36:04 +00:00
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-10-13 04:36:04 +00:00
|
|
|
err2:
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-10-13 04:36:04 +00:00
|
|
|
|
2016-06-27 22:48:43 +00:00
|
|
|
err1: {
|
|
|
|
struct spdk_nvmf_rdma_reject_private_data rej_data;
|
|
|
|
|
|
|
|
rej_data.status.sc = sts;
|
2016-07-22 16:43:08 +00:00
|
|
|
rdma_reject(event->id, &ctrlr_event_data, sizeof(rej_data));
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
err0:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-07-15 18:34:11 +00:00
|
|
|
nvmf_rdma_disconnect(struct rdma_cm_event *evt)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_qpair *qpair;
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr;
|
2016-08-25 22:00:50 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-15 18:34:11 +00:00
|
|
|
if (evt->id == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_ERRLOG("disconnect request: missing cm_id\n");
|
2016-07-15 18:34:11 +00:00
|
|
|
return -1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair = evt->id->context;
|
|
|
|
if (qpair == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_ERRLOG("disconnect request: no active connection\n");
|
2016-07-15 18:34:11 +00:00
|
|
|
return -1;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2016-07-19 08:20:39 +00:00
|
|
|
/* ack the disconnect event before rdma_destroy_id */
|
|
|
|
rdma_ack_cm_event(evt);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
2016-07-15 18:34:11 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
ctrlr = qpair->ctrlr;
|
2017-07-13 21:18:08 +00:00
|
|
|
if (ctrlr == NULL) {
|
2017-07-13 21:30:28 +00:00
|
|
|
/* No ctrlr has been established yet. That means the qpair
|
2016-07-15 18:34:11 +00:00
|
|
|
* must be in the pending connections list. Remove it. */
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&g_pending_conns, rdma_qpair, link);
|
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-15 18:34:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
subsystem = ctrlr->subsys;
|
2016-08-25 22:00:50 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
subsystem->disconnect_cb(subsystem->cb_ctx, qpair);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-11 23:59:58 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
static const char *CM_EVENT_STR[] = {
|
2016-06-06 21:44:30 +00:00
|
|
|
"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"
|
|
|
|
};
|
2016-07-11 23:59:58 +00:00
|
|
|
#endif /* DEBUG */
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
typedef enum _spdk_nvmf_request_prep_type {
|
|
|
|
SPDK_NVMF_REQUEST_PREP_ERROR = -1,
|
|
|
|
SPDK_NVMF_REQUEST_PREP_READY = 0,
|
|
|
|
SPDK_NVMF_REQUEST_PREP_PENDING_BUFFER = 1,
|
|
|
|
SPDK_NVMF_REQUEST_PREP_PENDING_DATA = 2,
|
|
|
|
} spdk_nvmf_request_prep_type;
|
|
|
|
|
|
|
|
static spdk_nvmf_request_prep_type
|
2016-07-25 23:26:08 +00:00
|
|
|
spdk_nvmf_request_prep_data(struct spdk_nvmf_request *req)
|
2016-07-22 20:53:00 +00:00
|
|
|
{
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
|
|
|
struct spdk_nvme_cpl *rsp;
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
|
|
|
struct spdk_nvme_sgl_descriptor *sgl;
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2016-07-22 20:53:00 +00:00
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
cmd = &req->cmd->nvme_cmd;
|
|
|
|
rsp = &req->rsp->nvme_cpl;
|
|
|
|
rdma_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_rdma_request, req);
|
|
|
|
|
2016-07-22 20:53:00 +00:00
|
|
|
req->length = 0;
|
|
|
|
req->data = NULL;
|
|
|
|
|
|
|
|
if (cmd->opc == SPDK_NVME_OPC_FABRIC) {
|
2016-07-28 17:23:52 +00:00
|
|
|
req->xfer = spdk_nvme_opc_get_data_transfer(req->cmd->nvmf_cmd.fctype);
|
2016-07-22 20:53:00 +00:00
|
|
|
} else {
|
2016-07-28 17:23:52 +00:00
|
|
|
req->xfer = spdk_nvme_opc_get_data_transfer(cmd->opc);
|
2017-07-13 21:30:28 +00:00
|
|
|
if ((req->qpair->type == QPAIR_TYPE_AQ) &&
|
2017-02-22 21:54:30 +00:00
|
|
|
((cmd->opc == SPDK_NVME_OPC_GET_FEATURES) ||
|
|
|
|
(cmd->opc == SPDK_NVME_OPC_SET_FEATURES))) {
|
|
|
|
switch (cmd->cdw10 & 0xff) {
|
|
|
|
case SPDK_NVME_FEAT_LBA_RANGE_TYPE:
|
|
|
|
case SPDK_NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION:
|
|
|
|
case SPDK_NVME_FEAT_HOST_IDENTIFIER:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
req->xfer = SPDK_NVME_DATA_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (req->xfer == SPDK_NVME_DATA_NONE) {
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_READY;
|
|
|
|
}
|
2016-07-22 20:53:00 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(req->qpair->transport, struct spdk_nvmf_rdma_transport, transport);
|
2016-07-28 17:23:52 +00:00
|
|
|
sgl = &cmd->dptr.sgl1;
|
2016-07-22 20:53:00 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (sgl->generic.type == SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK &&
|
|
|
|
(sgl->keyed.subtype == SPDK_NVME_SGL_SUBTYPE_ADDRESS ||
|
|
|
|
sgl->keyed.subtype == SPDK_NVME_SGL_SUBTYPE_INVALIDATE_KEY)) {
|
2017-07-28 18:43:18 +00:00
|
|
|
if (sgl->keyed.length > rtransport->max_io_size) {
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_ERRLOG("SGL length 0x%x exceeds max io size 0x%x\n",
|
2017-07-28 18:43:18 +00:00
|
|
|
sgl->keyed.length, rtransport->max_io_size);
|
2016-07-28 17:23:52 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_ERROR;
|
|
|
|
}
|
2016-07-22 20:53:00 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (sgl->keyed.length == 0) {
|
|
|
|
req->xfer = SPDK_NVME_DATA_NONE;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->length = sgl->keyed.length;
|
2017-03-15 20:13:32 +00:00
|
|
|
rdma_req->data.sgl[0].length = sgl->keyed.length;
|
|
|
|
rdma_req->data.wr.wr.rdma.rkey = sgl->keyed.key;
|
|
|
|
rdma_req->data.wr.wr.rdma.remote_addr = sgl->address;
|
2016-07-28 17:23:52 +00:00
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
if (!req->qpair->ctrlr) {
|
2017-07-13 21:18:08 +00:00
|
|
|
/* The only time a connection won't have a ctrlr
|
2017-03-15 22:06:27 +00:00
|
|
|
* is when this is the CONNECT request.
|
|
|
|
*/
|
|
|
|
assert(cmd->opc == SPDK_NVME_OPC_FABRIC);
|
|
|
|
assert(req->xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER);
|
2017-07-28 18:43:18 +00:00
|
|
|
assert(req->length <= rtransport->in_capsule_data_size);
|
2017-03-15 22:06:27 +00:00
|
|
|
|
|
|
|
/* Use the in capsule data buffer, even though this isn't in capsule data. */
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Request using in capsule buffer for non-capsule data\n");
|
|
|
|
req->data = rdma_req->recv->buf;
|
2017-08-10 21:32:39 +00:00
|
|
|
rdma_req->data.sgl[0].lkey = SPDK_CONTAINEROF(req->qpair, struct spdk_nvmf_rdma_qpair,
|
|
|
|
qpair)->bufs_mr->lkey;
|
2017-03-15 22:06:27 +00:00
|
|
|
rdma_req->data_from_pool = false;
|
|
|
|
} else {
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = SPDK_CONTAINEROF(req->qpair->ctrlr->group, struct spdk_nvmf_rdma_poll_group, group);
|
|
|
|
req->data = SLIST_FIRST(&rgroup->data_buf_pool);
|
|
|
|
rdma_req->data.sgl[0].lkey = rgroup->buf_mr->lkey;
|
2017-03-15 22:06:27 +00:00
|
|
|
rdma_req->data_from_pool = true;
|
2016-07-28 17:23:52 +00:00
|
|
|
if (!req->data) {
|
|
|
|
/* No available buffers. Queue this request up. */
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "No available large data buffers. Queueing request %p\n", req);
|
2017-03-15 20:13:32 +00:00
|
|
|
/* This will get assigned when we actually obtain a buffer */
|
|
|
|
rdma_req->data.sgl[0].addr = (uintptr_t)NULL;
|
2016-07-28 17:23:52 +00:00
|
|
|
return SPDK_NVMF_REQUEST_PREP_PENDING_BUFFER;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Request %p took buffer from central pool\n", req);
|
2017-07-28 18:21:45 +00:00
|
|
|
SLIST_REMOVE_HEAD(&rgroup->data_buf_pool, link);
|
2016-07-28 17:23:52 +00:00
|
|
|
}
|
2017-03-15 20:13:32 +00:00
|
|
|
|
|
|
|
rdma_req->data.sgl[0].addr = (uintptr_t)req->data;
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (req->xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_PENDING_DATA;
|
|
|
|
} else {
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_READY;
|
|
|
|
}
|
|
|
|
} else if (sgl->generic.type == SPDK_NVME_SGL_TYPE_DATA_BLOCK &&
|
|
|
|
sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_OFFSET) {
|
|
|
|
uint64_t offset = sgl->address;
|
2017-07-28 18:43:18 +00:00
|
|
|
uint32_t max_len = rtransport->in_capsule_data_size;
|
2016-07-28 17:23:52 +00:00
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "In-capsule data: offset 0x%" PRIx64 ", length 0x%x\n",
|
|
|
|
offset, sgl->unkeyed.length);
|
|
|
|
|
|
|
|
if (offset > max_len) {
|
|
|
|
SPDK_ERRLOG("In-capsule offset 0x%" PRIx64 " exceeds capsule length 0x%x\n",
|
|
|
|
offset, max_len);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_SGL_OFFSET;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_ERROR;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
2016-07-28 17:23:52 +00:00
|
|
|
max_len -= (uint32_t)offset;
|
2016-07-22 20:53:00 +00:00
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (sgl->unkeyed.length > max_len) {
|
|
|
|
SPDK_ERRLOG("In-capsule data length 0x%x exceeds capsule length 0x%x\n",
|
|
|
|
sgl->unkeyed.length, max_len);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_ERROR;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
if (sgl->unkeyed.length == 0) {
|
|
|
|
req->xfer = SPDK_NVME_DATA_NONE;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_READY;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
req->data = rdma_req->recv->buf + offset;
|
2017-03-15 22:06:27 +00:00
|
|
|
rdma_req->data_from_pool = false;
|
2016-07-28 17:23:52 +00:00
|
|
|
req->length = sgl->unkeyed.length;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_READY;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
SPDK_ERRLOG("Invalid NVMf I/O Command SGL: Type 0x%x, Subtype 0x%x\n",
|
|
|
|
sgl->generic.type, sgl->generic.subtype);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_SGL_DESCRIPTOR_TYPE_INVALID;
|
|
|
|
return SPDK_NVMF_REQUEST_PREP_ERROR;
|
2016-07-22 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 17:17:14 +00:00
|
|
|
static int
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_handle_pending_rdma_rw(struct spdk_nvmf_qpair *qpair)
|
2016-10-19 17:17:14 +00:00
|
|
|
{
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req, *tmp;
|
|
|
|
int rc;
|
|
|
|
int count = 0;
|
2017-08-10 21:32:39 +00:00
|
|
|
|
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
2016-10-19 17:17:14 +00:00
|
|
|
|
|
|
|
/* First, try to assign free data buffers to requests that need one */
|
2017-07-13 21:30:28 +00:00
|
|
|
if (qpair->ctrlr) {
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = SPDK_CONTAINEROF(qpair->ctrlr->group, struct spdk_nvmf_rdma_poll_group, group);
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rdma_qpair->pending_data_buf_queue, link, tmp) {
|
2016-10-19 17:17:14 +00:00
|
|
|
assert(rdma_req->req.data == NULL);
|
2017-07-28 18:21:45 +00:00
|
|
|
rdma_req->req.data = SLIST_FIRST(&rgroup->data_buf_pool);
|
2016-10-19 17:17:14 +00:00
|
|
|
if (!rdma_req->req.data) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 18:21:45 +00:00
|
|
|
SLIST_REMOVE_HEAD(&rgroup->data_buf_pool, link);
|
2017-03-15 20:13:32 +00:00
|
|
|
rdma_req->data.sgl[0].addr = (uintptr_t)rdma_req->req.data;
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&rdma_qpair->pending_data_buf_queue, rdma_req, link);
|
2016-10-19 17:17:14 +00:00
|
|
|
if (rdma_req->req.xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->pending_rdma_rw_queue, rdma_req, link);
|
2016-10-19 17:17:14 +00:00
|
|
|
} else {
|
|
|
|
rc = spdk_nvmf_request_exec(&rdma_req->req);
|
|
|
|
if (rc < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to initiate RDMA Reads or Writes on requests that have data buffers */
|
2017-07-13 21:30:28 +00:00
|
|
|
while (rdma_qpair->cur_rdma_rw_depth < rdma_qpair->max_rw_depth) {
|
|
|
|
rdma_req = TAILQ_FIRST(&rdma_qpair->pending_rdma_rw_queue);
|
2017-05-05 06:59:58 +00:00
|
|
|
if (spdk_unlikely(!rdma_req)) {
|
2016-10-19 17:17:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&rdma_qpair->pending_rdma_rw_queue, rdma_req, link);
|
2016-10-19 17:17:14 +00:00
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Submitting previously queued for RDMA R/W request %p\n", rdma_req);
|
|
|
|
|
|
|
|
rc = spdk_nvmf_rdma_request_transfer_data(&rdma_req->req);
|
|
|
|
if (rc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Public API callbacks begin here */
|
|
|
|
|
2017-07-24 23:30:07 +00:00
|
|
|
static struct spdk_nvmf_transport *
|
|
|
|
spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt)
|
2016-10-19 17:17:14 +00:00
|
|
|
{
|
|
|
|
int rc;
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_device *device, *tmp;
|
|
|
|
struct ibv_context **contexts;
|
|
|
|
uint32_t i;
|
2017-07-24 23:30:07 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = calloc(1, sizeof(*rtransport));
|
|
|
|
if (!rtransport) {
|
2017-07-24 23:30:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_init(&rtransport->lock, NULL);
|
2017-08-02 23:00:18 +00:00
|
|
|
TAILQ_INIT(&rtransport->devices);
|
2017-07-28 18:43:18 +00:00
|
|
|
TAILQ_INIT(&rtransport->listen_addrs);
|
|
|
|
|
|
|
|
rtransport->transport.tgt = tgt;
|
|
|
|
rtransport->transport.ops = &spdk_nvmf_transport_rdma;
|
2016-10-19 17:17:14 +00:00
|
|
|
|
|
|
|
SPDK_NOTICELOG("*** RDMA Transport Init ***\n");
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport->max_queue_depth = tgt->max_queue_depth;
|
|
|
|
rtransport->max_io_size = tgt->max_io_size;
|
|
|
|
rtransport->in_capsule_data_size = tgt->in_capsule_data_size;
|
2016-10-19 17:17:14 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport->event_channel = rdma_create_event_channel();
|
|
|
|
if (rtransport->event_channel == NULL) {
|
2016-11-02 03:11:30 +00:00
|
|
|
SPDK_ERRLOG("rdma_create_event_channel() failed, %s\n", strerror(errno));
|
2017-07-28 18:43:18 +00:00
|
|
|
free(rtransport);
|
2017-07-24 23:30:07 +00:00
|
|
|
return NULL;
|
2016-10-19 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rc = fcntl(rtransport->event_channel->fd, F_SETFL, O_NONBLOCK);
|
2016-10-19 17:17:14 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("fcntl to set fd to non-blocking failed\n");
|
2017-07-28 18:43:18 +00:00
|
|
|
free(rtransport);
|
2017-07-24 23:30:07 +00:00
|
|
|
return NULL;
|
2016-10-19 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
contexts = rdma_get_devices(NULL);
|
|
|
|
i = 0;
|
|
|
|
rc = 0;
|
|
|
|
while (contexts[i] != NULL) {
|
|
|
|
device = calloc(1, sizeof(*device));
|
|
|
|
if (!device) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate memory for RDMA devices.\n");
|
|
|
|
rc = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
device->context = contexts[i];
|
|
|
|
rc = ibv_query_device(device->context, &device->attr);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to query RDMA device attributes.\n");
|
|
|
|
free(device);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&rtransport->devices, device, link);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
TAILQ_FOREACH_SAFE(device, &rtransport->devices, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&rtransport->devices, device, link);
|
|
|
|
free(device);
|
|
|
|
}
|
|
|
|
rdma_destroy_event_channel(rtransport->event_channel);
|
|
|
|
free(rtransport);
|
|
|
|
rdma_free_devices(contexts);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdma_free_devices(contexts);
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
return &rtransport->transport;
|
2016-10-19 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-24 23:30:07 +00:00
|
|
|
spdk_nvmf_rdma_destroy(struct spdk_nvmf_transport *transport)
|
2017-01-25 11:51:35 +00:00
|
|
|
{
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
|
|
|
struct spdk_nvmf_rdma_device *device, *device_tmp;
|
2017-02-06 05:25:56 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
|
|
|
assert(TAILQ_EMPTY(&rtransport->listen_addrs));
|
|
|
|
if (rtransport->event_channel != NULL) {
|
|
|
|
rdma_destroy_event_channel(rtransport->event_channel);
|
2017-01-25 11:51:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
TAILQ_FOREACH_SAFE(device, &rtransport->devices, link, device_tmp) {
|
|
|
|
TAILQ_REMOVE(&rtransport->devices, device, link);
|
|
|
|
free(device);
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
free(rtransport);
|
2017-07-24 23:30:07 +00:00
|
|
|
|
2017-01-25 11:51:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-28 17:40:40 +00:00
|
|
|
spdk_nvmf_rdma_listen(struct spdk_nvmf_transport *transport,
|
|
|
|
const struct spdk_nvme_transport_id *trid)
|
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_device *device;
|
2017-07-28 17:40:40 +00:00
|
|
|
struct spdk_nvmf_rdma_listen_addr *addr_tmp, *addr;
|
|
|
|
struct sockaddr_in saddr;
|
|
|
|
int rc;
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
2017-07-28 17:40:40 +00:00
|
|
|
addr = calloc(1, sizeof(*addr));
|
|
|
|
if (!addr) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Selectively copy the trid. Things like NQN don't matter here - that
|
|
|
|
* mapping is enforced elsewhere.
|
|
|
|
*/
|
|
|
|
addr->trid.trtype = SPDK_NVME_TRANSPORT_RDMA;
|
|
|
|
addr->trid.adrfam = trid->adrfam;
|
|
|
|
snprintf(addr->trid.traddr, sizeof(addr->trid.traddr), "%s", trid->traddr);
|
|
|
|
snprintf(addr->trid.trsvcid, sizeof(addr->trid.trsvcid), "%s", trid->trsvcid);
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_lock(&rtransport->lock);
|
|
|
|
assert(rtransport->event_channel != NULL);
|
|
|
|
TAILQ_FOREACH(addr_tmp, &rtransport->listen_addrs, link) {
|
2017-07-28 17:40:40 +00:00
|
|
|
if (spdk_nvme_transport_id_compare(&addr_tmp->trid, &addr->trid) == 0) {
|
|
|
|
addr_tmp->ref++;
|
|
|
|
free(addr);
|
|
|
|
/* Already listening at this address */
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rc = rdma_create_id(rtransport->event_channel, &addr->id, addr, RDMA_PS_TCP);
|
2017-07-28 17:40:40 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_create_id() failed\n");
|
|
|
|
free(addr);
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&saddr, 0, sizeof(saddr));
|
|
|
|
saddr.sin_family = AF_INET;
|
|
|
|
saddr.sin_addr.s_addr = inet_addr(addr->trid.traddr);
|
|
|
|
saddr.sin_port = htons((uint16_t)strtoul(addr->trid.trsvcid, NULL, 10));
|
|
|
|
rc = rdma_bind_addr(addr->id, (struct sockaddr *)&saddr);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_bind_addr() failed\n");
|
|
|
|
rdma_destroy_id(addr->id);
|
|
|
|
free(addr);
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr->comp_channel = ibv_create_comp_channel(addr->id->verbs);
|
|
|
|
if (!addr->comp_channel) {
|
|
|
|
SPDK_ERRLOG("Failed to create completion channel\n");
|
|
|
|
rdma_destroy_id(addr->id);
|
|
|
|
free(addr);
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "For listen id %p with context %p, created completion channel %p\n",
|
|
|
|
addr->id, addr->id->verbs, addr->comp_channel);
|
|
|
|
|
|
|
|
rc = fcntl(addr->comp_channel->fd, F_SETFL, O_NONBLOCK);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("fcntl to set comp channel to non-blocking failed\n");
|
|
|
|
ibv_destroy_comp_channel(addr->comp_channel);
|
|
|
|
rdma_destroy_id(addr->id);
|
|
|
|
free(addr);
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = rdma_listen(addr->id, 10); /* 10 = backlog */
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("rdma_listen() failed\n");
|
|
|
|
ibv_destroy_comp_channel(addr->comp_channel);
|
|
|
|
rdma_destroy_id(addr->id);
|
|
|
|
free(addr);
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
TAILQ_FOREACH(device, &rtransport->devices, link) {
|
|
|
|
if (device->context == addr->id->verbs) {
|
|
|
|
addr->device = device;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!addr->device) {
|
|
|
|
SPDK_ERRLOG("Accepted a connection with verbs %p, but unable to find a corresponding device.\n",
|
|
|
|
addr->id->verbs);
|
|
|
|
ibv_destroy_comp_channel(addr->comp_channel);
|
|
|
|
rdma_destroy_id(addr->id);
|
|
|
|
free(addr);
|
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:40:40 +00:00
|
|
|
SPDK_NOTICELOG("*** NVMf Target Listening on %s port %d ***\n",
|
|
|
|
addr->trid.traddr, ntohs(rdma_get_src_port(addr->id)));
|
|
|
|
|
|
|
|
addr->ref = 1;
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rtransport->listen_addrs, addr, link);
|
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2017-07-28 17:40:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_rdma_stop_listen(struct spdk_nvmf_transport *transport,
|
|
|
|
const struct spdk_nvme_transport_id *_trid)
|
2016-10-19 17:17:14 +00:00
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2016-10-19 17:17:14 +00:00
|
|
|
struct spdk_nvmf_rdma_listen_addr *addr, *tmp;
|
2017-07-28 17:40:40 +00:00
|
|
|
struct spdk_nvme_transport_id trid = {};
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
2017-07-28 17:40:40 +00:00
|
|
|
/* Selectively copy the trid. Things like NQN don't matter here - that
|
|
|
|
* mapping is enforced elsewhere.
|
|
|
|
*/
|
|
|
|
trid.trtype = SPDK_NVME_TRANSPORT_RDMA;
|
|
|
|
trid.adrfam = _trid->adrfam;
|
|
|
|
snprintf(trid.traddr, sizeof(addr->trid.traddr), "%s", _trid->traddr);
|
|
|
|
snprintf(trid.trsvcid, sizeof(addr->trid.trsvcid), "%s", _trid->trsvcid);
|
2016-10-19 17:17:14 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_lock(&rtransport->lock);
|
|
|
|
TAILQ_FOREACH_SAFE(addr, &rtransport->listen_addrs, link, tmp) {
|
2017-07-28 17:40:40 +00:00
|
|
|
if (spdk_nvme_transport_id_compare(&addr->trid, &trid) == 0) {
|
2017-01-25 11:51:35 +00:00
|
|
|
assert(addr->ref > 0);
|
|
|
|
addr->ref--;
|
2017-07-28 17:40:40 +00:00
|
|
|
if (addr->ref == 0) {
|
2017-07-28 18:43:18 +00:00
|
|
|
TAILQ_REMOVE(&rtransport->listen_addrs, addr, link);
|
2017-01-25 11:51:35 +00:00
|
|
|
ibv_destroy_comp_channel(addr->comp_channel);
|
|
|
|
rdma_destroy_id(addr->id);
|
2017-07-28 17:40:40 +00:00
|
|
|
free(addr);
|
2017-01-25 11:51:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-19 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
pthread_mutex_unlock(&rtransport->lock);
|
2016-10-19 17:17:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_poll(struct spdk_nvmf_qpair *qpair);
|
2016-07-22 22:15:24 +00:00
|
|
|
|
2017-02-15 16:23:46 +00:00
|
|
|
static void
|
2017-07-28 17:40:40 +00:00
|
|
|
spdk_nvmf_rdma_accept(struct spdk_nvmf_transport *transport)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2016-06-06 21:44:30 +00:00
|
|
|
struct rdma_cm_event *event;
|
|
|
|
int rc;
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair, *tmp;
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
|
|
|
if (rtransport->event_channel == NULL) {
|
2016-06-06 21:44:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-14 20:52:03 +00:00
|
|
|
/* Process pending connections for incoming capsules. The only capsule
|
|
|
|
* this should ever find is a CONNECT request. */
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rdma_qpair, &g_pending_conns, link, tmp) {
|
|
|
|
rc = spdk_nvmf_rdma_poll(&rdma_qpair->qpair);
|
2016-07-22 22:15:24 +00:00
|
|
|
if (rc < 0) {
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&g_pending_conns, rdma_qpair, link);
|
|
|
|
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
2016-07-22 22:15:24 +00:00
|
|
|
} else if (rc > 0) {
|
|
|
|
/* At least one request was processed which is assumed to be
|
|
|
|
* a CONNECT. Remove this connection from our list. */
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&g_pending_conns, rdma_qpair, link);
|
2016-07-14 20:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
while (1) {
|
2017-07-28 18:43:18 +00:00
|
|
|
rc = rdma_get_cm_event(rtransport->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:
|
2017-07-24 23:30:07 +00:00
|
|
|
rc = nvmf_rdma_connect(transport, event);
|
2016-06-24 18:55:06 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-07-19 08:20:39 +00:00
|
|
|
continue;
|
2016-06-24 18:55:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 17:17:14 +00:00
|
|
|
static void
|
2017-07-24 23:30:07 +00:00
|
|
|
spdk_nvmf_rdma_discover(struct spdk_nvmf_transport *transport,
|
|
|
|
struct spdk_nvmf_listen_addr *listen_addr,
|
2016-10-19 17:17:14 +00:00
|
|
|
struct spdk_nvmf_discovery_log_page_entry *entry)
|
|
|
|
{
|
|
|
|
entry->trtype = SPDK_NVMF_TRTYPE_RDMA;
|
2017-07-13 20:13:05 +00:00
|
|
|
entry->adrfam = listen_addr->trid.adrfam;
|
2016-10-19 17:17:14 +00:00
|
|
|
entry->treq.secure_channel = SPDK_NVMF_TREQ_SECURE_CHANNEL_NOT_SPECIFIED;
|
|
|
|
|
2017-07-13 20:13:05 +00:00
|
|
|
spdk_strcpy_pad(entry->trsvcid, listen_addr->trid.trsvcid, sizeof(entry->trsvcid), ' ');
|
|
|
|
spdk_strcpy_pad(entry->traddr, listen_addr->trid.traddr, sizeof(entry->traddr), ' ');
|
2016-10-19 17:17:14 +00:00
|
|
|
|
|
|
|
entry->tsas.rdma.rdma_qptype = SPDK_NVMF_RDMA_QPTYPE_RELIABLE_CONNECTED;
|
|
|
|
entry->tsas.rdma.rdma_prtype = SPDK_NVMF_RDMA_PRTYPE_NONE;
|
|
|
|
entry->tsas.rdma.rdma_cms = SPDK_NVMF_RDMA_CMS_RDMA_CM;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
static struct spdk_nvmf_poll_group *
|
|
|
|
spdk_nvmf_rdma_poll_group_create(struct spdk_nvmf_transport *transport)
|
2016-07-26 23:34:12 +00:00
|
|
|
{
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
2016-07-28 17:23:52 +00:00
|
|
|
int i;
|
|
|
|
struct spdk_nvmf_rdma_buf *buf;
|
2016-07-26 23:34:12 +00:00
|
|
|
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = calloc(1, sizeof(*rgroup));
|
|
|
|
if (!rgroup) {
|
2016-10-19 19:41:11 +00:00
|
|
|
return NULL;
|
2016-07-26 23:34:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
/* TODO: Make the number of elements in this pool configurable. For now, one full queue
|
|
|
|
* worth seems reasonable.
|
|
|
|
*/
|
2017-07-28 18:43:18 +00:00
|
|
|
rgroup->buf = spdk_dma_zmalloc(rtransport->max_queue_depth * rtransport->max_io_size,
|
2017-07-28 18:21:45 +00:00
|
|
|
0x20000, NULL);
|
|
|
|
if (!rgroup->buf) {
|
2016-08-03 21:53:23 +00:00
|
|
|
SPDK_ERRLOG("Large buffer pool allocation failed (%d x %d)\n",
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport->max_queue_depth, rtransport->max_io_size);
|
2017-07-28 18:21:45 +00:00
|
|
|
free(rgroup);
|
2016-10-19 19:41:11 +00:00
|
|
|
return NULL;
|
2016-07-28 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
SLIST_INIT(&rgroup->data_buf_pool);
|
2017-07-28 18:43:18 +00:00
|
|
|
for (i = 0; i < rtransport->max_queue_depth; i++) {
|
|
|
|
buf = (struct spdk_nvmf_rdma_buf *)(rgroup->buf + (i * rtransport->max_io_size));
|
2017-07-28 18:21:45 +00:00
|
|
|
SLIST_INSERT_HEAD(&rgroup->data_buf_pool, buf, link);
|
2016-07-28 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
return &rgroup->group;
|
2016-07-26 23:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-28 18:21:45 +00:00
|
|
|
spdk_nvmf_rdma_poll_group_destroy(struct spdk_nvmf_poll_group *group)
|
2016-07-26 23:34:12 +00:00
|
|
|
{
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
2017-08-10 21:32:39 +00:00
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_rdma_poll_group, group);
|
2016-07-26 23:34:12 +00:00
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
if (!rgroup) {
|
2016-07-26 23:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
ibv_dereg_mr(rgroup->buf_mr);
|
|
|
|
spdk_dma_free(rgroup->buf);
|
|
|
|
free(rgroup);
|
2016-07-26 23:34:12 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 18:16:17 +00:00
|
|
|
static int
|
2017-07-28 18:21:45 +00:00
|
|
|
spdk_nvmf_rdma_poll_group_add(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_qpair *qpair)
|
2016-10-19 18:16:17 +00:00
|
|
|
{
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
2017-07-28 18:43:18 +00:00
|
|
|
struct spdk_nvmf_rdma_transport *rtransport;
|
2017-08-02 23:00:18 +00:00
|
|
|
struct spdk_nvmf_rdma_device *device;
|
2017-08-10 21:32:39 +00:00
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_rdma_poll_group, group);
|
2017-08-10 21:32:39 +00:00
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport = SPDK_CONTAINEROF(group->transport, struct spdk_nvmf_rdma_transport, transport);
|
2016-10-19 18:16:17 +00:00
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
if (rgroup->device != NULL) {
|
|
|
|
if (rgroup->device->context != rdma_qpair->cm_id->verbs) {
|
2017-07-28 18:21:45 +00:00
|
|
|
SPDK_ERRLOG("Attempted to add a qpair to a poll group with mismatched RDMA devices.\n");
|
2016-10-19 18:16:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
/* TODO: This actually needs to add the qpairs to an internal list! */
|
2016-10-19 18:16:17 +00:00
|
|
|
/* Nothing else to do. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-02 23:00:18 +00:00
|
|
|
TAILQ_FOREACH(device, &rtransport->devices, link) {
|
|
|
|
if (device->context == rdma_qpair->cm_id->verbs) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!device) {
|
|
|
|
SPDK_ERRLOG("Attempted to add a qpair with an unknown device\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rgroup->device = device;
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup->buf_mr = ibv_reg_mr(rdma_qpair->cm_id->pd, rgroup->buf,
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport->max_queue_depth * rtransport->max_io_size,
|
2017-07-28 18:21:45 +00:00
|
|
|
IBV_ACCESS_LOCAL_WRITE |
|
|
|
|
IBV_ACCESS_REMOTE_WRITE);
|
|
|
|
if (!rgroup->buf_mr) {
|
2016-10-19 18:16:17 +00:00
|
|
|
SPDK_ERRLOG("Large buffer pool registration failed (%d x %d)\n",
|
2017-07-28 18:43:18 +00:00
|
|
|
rtransport->max_queue_depth, rtransport->max_io_size);
|
2017-07-28 18:21:45 +00:00
|
|
|
spdk_dma_free(rgroup->buf);
|
|
|
|
free(rgroup);
|
2016-10-19 18:16:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Controller session Shared Data Pool: %p Length: %x LKey: %x\n",
|
2017-07-28 18:43:18 +00:00
|
|
|
rgroup->buf, rtransport->max_queue_depth * rtransport->max_io_size, rgroup->buf_mr->lkey);
|
2016-10-19 18:16:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-28 18:21:45 +00:00
|
|
|
spdk_nvmf_rdma_poll_group_remove(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_qpair *qpair)
|
2016-10-19 18:16:17 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:25:23 +00:00
|
|
|
static int
|
2016-10-19 17:17:14 +00:00
|
|
|
spdk_nvmf_rdma_request_complete(struct spdk_nvmf_request *req)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2016-10-19 17:17:14 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
2016-10-19 17:03:45 +00:00
|
|
|
int rc;
|
|
|
|
|
2016-10-19 17:17:14 +00:00
|
|
|
if (rsp->status.sc == SPDK_NVME_SC_SUCCESS &&
|
|
|
|
req->xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
|
|
|
rc = spdk_nvmf_rdma_request_transfer_data(req);
|
|
|
|
} else {
|
2017-03-15 18:19:08 +00:00
|
|
|
rc = request_transfer_out(req);
|
2016-10-19 17:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 17:17:14 +00:00
|
|
|
return rc;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
static void
|
|
|
|
request_release_buffer(struct spdk_nvmf_request *req)
|
|
|
|
{
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2017-07-13 21:30:28 +00:00
|
|
|
struct spdk_nvmf_qpair *qpair = req->qpair;
|
2017-07-28 18:21:45 +00:00
|
|
|
struct spdk_nvmf_rdma_poll_group *rgroup;
|
2017-03-15 18:19:08 +00:00
|
|
|
struct spdk_nvmf_rdma_buf *buf;
|
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
rdma_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_rdma_request, req);
|
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
if (rdma_req->data_from_pool) {
|
|
|
|
/* Put the buffer back in the pool */
|
2017-07-28 18:21:45 +00:00
|
|
|
rgroup = SPDK_CONTAINEROF(qpair->ctrlr->group, struct spdk_nvmf_rdma_poll_group, group);
|
2017-03-15 18:19:08 +00:00
|
|
|
buf = req->data;
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
SLIST_INSERT_HEAD(&rgroup->data_buf_pool, buf, link);
|
2017-03-15 18:19:08 +00:00
|
|
|
req->data = NULL;
|
|
|
|
req->length = 0;
|
|
|
|
rdma_req->data_from_pool = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:17:57 +00:00
|
|
|
static void
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_close_qpair(struct spdk_nvmf_qpair *qpair)
|
2016-07-25 16:17:57 +00:00
|
|
|
{
|
2017-08-10 21:32:39 +00:00
|
|
|
spdk_nvmf_rdma_qpair_destroy(SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair));
|
2016-07-25 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:28:05 +00:00
|
|
|
static int
|
2017-07-13 21:30:28 +00:00
|
|
|
process_incoming_queue(struct spdk_nvmf_rdma_qpair *rdma_qpair)
|
2017-03-15 16:28:05 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_recv *rdma_recv, *tmp;
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
struct spdk_nvmf_request *req;
|
|
|
|
int rc, count;
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
count = 0;
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rdma_recv, &rdma_qpair->incoming_queue, link, tmp) {
|
|
|
|
rdma_req = TAILQ_FIRST(&rdma_qpair->free_queue);
|
2017-03-15 16:28:05 +00:00
|
|
|
if (rdma_req == NULL) {
|
|
|
|
/* Need to wait for more SEND completions */
|
|
|
|
break;
|
|
|
|
}
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_REMOVE(&rdma_qpair->free_queue, rdma_req, link);
|
|
|
|
TAILQ_REMOVE(&rdma_qpair->incoming_queue, rdma_recv, link);
|
2017-03-15 16:28:05 +00:00
|
|
|
rdma_req->recv = rdma_recv;
|
|
|
|
req = &rdma_req->req;
|
|
|
|
|
|
|
|
/* The first element of the SGL is the NVMe command */
|
|
|
|
req->cmd = (union nvmf_h2c_msg *)rdma_recv->sgl[0].addr;
|
|
|
|
|
|
|
|
spdk_trace_record(TRACE_NVMF_IO_START, 0, 0, (uint64_t)req, 0);
|
|
|
|
|
|
|
|
memset(req->rsp, 0, sizeof(*req->rsp));
|
|
|
|
rc = spdk_nvmf_request_prep_data(req);
|
|
|
|
switch (rc) {
|
|
|
|
case SPDK_NVMF_REQUEST_PREP_READY:
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Request %p is ready for execution\n", req);
|
|
|
|
/* Data is immediately available */
|
|
|
|
rc = spdk_nvmf_request_exec(req);
|
|
|
|
if (rc < 0) {
|
|
|
|
error = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
case SPDK_NVMF_REQUEST_PREP_PENDING_BUFFER:
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Request %p needs data buffer\n", req);
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->pending_data_buf_queue, rdma_req, link);
|
2017-03-15 16:28:05 +00:00
|
|
|
break;
|
|
|
|
case SPDK_NVMF_REQUEST_PREP_PENDING_DATA:
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "Request %p needs data transfer\n", req);
|
|
|
|
rc = spdk_nvmf_rdma_request_transfer_data(req);
|
|
|
|
if (rc < 0) {
|
|
|
|
error = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPDK_NVMF_REQUEST_PREP_ERROR:
|
|
|
|
spdk_nvmf_request_complete(req);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvmf_rdma_request *
|
2017-07-13 21:30:28 +00:00
|
|
|
get_rdma_req_from_wc(struct spdk_nvmf_rdma_qpair *rdma_qpair,
|
2017-03-15 16:28:05 +00:00
|
|
|
struct ibv_wc *wc)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
|
|
|
|
|
|
|
rdma_req = (struct spdk_nvmf_rdma_request *)wc->wr_id;
|
|
|
|
assert(rdma_req != NULL);
|
2017-07-13 21:30:28 +00:00
|
|
|
assert(rdma_req - rdma_qpair->reqs >= 0);
|
|
|
|
assert(rdma_req - rdma_qpair->reqs < (ptrdiff_t)rdma_qpair->max_queue_depth);
|
2017-03-15 16:28:05 +00:00
|
|
|
|
|
|
|
return rdma_req;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvmf_rdma_recv *
|
2017-07-13 21:30:28 +00:00
|
|
|
get_rdma_recv_from_wc(struct spdk_nvmf_rdma_qpair *rdma_qpair,
|
2017-03-15 16:28:05 +00:00
|
|
|
struct ibv_wc *wc)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_rdma_recv *rdma_recv;
|
|
|
|
|
|
|
|
assert(wc->byte_len >= sizeof(struct spdk_nvmf_capsule_cmd));
|
|
|
|
|
|
|
|
rdma_recv = (struct spdk_nvmf_rdma_recv *)wc->wr_id;
|
|
|
|
assert(rdma_recv != NULL);
|
2017-07-13 21:30:28 +00:00
|
|
|
assert(rdma_recv - rdma_qpair->recvs >= 0);
|
|
|
|
assert(rdma_recv - rdma_qpair->recvs < (ptrdiff_t)rdma_qpair->max_queue_depth);
|
2017-03-15 16:28:05 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
assert(rdma_recv->in_use == false);
|
|
|
|
rdma_recv->in_use = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rdma_recv;
|
|
|
|
}
|
|
|
|
|
2016-07-22 21:33:42 +00:00
|
|
|
/* Returns the number of times that spdk_nvmf_request_exec was called,
|
|
|
|
* or -1 on error.
|
|
|
|
*/
|
2016-07-14 22:25:23 +00:00
|
|
|
static int
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_poll(struct spdk_nvmf_qpair *qpair)
|
2016-06-27 17:14:41 +00:00
|
|
|
{
|
2016-09-15 22:22:45 +00:00
|
|
|
struct ibv_wc wc[32];
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
2016-06-27 22:22:48 +00:00
|
|
|
struct spdk_nvmf_rdma_request *rdma_req;
|
2017-03-15 16:28:05 +00:00
|
|
|
struct spdk_nvmf_rdma_recv *rdma_recv;
|
2016-06-27 17:14:41 +00:00
|
|
|
struct spdk_nvmf_request *req;
|
2016-09-15 22:22:45 +00:00
|
|
|
int reaped, i, rc;
|
2016-07-27 16:38:34 +00:00
|
|
|
int count = 0;
|
2017-02-03 03:55:27 +00:00
|
|
|
bool error = false;
|
2016-06-27 17:14:41 +00:00
|
|
|
|
2017-08-10 21:32:39 +00:00
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
|
|
|
|
2016-09-15 22:10:23 +00:00
|
|
|
/* Poll for completing operations. */
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = ibv_poll_cq(rdma_qpair->cq, 32, wc);
|
2016-09-15 22:22:45 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Error polling CQ! (%d): %s\n",
|
|
|
|
errno, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-27 17:14:41 +00:00
|
|
|
|
2016-09-15 22:22:45 +00:00
|
|
|
reaped = rc;
|
|
|
|
for (i = 0; i < reaped; i++) {
|
|
|
|
if (wc[i].status) {
|
2016-09-15 22:10:23 +00:00
|
|
|
SPDK_ERRLOG("CQ error on Connection %p, Request 0x%lu (%d): %s\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
qpair, wc[i].wr_id, wc[i].status, ibv_wc_status_str(wc[i].status));
|
2017-02-03 03:55:27 +00:00
|
|
|
error = true;
|
|
|
|
continue;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 22:22:45 +00:00
|
|
|
switch (wc[i].opcode) {
|
2016-06-27 17:14:41 +00:00
|
|
|
case IBV_WC_SEND:
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req = get_rdma_req_from_wc(rdma_qpair, &wc[i]);
|
2017-03-15 16:28:05 +00:00
|
|
|
req = &rdma_req->req;
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
assert(rdma_qpair->cur_queue_depth > 0);
|
2016-07-22 22:47:35 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA,
|
|
|
|
"RDMA SEND Complete. Request: %p Connection: %p Outstanding I/O: %d\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
req, qpair, rdma_qpair->cur_queue_depth - 1);
|
|
|
|
rdma_qpair->cur_queue_depth--;
|
2017-03-15 18:19:08 +00:00
|
|
|
|
|
|
|
/* The request may still own a data buffer. Release it */
|
|
|
|
request_release_buffer(req);
|
|
|
|
|
|
|
|
/* Put the request back on the free list */
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->free_queue, rdma_req, link);
|
2017-03-15 18:19:08 +00:00
|
|
|
|
|
|
|
/* Try to process queued incoming requests */
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = process_incoming_queue(rdma_qpair);
|
2017-03-15 16:28:05 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
error = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
count += rc;
|
2016-06-27 17:14:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RDMA_WRITE:
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req = get_rdma_req_from_wc(rdma_qpair, &wc[i]);
|
2017-03-15 16:28:05 +00:00
|
|
|
req = &rdma_req->req;
|
|
|
|
|
2016-07-22 22:30:55 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA WRITE Complete. Request: %p Connection: %p\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
req, qpair);
|
2016-06-27 17:14:41 +00:00
|
|
|
spdk_trace_record(TRACE_RDMA_WRITE_COMPLETE, 0, 0, (uint64_t)req, 0);
|
2016-07-27 22:30:42 +00:00
|
|
|
|
2017-03-15 18:19:08 +00:00
|
|
|
/* Now that the write has completed, the data buffer can be released */
|
|
|
|
request_release_buffer(req);
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_rdma_rw_depth--;
|
2017-03-15 18:19:08 +00:00
|
|
|
|
|
|
|
/* Since an RDMA R/W operation completed, try to submit from the pending list. */
|
2017-07-13 21:30:28 +00:00
|
|
|
rc = spdk_nvmf_rdma_handle_pending_rdma_rw(qpair);
|
2016-07-28 17:23:52 +00:00
|
|
|
if (rc < 0) {
|
2017-02-03 03:55:27 +00:00
|
|
|
error = true;
|
|
|
|
continue;
|
2016-07-27 22:30:42 +00:00
|
|
|
}
|
2016-07-28 17:23:52 +00:00
|
|
|
count += rc;
|
2016-06-27 17:14:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RDMA_READ:
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_req = get_rdma_req_from_wc(rdma_qpair, &wc[i]);
|
2017-03-15 16:28:05 +00:00
|
|
|
req = &rdma_req->req;
|
|
|
|
|
2016-07-22 22:30:55 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA, "RDMA READ Complete. Request: %p Connection: %p\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
req, qpair);
|
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) {
|
2017-02-03 03:55:27 +00:00
|
|
|
error = true;
|
|
|
|
continue;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
2016-07-22 21:33:42 +00:00
|
|
|
count++;
|
2016-07-27 22:30:42 +00:00
|
|
|
|
|
|
|
/* Since an RDMA R/W operation completed, try to submit from the pending list. */
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_rdma_rw_depth--;
|
|
|
|
rc = spdk_nvmf_rdma_handle_pending_rdma_rw(qpair);
|
2016-07-28 17:23:52 +00:00
|
|
|
if (rc < 0) {
|
2017-02-03 03:55:27 +00:00
|
|
|
error = true;
|
|
|
|
continue;
|
2016-07-27 22:30:42 +00:00
|
|
|
}
|
2016-07-28 17:23:52 +00:00
|
|
|
count += rc;
|
2016-06-27 17:14:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBV_WC_RECV:
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_recv = get_rdma_recv_from_wc(rdma_qpair, &wc[i]);
|
2016-07-22 21:28:35 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_queue_depth++;
|
|
|
|
if (rdma_qpair->cur_queue_depth > rdma_qpair->max_queue_depth) {
|
2017-03-15 16:28:05 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA,
|
|
|
|
"Temporarily exceeded maximum queue depth (%u). Queueing.\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_qpair->cur_queue_depth);
|
2017-03-15 16:28:05 +00:00
|
|
|
}
|
2016-07-22 22:47:35 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_RDMA,
|
2017-03-15 16:28:05 +00:00
|
|
|
"RDMA RECV Complete. Recv: %p Connection: %p Outstanding I/O: %d\n",
|
2017-07-13 21:30:28 +00:00
|
|
|
rdma_recv, qpair, rdma_qpair->cur_queue_depth);
|
2017-03-15 16:28:05 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rdma_qpair->incoming_queue, rdma_recv, link);
|
|
|
|
rc = process_incoming_queue(rdma_qpair);
|
2017-03-15 16:28:05 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
error = true;
|
|
|
|
continue;
|
2016-07-22 21:28:35 +00:00
|
|
|
}
|
2017-03-15 16:28:05 +00:00
|
|
|
count += rc;
|
2016-06-27 17:14:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-09-15 22:22:45 +00:00
|
|
|
SPDK_ERRLOG("Received an unknown opcode on the CQ: %d\n", wc[i].opcode);
|
2017-02-03 03:55:27 +00:00
|
|
|
error = true;
|
|
|
|
continue;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-15 22:45:52 +00:00
|
|
|
|
2017-02-03 03:55:27 +00:00
|
|
|
if (error == true) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-22 21:33:42 +00:00
|
|
|
return count;
|
2016-06-27 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 05:20:49 +00:00
|
|
|
static bool
|
2017-07-13 21:30:28 +00:00
|
|
|
spdk_nvmf_rdma_qpair_is_idle(struct spdk_nvmf_qpair *qpair)
|
2017-03-02 05:20:49 +00:00
|
|
|
{
|
2017-08-10 21:32:39 +00:00
|
|
|
struct spdk_nvmf_rdma_qpair *rdma_qpair;
|
|
|
|
|
|
|
|
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
2017-03-02 05:20:49 +00:00
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
if (rdma_qpair->cur_queue_depth == 0 && rdma_qpair->cur_rdma_rw_depth == 0) {
|
2017-03-02 05:20:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 23:30:07 +00:00
|
|
|
const struct spdk_nvmf_transport_ops spdk_nvmf_transport_rdma = {
|
2017-07-13 19:36:44 +00:00
|
|
|
.type = SPDK_NVME_TRANSPORT_RDMA,
|
2017-07-24 23:30:07 +00:00
|
|
|
.create = spdk_nvmf_rdma_create,
|
|
|
|
.destroy = spdk_nvmf_rdma_destroy,
|
2016-08-16 16:35:59 +00:00
|
|
|
|
2017-07-28 17:40:40 +00:00
|
|
|
.listen = spdk_nvmf_rdma_listen,
|
|
|
|
.stop_listen = spdk_nvmf_rdma_stop_listen,
|
|
|
|
.accept = spdk_nvmf_rdma_accept,
|
2016-07-14 22:25:23 +00:00
|
|
|
|
2016-08-18 02:58:15 +00:00
|
|
|
.listen_addr_discover = spdk_nvmf_rdma_discover,
|
|
|
|
|
2017-07-28 18:21:45 +00:00
|
|
|
.poll_group_create = spdk_nvmf_rdma_poll_group_create,
|
|
|
|
.poll_group_destroy = spdk_nvmf_rdma_poll_group_destroy,
|
|
|
|
.poll_group_add = spdk_nvmf_rdma_poll_group_add,
|
|
|
|
.poll_group_remove = spdk_nvmf_rdma_poll_group_remove,
|
2016-07-26 23:34:12 +00:00
|
|
|
|
2016-07-14 22:25:23 +00:00
|
|
|
.req_complete = spdk_nvmf_rdma_request_complete,
|
|
|
|
|
2017-07-13 21:30:28 +00:00
|
|
|
.qpair_fini = spdk_nvmf_rdma_close_qpair,
|
|
|
|
.qpair_poll = spdk_nvmf_rdma_poll,
|
|
|
|
.qpair_is_idle = spdk_nvmf_rdma_qpair_is_idle,
|
2016-08-18 02:58:15 +00:00
|
|
|
|
2016-07-14 22:25:23 +00:00
|
|
|
};
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
SPDK_LOG_REGISTER_TRACE_FLAG("rdma", SPDK_TRACE_RDMA)
|