2016-11-15 05:42:59 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2019-11-18 17:37:09 +00:00
|
|
|
* Copyright (c) Intel Corporation. All rights reserved.
|
2020-01-21 09:13:05 +00:00
|
|
|
* Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
|
2016-11-15 05:42:59 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NVMe over RDMA transport
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
#include "spdk/assert.h"
|
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
#include "spdk/queue.h"
|
|
|
|
#include "spdk/nvme.h"
|
|
|
|
#include "spdk/nvmf_spec.h"
|
2016-11-21 22:11:59 +00:00
|
|
|
#include "spdk/string.h"
|
2017-06-12 23:30:17 +00:00
|
|
|
#include "spdk/endian.h"
|
2018-06-12 20:03:49 +00:00
|
|
|
#include "spdk/likely.h"
|
2020-01-21 14:03:40 +00:00
|
|
|
#include "spdk/config.h"
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
#include "nvme_internal.h"
|
2020-03-14 09:20:44 +00:00
|
|
|
#include "spdk_internal/rdma.h"
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
#define NVME_RDMA_TIME_OUT_IN_MS 2000
|
|
|
|
#define NVME_RDMA_RW_BUFFER_SIZE 131072
|
|
|
|
|
|
|
|
/*
|
2018-10-01 20:44:08 +00:00
|
|
|
* NVME RDMA qpair Resource Defaults
|
2016-11-15 05:42:59 +00:00
|
|
|
*/
|
|
|
|
#define NVME_RDMA_DEFAULT_TX_SGE 2
|
|
|
|
#define NVME_RDMA_DEFAULT_RX_SGE 1
|
|
|
|
|
2018-10-01 20:44:08 +00:00
|
|
|
/* Max number of NVMe-oF SGL descriptors supported by the host */
|
|
|
|
#define NVME_RDMA_MAX_SGL_DESCRIPTORS 16
|
2019-09-05 22:20:56 +00:00
|
|
|
|
|
|
|
/* number of STAILQ entries for holding pending RDMA CM events. */
|
|
|
|
#define NVME_RDMA_NUM_CM_EVENTS 256
|
|
|
|
|
2019-09-20 17:27:32 +00:00
|
|
|
/* CM event processing timeout */
|
2019-12-20 17:05:06 +00:00
|
|
|
#define NVME_RDMA_QPAIR_CM_EVENT_TIMEOUT_US 1000000
|
2019-09-20 17:27:32 +00:00
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
/* The default size for a shared rdma completion queue. */
|
|
|
|
#define DEFAULT_NVME_RDMA_CQ_SIZE 4096
|
|
|
|
|
2019-11-01 22:56:55 +00:00
|
|
|
/*
|
|
|
|
* In the special case of a stale connection we don't expose a mechanism
|
|
|
|
* for the user to retry the connection so we need to handle it internally.
|
|
|
|
*/
|
|
|
|
#define NVME_RDMA_STALE_CONN_RETRY_MAX 5
|
|
|
|
#define NVME_RDMA_STALE_CONN_RETRY_DELAY_US 10000
|
|
|
|
|
2020-01-21 09:13:05 +00:00
|
|
|
/*
|
|
|
|
* Maximum value of transport_retry_count used by RDMA controller
|
|
|
|
*/
|
|
|
|
#define NVME_RDMA_CTRLR_MAX_TRANSPORT_RETRY_COUNT 7
|
|
|
|
|
2020-01-21 14:03:40 +00:00
|
|
|
/*
|
|
|
|
* Maximum value of transport_ack_timeout used by RDMA controller
|
|
|
|
*/
|
|
|
|
#define NVME_RDMA_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT 31
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
/*
|
|
|
|
* Number of poller cycles to keep a pointer to destroyed qpairs
|
|
|
|
* in the poll group.
|
|
|
|
*/
|
2020-05-21 21:35:31 +00:00
|
|
|
#define NVME_RDMA_DESTROYED_QPAIR_EXPIRATION_CYCLES 50
|
2020-03-05 21:47:49 +00:00
|
|
|
|
2020-06-25 12:19:49 +00:00
|
|
|
/*
|
|
|
|
* The max length of keyed SGL data block (3 bytes)
|
|
|
|
*/
|
|
|
|
#define NVME_RDMA_MAX_KEYED_SGL_LENGTH ((1u << 24u) - 1)
|
|
|
|
|
2020-04-18 21:26:02 +00:00
|
|
|
#define WC_PER_QPAIR(queue_depth) (queue_depth * 2)
|
|
|
|
|
2020-03-05 18:41:20 +00:00
|
|
|
enum nvme_rdma_wr_type {
|
|
|
|
RDMA_WR_TYPE_RECV,
|
|
|
|
RDMA_WR_TYPE_SEND,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvme_rdma_wr {
|
|
|
|
/* Using this instead of the enum allows this struct to only occupy one byte. */
|
|
|
|
uint8_t type;
|
|
|
|
};
|
|
|
|
|
2018-10-01 20:44:08 +00:00
|
|
|
struct spdk_nvmf_cmd {
|
|
|
|
struct spdk_nvme_cmd cmd;
|
|
|
|
struct spdk_nvme_sgl_descriptor sgl[NVME_RDMA_MAX_SGL_DESCRIPTORS];
|
|
|
|
};
|
|
|
|
|
2018-08-06 23:27:13 +00:00
|
|
|
struct spdk_nvme_rdma_hooks g_nvme_hooks = {};
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
/* Mapping from virtual address to ibv_mr pointer for a protection domain */
|
|
|
|
struct spdk_nvme_rdma_mr_map {
|
|
|
|
struct ibv_pd *pd;
|
|
|
|
struct spdk_mem_map *map;
|
|
|
|
uint64_t ref;
|
|
|
|
LIST_ENTRY(spdk_nvme_rdma_mr_map) link;
|
|
|
|
};
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
/* STAILQ wrapper for cm events. */
|
|
|
|
struct nvme_rdma_cm_event_entry {
|
|
|
|
struct rdma_cm_event *evt;
|
|
|
|
STAILQ_ENTRY(nvme_rdma_cm_event_entry) link;
|
|
|
|
};
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
/* NVMe RDMA transport extensions for spdk_nvme_ctrlr */
|
|
|
|
struct nvme_rdma_ctrlr {
|
|
|
|
struct spdk_nvme_ctrlr ctrlr;
|
2018-08-06 23:27:13 +00:00
|
|
|
|
|
|
|
struct ibv_pd *pd;
|
2019-06-27 06:15:56 +00:00
|
|
|
|
|
|
|
uint16_t max_sge;
|
2019-09-05 22:20:56 +00:00
|
|
|
|
|
|
|
struct rdma_event_channel *cm_channel;
|
|
|
|
|
|
|
|
STAILQ_HEAD(, nvme_rdma_cm_event_entry) pending_cm_events;
|
|
|
|
|
|
|
|
STAILQ_HEAD(, nvme_rdma_cm_event_entry) free_cm_events;
|
|
|
|
|
|
|
|
struct nvme_rdma_cm_event_entry *cm_events;
|
2016-11-15 05:42:59 +00:00
|
|
|
};
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
struct nvme_rdma_destroyed_qpair {
|
|
|
|
struct nvme_rdma_qpair *destroyed_qpair_tracker;
|
|
|
|
uint32_t completed_cycles;
|
|
|
|
STAILQ_ENTRY(nvme_rdma_destroyed_qpair) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvme_rdma_poller {
|
|
|
|
struct ibv_context *device;
|
|
|
|
struct ibv_cq *cq;
|
2020-04-18 21:26:02 +00:00
|
|
|
int required_num_wc;
|
|
|
|
int current_num_wc;
|
2020-03-05 21:47:49 +00:00
|
|
|
STAILQ_ENTRY(nvme_rdma_poller) link;
|
|
|
|
};
|
|
|
|
|
2020-02-06 22:23:22 +00:00
|
|
|
struct nvme_rdma_poll_group {
|
2020-03-05 21:47:49 +00:00
|
|
|
struct spdk_nvme_transport_poll_group group;
|
|
|
|
STAILQ_HEAD(, nvme_rdma_poller) pollers;
|
|
|
|
int num_pollers;
|
|
|
|
STAILQ_HEAD(, nvme_rdma_destroyed_qpair) destroyed_qpairs;
|
2020-02-06 22:23:22 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
struct spdk_nvme_recv_wr_list {
|
|
|
|
struct ibv_recv_wr *first;
|
|
|
|
struct ibv_recv_wr *last;
|
|
|
|
};
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
/* Memory regions */
|
|
|
|
union nvme_rdma_mr {
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
uint64_t key;
|
|
|
|
};
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
/* NVMe RDMA qpair extensions for spdk_nvme_qpair */
|
|
|
|
struct nvme_rdma_qpair {
|
|
|
|
struct spdk_nvme_qpair qpair;
|
|
|
|
|
2020-03-14 09:20:44 +00:00
|
|
|
struct spdk_rdma_qp *rdma_qp;
|
2016-11-15 05:42:59 +00:00
|
|
|
struct rdma_cm_id *cm_id;
|
2017-03-08 17:30:49 +00:00
|
|
|
struct ibv_cq *cq;
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_reqs;
|
|
|
|
|
2018-11-14 15:34:17 +00:00
|
|
|
uint32_t max_send_sge;
|
|
|
|
|
|
|
|
uint32_t max_recv_sge;
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
uint16_t num_entries;
|
|
|
|
|
2020-04-09 10:02:09 +00:00
|
|
|
bool delay_cmd_submit;
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
bool poll_group_disconnect_in_progress;
|
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
uint32_t num_completions;
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
/* Parallel arrays of response buffers + response SGLs of size num_entries */
|
2016-11-28 22:04:51 +00:00
|
|
|
struct ibv_sge *rsp_sgls;
|
2020-03-05 18:41:20 +00:00
|
|
|
struct spdk_nvme_rdma_rsp *rsps;
|
2016-11-28 22:04:51 +00:00
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_recv_wr *rsp_recv_wrs;
|
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
struct spdk_nvme_recv_wr_list recvs_to_post;
|
|
|
|
|
2016-11-28 22:04:51 +00:00
|
|
|
/* Memory region describing all rsps for this qpair */
|
2020-04-16 21:54:09 +00:00
|
|
|
union nvme_rdma_mr rsp_mr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-14 22:48:24 +00:00
|
|
|
/*
|
2017-01-05 16:54:00 +00:00
|
|
|
* Array of num_entries NVMe commands registered as RDMA message buffers.
|
2016-12-14 22:48:24 +00:00
|
|
|
* Indexed by rdma_req->id.
|
|
|
|
*/
|
2018-10-01 20:44:08 +00:00
|
|
|
struct spdk_nvmf_cmd *cmds;
|
2016-12-14 22:48:24 +00:00
|
|
|
|
|
|
|
/* Memory region describing all cmds for this qpair */
|
2020-04-16 21:54:09 +00:00
|
|
|
union nvme_rdma_mr cmd_mr;
|
2016-12-14 22:48:24 +00:00
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvme_rdma_req) free_reqs;
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_HEAD(, spdk_nvme_rdma_req) outstanding_reqs;
|
2018-11-14 15:34:17 +00:00
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
/* Counts of outstanding send and recv objects */
|
|
|
|
uint16_t current_num_recvs;
|
|
|
|
uint16_t current_num_sends;
|
|
|
|
|
2018-11-14 15:34:17 +00:00
|
|
|
/* Placed at the end of the struct since it is not used frequently */
|
2019-09-05 22:20:56 +00:00
|
|
|
struct rdma_cm_event *evt;
|
2020-03-05 21:47:49 +00:00
|
|
|
|
|
|
|
/* Used by poll group to keep the qpair around until it is ready to remove it. */
|
|
|
|
bool defer_deletion_to_pg;
|
2016-11-15 05:42:59 +00:00
|
|
|
};
|
|
|
|
|
2020-04-09 10:02:09 +00:00
|
|
|
enum NVME_RDMA_COMPLETION_FLAGS {
|
|
|
|
NVME_RDMA_SEND_COMPLETED = 1u << 0,
|
|
|
|
NVME_RDMA_RECV_COMPLETED = 1u << 1,
|
|
|
|
};
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-04-09 10:02:09 +00:00
|
|
|
struct spdk_nvme_rdma_req {
|
|
|
|
uint16_t id;
|
|
|
|
uint16_t completion_flags: 2;
|
|
|
|
uint16_t reserved: 14;
|
|
|
|
/* if completion of RDMA_RECV received before RDMA_SEND, we will complete nvme request
|
|
|
|
* during processing of RDMA_SEND. To complete the request we must know the index
|
|
|
|
* of nvme_cpl received in RDMA_RECV, so store it in this field */
|
|
|
|
uint16_t rsp_idx;
|
2020-03-04 22:08:20 +00:00
|
|
|
|
2020-03-05 18:41:20 +00:00
|
|
|
struct nvme_rdma_wr rdma_wr;
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
struct ibv_send_wr send_wr;
|
|
|
|
|
2018-03-02 19:49:36 +00:00
|
|
|
struct nvme_request *req;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
struct ibv_sge send_sgl[NVME_RDMA_DEFAULT_TX_SGE];
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_ENTRY(spdk_nvme_rdma_req) link;
|
2016-11-15 05:42:59 +00:00
|
|
|
};
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
enum nvme_rdma_key_type {
|
|
|
|
NVME_RDMA_MR_RKEY,
|
|
|
|
NVME_RDMA_MR_LKEY
|
|
|
|
};
|
|
|
|
|
2020-03-05 18:41:20 +00:00
|
|
|
struct spdk_nvme_rdma_rsp {
|
|
|
|
struct spdk_nvme_cpl cpl;
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
uint16_t idx;
|
|
|
|
struct nvme_rdma_wr rdma_wr;
|
|
|
|
};
|
|
|
|
|
2017-11-24 07:17:22 +00:00
|
|
|
static const char *rdma_cm_event_str[] = {
|
|
|
|
"RDMA_CM_EVENT_ADDR_RESOLVED",
|
|
|
|
"RDMA_CM_EVENT_ADDR_ERROR",
|
|
|
|
"RDMA_CM_EVENT_ROUTE_RESOLVED",
|
|
|
|
"RDMA_CM_EVENT_ROUTE_ERROR",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_REQUEST",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_RESPONSE",
|
|
|
|
"RDMA_CM_EVENT_CONNECT_ERROR",
|
|
|
|
"RDMA_CM_EVENT_UNREACHABLE",
|
|
|
|
"RDMA_CM_EVENT_REJECTED",
|
|
|
|
"RDMA_CM_EVENT_ESTABLISHED",
|
|
|
|
"RDMA_CM_EVENT_DISCONNECTED",
|
|
|
|
"RDMA_CM_EVENT_DEVICE_REMOVAL",
|
|
|
|
"RDMA_CM_EVENT_MULTICAST_JOIN",
|
|
|
|
"RDMA_CM_EVENT_MULTICAST_ERROR",
|
|
|
|
"RDMA_CM_EVENT_ADDR_CHANGE",
|
|
|
|
"RDMA_CM_EVENT_TIMEWAIT_EXIT"
|
|
|
|
};
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
static LIST_HEAD(, spdk_nvme_rdma_mr_map) g_rdma_mr_maps = LIST_HEAD_INITIALIZER(&g_rdma_mr_maps);
|
|
|
|
static pthread_mutex_t g_rdma_mr_maps_mutex = PTHREAD_MUTEX_INITIALIZER;
|
2020-05-21 21:35:31 +00:00
|
|
|
struct nvme_rdma_qpair *nvme_rdma_poll_group_get_qpair_by_id(struct nvme_rdma_poll_group *group,
|
|
|
|
uint32_t qp_num);
|
2018-03-28 21:12:38 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
static inline void *
|
|
|
|
nvme_rdma_calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
return calloc(nmemb, size);
|
|
|
|
} else {
|
|
|
|
return spdk_zmalloc(nmemb * size, 0, NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
nvme_rdma_free(void *buf)
|
|
|
|
{
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
spdk_free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int nvme_rdma_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr,
|
|
|
|
struct spdk_nvme_qpair *qpair);
|
2016-11-28 22:25:05 +00:00
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static inline struct nvme_rdma_qpair *
|
|
|
|
nvme_rdma_qpair(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
assert(qpair->trtype == SPDK_NVME_TRANSPORT_RDMA);
|
2018-07-05 22:04:43 +00:00
|
|
|
return SPDK_CONTAINEROF(qpair, struct nvme_rdma_qpair, qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
static inline struct nvme_rdma_poll_group *
|
|
|
|
nvme_rdma_poll_group(struct spdk_nvme_transport_poll_group *group)
|
|
|
|
{
|
|
|
|
return (SPDK_CONTAINEROF(group, struct nvme_rdma_poll_group, group));
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static inline struct nvme_rdma_ctrlr *
|
|
|
|
nvme_rdma_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
assert(ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_RDMA);
|
2018-07-05 22:04:43 +00:00
|
|
|
return SPDK_CONTAINEROF(ctrlr, struct nvme_rdma_ctrlr, ctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvme_rdma_req *
|
|
|
|
nvme_rdma_req_get(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
rdma_req = TAILQ_FIRST(&rqpair->free_reqs);
|
2016-11-28 21:28:40 +00:00
|
|
|
if (rdma_req) {
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_REMOVE(&rqpair->free_reqs, rdma_req, link);
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rqpair->outstanding_reqs, rdma_req, link);
|
2016-11-28 21:28:40 +00:00
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
return rdma_req;
|
|
|
|
}
|
|
|
|
|
2020-06-22 21:20:38 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_req_put(struct nvme_rdma_qpair *rqpair, struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
|
|
|
rdma_req->completion_flags = 0;
|
|
|
|
rdma_req->req = NULL;
|
|
|
|
TAILQ_INSERT_HEAD(&rqpair->free_reqs, rdma_req, link);
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static void
|
2020-06-12 02:47:02 +00:00
|
|
|
nvme_rdma_req_complete(struct spdk_nvme_rdma_req *rdma_req,
|
2016-11-15 05:42:59 +00:00
|
|
|
struct spdk_nvme_cpl *rsp)
|
|
|
|
{
|
2020-06-12 02:47:02 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2020-06-22 21:20:38 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair;
|
2020-06-12 02:47:02 +00:00
|
|
|
|
|
|
|
assert(req != NULL);
|
|
|
|
|
2020-06-22 21:20:38 +00:00
|
|
|
rqpair = nvme_rdma_qpair(req->qpair);
|
|
|
|
TAILQ_REMOVE(&rqpair->outstanding_reqs, rdma_req, link);
|
|
|
|
|
2019-05-21 10:06:42 +00:00
|
|
|
nvme_complete_request(req->cb_fn, req->cb_arg, req->qpair, req, rsp);
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_free_request(req);
|
|
|
|
}
|
|
|
|
|
2017-11-24 07:17:22 +00:00
|
|
|
static const char *
|
|
|
|
nvme_rdma_cm_event_str_get(uint32_t event)
|
|
|
|
{
|
|
|
|
if (event < SPDK_COUNTOF(rdma_cm_event_str)) {
|
|
|
|
return rdma_cm_event_str[event];
|
|
|
|
} else {
|
|
|
|
return "Undefined";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:00:28 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_process_cm_event(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
struct rdma_cm_event *event = rqpair->evt;
|
|
|
|
struct spdk_nvmf_rdma_accept_private_data *accept_data;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
switch (event->event) {
|
|
|
|
case RDMA_CM_EVENT_ADDR_RESOLVED:
|
|
|
|
case RDMA_CM_EVENT_ADDR_ERROR:
|
|
|
|
case RDMA_CM_EVENT_ROUTE_RESOLVED:
|
|
|
|
case RDMA_CM_EVENT_ROUTE_ERROR:
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_CONNECT_REQUEST:
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_CONNECT_ERROR:
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_UNREACHABLE:
|
|
|
|
case RDMA_CM_EVENT_REJECTED:
|
|
|
|
break;
|
2020-03-14 12:08:29 +00:00
|
|
|
case RDMA_CM_EVENT_CONNECT_RESPONSE:
|
|
|
|
rc = spdk_rdma_qp_complete_connect(rqpair->rdma_qp);
|
|
|
|
/* fall through */
|
2019-09-05 21:00:28 +00:00
|
|
|
case RDMA_CM_EVENT_ESTABLISHED:
|
|
|
|
accept_data = (struct spdk_nvmf_rdma_accept_private_data *)event->param.conn.private_data;
|
|
|
|
if (accept_data == NULL) {
|
|
|
|
rc = -1;
|
|
|
|
} else {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "Requested queue depth %d. Actually got queue depth %d.\n",
|
2019-09-05 21:00:28 +00:00
|
|
|
rqpair->num_entries, accept_data->crqsize);
|
|
|
|
rqpair->num_entries = spdk_min(rqpair->num_entries, accept_data->crqsize);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_DISCONNECTED:
|
2019-11-25 23:17:50 +00:00
|
|
|
rqpair->qpair.transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_REMOTE;
|
|
|
|
break;
|
2019-09-05 21:00:28 +00:00
|
|
|
case RDMA_CM_EVENT_DEVICE_REMOVAL:
|
2019-11-25 23:17:50 +00:00
|
|
|
rqpair->qpair.transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_LOCAL;
|
2019-09-05 21:00:28 +00:00
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_MULTICAST_JOIN:
|
|
|
|
case RDMA_CM_EVENT_MULTICAST_ERROR:
|
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_ADDR_CHANGE:
|
2019-11-25 23:17:50 +00:00
|
|
|
rqpair->qpair.transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_LOCAL;
|
2019-09-05 21:00:28 +00:00
|
|
|
break;
|
|
|
|
case RDMA_CM_EVENT_TIMEWAIT_EXIT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unexpected Acceptor Event [%d]\n", event->event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rqpair->evt = NULL;
|
|
|
|
rdma_ack_cm_event(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
/*
|
|
|
|
* This function must be called under the nvme controller's lock
|
|
|
|
* because it touches global controller variables. The lock is taken
|
|
|
|
* by the generic transport code before invoking a few of the functions
|
|
|
|
* in this file: nvme_rdma_ctrlr_connect_qpair, nvme_rdma_ctrlr_delete_io_qpair,
|
|
|
|
* and conditionally nvme_rdma_qpair_process_completions when it is calling
|
|
|
|
* completions on the admin qpair. When adding a new call to this function, please
|
|
|
|
* verify that it is in a situation where it falls under the lock.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nvme_rdma_poll_events(struct nvme_rdma_ctrlr *rctrlr)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_cm_event_entry *entry, *tmp;
|
|
|
|
struct nvme_rdma_qpair *event_qpair;
|
|
|
|
struct rdma_cm_event *event;
|
|
|
|
struct rdma_event_channel *channel = rctrlr->cm_channel;
|
|
|
|
|
|
|
|
STAILQ_FOREACH_SAFE(entry, &rctrlr->pending_cm_events, link, tmp) {
|
|
|
|
event_qpair = nvme_rdma_qpair(entry->evt->id->context);
|
|
|
|
if (event_qpair->evt == NULL) {
|
|
|
|
event_qpair->evt = entry->evt;
|
|
|
|
STAILQ_REMOVE(&rctrlr->pending_cm_events, entry, nvme_rdma_cm_event_entry, link);
|
|
|
|
STAILQ_INSERT_HEAD(&rctrlr->free_cm_events, entry, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (rdma_get_cm_event(channel, &event) == 0) {
|
|
|
|
event_qpair = nvme_rdma_qpair(event->id->context);
|
|
|
|
if (event_qpair->evt == NULL) {
|
|
|
|
event_qpair->evt = event;
|
|
|
|
} else {
|
|
|
|
assert(rctrlr == nvme_rdma_ctrlr(event_qpair->qpair.ctrlr));
|
|
|
|
entry = STAILQ_FIRST(&rctrlr->free_cm_events);
|
|
|
|
if (entry == NULL) {
|
|
|
|
rdma_ack_cm_event(event);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE(&rctrlr->free_cm_events, entry, nvme_rdma_cm_event_entry, link);
|
|
|
|
entry->evt = event;
|
|
|
|
STAILQ_INSERT_TAIL(&rctrlr->pending_cm_events, entry, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:28:58 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_validate_cm_event(enum rdma_cm_event_type expected_evt_type,
|
|
|
|
struct rdma_cm_event *reaped_evt)
|
|
|
|
{
|
|
|
|
int rc = -EBADMSG;
|
|
|
|
|
|
|
|
if (expected_evt_type == reaped_evt->event) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:31:32 +00:00
|
|
|
switch (expected_evt_type) {
|
|
|
|
case RDMA_CM_EVENT_ESTABLISHED:
|
|
|
|
/*
|
|
|
|
* There is an enum ib_cm_rej_reason in the kernel headers that sets 10 as
|
|
|
|
* IB_CM_REJ_STALE_CONN. I can't find the corresponding userspace but we get
|
|
|
|
* the same values here.
|
|
|
|
*/
|
|
|
|
if (reaped_evt->event == RDMA_CM_EVENT_REJECTED && reaped_evt->status == 10) {
|
|
|
|
rc = -ESTALE;
|
2020-03-14 12:08:29 +00:00
|
|
|
} else if (reaped_evt->event == RDMA_CM_EVENT_CONNECT_RESPONSE) {
|
|
|
|
/*
|
|
|
|
* If we are using a qpair which is not created using rdma cm API
|
|
|
|
* then we will receive RDMA_CM_EVENT_CONNECT_RESPONSE instead of
|
|
|
|
* RDMA_CM_EVENT_ESTABLISHED.
|
|
|
|
*/
|
|
|
|
return 0;
|
2019-11-01 22:31:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:28:58 +00:00
|
|
|
SPDK_ERRLOG("Expected %s but received %s (%d) from CM event channel (status = %d)\n",
|
|
|
|
nvme_rdma_cm_event_str_get(expected_evt_type),
|
|
|
|
nvme_rdma_cm_event_str_get(reaped_evt->event), reaped_evt->event,
|
|
|
|
reaped_evt->status);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:00:28 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_process_event(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct rdma_event_channel *channel,
|
|
|
|
enum rdma_cm_event_type evt)
|
2016-12-15 21:09:03 +00:00
|
|
|
{
|
2019-09-05 22:20:56 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2019-09-20 17:27:32 +00:00
|
|
|
uint64_t timeout_ticks;
|
2019-09-05 22:20:56 +00:00
|
|
|
int rc = 0, rc2;
|
2019-09-05 21:00:28 +00:00
|
|
|
|
|
|
|
if (rqpair->evt != NULL) {
|
2019-09-05 22:20:56 +00:00
|
|
|
rc = nvme_rdma_qpair_process_cm_event(rqpair);
|
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
2019-09-05 21:00:28 +00:00
|
|
|
}
|
2016-12-15 21:09:03 +00:00
|
|
|
|
2019-09-20 17:27:32 +00:00
|
|
|
timeout_ticks = (NVME_RDMA_QPAIR_CM_EVENT_TIMEOUT_US * spdk_get_ticks_hz()) / SPDK_SEC_TO_USEC +
|
|
|
|
spdk_get_ticks();
|
2019-09-05 22:20:56 +00:00
|
|
|
rctrlr = nvme_rdma_ctrlr(rqpair->qpair.ctrlr);
|
|
|
|
assert(rctrlr != NULL);
|
2019-09-20 17:27:32 +00:00
|
|
|
|
|
|
|
while (!rqpair->evt && spdk_get_ticks() < timeout_ticks && rc == 0) {
|
2019-09-05 22:20:56 +00:00
|
|
|
rc = nvme_rdma_poll_events(rctrlr);
|
|
|
|
}
|
2019-09-05 19:53:18 +00:00
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
2016-12-15 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 17:27:32 +00:00
|
|
|
if (rqpair->evt == NULL) {
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:28:58 +00:00
|
|
|
rc = nvme_rdma_validate_cm_event(evt, rqpair->evt);
|
2016-12-15 21:09:03 +00:00
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
rc2 = nvme_rdma_qpair_process_cm_event(rqpair);
|
|
|
|
/* bad message takes precedence over the other error codes from processing the event. */
|
|
|
|
return rc == 0 ? rc2 : rc;
|
2016-12-15 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_init(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
int rc;
|
2020-03-14 09:20:44 +00:00
|
|
|
struct spdk_rdma_qp_init_attr attr = {};
|
2018-11-14 15:34:17 +00:00
|
|
|
struct ibv_device_attr dev_attr;
|
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
|
|
|
|
|
|
|
rc = ibv_query_device(rqpair->cm_id->verbs, &dev_attr);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to query RDMA device attributes.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
if (rqpair->qpair.poll_group) {
|
|
|
|
assert(!rqpair->cq);
|
|
|
|
rc = nvme_poll_group_connect_qpair(&rqpair->qpair);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to activate the rdmaqpair.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
assert(rqpair->cq);
|
|
|
|
} else {
|
|
|
|
rqpair->cq = ibv_create_cq(rqpair->cm_id->verbs, rqpair->num_entries * 2, rqpair, NULL, 0);
|
|
|
|
if (!rqpair->cq) {
|
|
|
|
SPDK_ERRLOG("Unable to create completion queue: errno %d: %s\n", errno, spdk_strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-08 17:30:49 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:27:13 +00:00
|
|
|
rctrlr = nvme_rdma_ctrlr(rqpair->qpair.ctrlr);
|
2018-11-09 17:31:15 +00:00
|
|
|
if (g_nvme_hooks.get_ibv_pd) {
|
|
|
|
rctrlr->pd = g_nvme_hooks.get_ibv_pd(&rctrlr->ctrlr.trid, rqpair->cm_id->verbs);
|
2018-08-06 23:27:13 +00:00
|
|
|
} else {
|
|
|
|
rctrlr->pd = NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-14 09:20:44 +00:00
|
|
|
attr.pd = rctrlr->pd;
|
2017-03-08 17:30:49 +00:00
|
|
|
attr.send_cq = rqpair->cq;
|
|
|
|
attr.recv_cq = rqpair->cq;
|
2017-01-05 16:54:00 +00:00
|
|
|
attr.cap.max_send_wr = rqpair->num_entries; /* SEND operations */
|
|
|
|
attr.cap.max_recv_wr = rqpair->num_entries; /* RECV operations */
|
2018-11-14 15:34:17 +00:00
|
|
|
attr.cap.max_send_sge = spdk_min(NVME_RDMA_DEFAULT_TX_SGE, dev_attr.max_sge);
|
|
|
|
attr.cap.max_recv_sge = spdk_min(NVME_RDMA_DEFAULT_RX_SGE, dev_attr.max_sge);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-14 09:20:44 +00:00
|
|
|
rqpair->rdma_qp = spdk_rdma_qp_create(rqpair->cm_id, &attr);
|
2018-11-14 15:34:17 +00:00
|
|
|
|
2020-03-14 09:20:44 +00:00
|
|
|
if (!rqpair->rdma_qp) {
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2018-11-14 15:34:17 +00:00
|
|
|
|
|
|
|
/* ibv_create_qp will change the values in attr.cap. Make sure we store the proper value. */
|
|
|
|
rqpair->max_send_sge = spdk_min(NVME_RDMA_DEFAULT_TX_SGE, attr.cap.max_send_sge);
|
|
|
|
rqpair->max_recv_sge = spdk_min(NVME_RDMA_DEFAULT_RX_SGE, attr.cap.max_recv_sge);
|
2020-05-21 21:35:31 +00:00
|
|
|
rqpair->current_num_recvs = 0;
|
|
|
|
rqpair->current_num_sends = 0;
|
2018-11-14 15:34:17 +00:00
|
|
|
|
2020-03-14 12:08:29 +00:00
|
|
|
rctrlr->pd = rqpair->rdma_qp->qp->pd;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
rqpair->cm_id->context = &rqpair->qpair;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
static inline int
|
|
|
|
nvme_rdma_qpair_submit_sends(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2020-10-15 15:08:13 +00:00
|
|
|
struct ibv_send_wr *bad_send_wr = NULL;
|
2019-07-02 14:58:22 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-04-02 11:03:11 +00:00
|
|
|
rc = spdk_rdma_qp_flush_send_wrs(rqpair->rdma_qp, &bad_send_wr);
|
|
|
|
|
|
|
|
if (spdk_unlikely(rc)) {
|
|
|
|
SPDK_ERRLOG("Failed to post WRs on send queue, errno %d (%s), bad_wr %p\n",
|
|
|
|
rc, spdk_strerror(rc), bad_send_wr);
|
2020-05-21 21:35:31 +00:00
|
|
|
while (bad_send_wr != NULL) {
|
|
|
|
assert(rqpair->current_num_sends > 0);
|
|
|
|
rqpair->current_num_sends--;
|
|
|
|
bad_send_wr = bad_send_wr->next;
|
|
|
|
}
|
2020-04-02 11:03:11 +00:00
|
|
|
return rc;
|
2019-07-02 14:58:22 +00:00
|
|
|
}
|
2020-04-02 11:03:11 +00:00
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
nvme_rdma_qpair_submit_recvs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
struct ibv_recv_wr *bad_recv_wr;
|
2020-07-02 14:39:32 +00:00
|
|
|
int rc = 0;
|
2019-07-02 14:58:22 +00:00
|
|
|
|
|
|
|
if (rqpair->recvs_to_post.first) {
|
2020-03-14 12:08:29 +00:00
|
|
|
rc = ibv_post_recv(rqpair->rdma_qp->qp, rqpair->recvs_to_post.first, &bad_recv_wr);
|
2019-07-02 14:58:22 +00:00
|
|
|
if (spdk_unlikely(rc)) {
|
|
|
|
SPDK_ERRLOG("Failed to post WRs on receive queue, errno %d (%s), bad_wr %p\n",
|
|
|
|
rc, spdk_strerror(rc), bad_recv_wr);
|
2020-05-21 21:35:31 +00:00
|
|
|
while (bad_recv_wr != NULL) {
|
|
|
|
assert(rqpair->current_num_sends > 0);
|
|
|
|
rqpair->current_num_recvs--;
|
|
|
|
bad_recv_wr = bad_recv_wr->next;
|
|
|
|
}
|
2019-07-02 14:58:22 +00:00
|
|
|
}
|
2020-04-02 11:23:41 +00:00
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
rqpair->recvs_to_post.first = NULL;
|
|
|
|
}
|
2020-07-02 14:39:32 +00:00
|
|
|
return rc;
|
2019-07-02 14:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the given send wr structure to the qpair's outstanding sends list. */
|
|
|
|
/* This function accepts only a single wr. */
|
|
|
|
static inline int
|
|
|
|
nvme_rdma_qpair_queue_send_wr(struct nvme_rdma_qpair *rqpair, struct ibv_send_wr *wr)
|
|
|
|
{
|
|
|
|
assert(wr->next == NULL);
|
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
assert(rqpair->current_num_sends < rqpair->num_entries);
|
|
|
|
|
|
|
|
rqpair->current_num_sends++;
|
2020-04-02 11:03:11 +00:00
|
|
|
spdk_rdma_qp_queue_send_wrs(rqpair->rdma_qp, wr);
|
2019-07-02 14:58:22 +00:00
|
|
|
|
|
|
|
if (!rqpair->delay_cmd_submit) {
|
|
|
|
return nvme_rdma_qpair_submit_sends(rqpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the given recv wr structure to the qpair's outstanding recvs list. */
|
|
|
|
/* This function accepts only a single wr. */
|
|
|
|
static inline int
|
|
|
|
nvme_rdma_qpair_queue_recv_wr(struct nvme_rdma_qpair *rqpair, struct ibv_recv_wr *wr)
|
|
|
|
{
|
2020-05-21 21:35:31 +00:00
|
|
|
|
2019-07-02 14:58:22 +00:00
|
|
|
assert(wr->next == NULL);
|
2020-05-21 21:35:31 +00:00
|
|
|
assert(rqpair->current_num_recvs < rqpair->num_entries);
|
2019-07-02 14:58:22 +00:00
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
rqpair->current_num_recvs++;
|
2019-07-02 14:58:22 +00:00
|
|
|
if (rqpair->recvs_to_post.first == NULL) {
|
|
|
|
rqpair->recvs_to_post.first = wr;
|
|
|
|
} else {
|
|
|
|
rqpair->recvs_to_post.last->next = wr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->recvs_to_post.last = wr;
|
|
|
|
|
|
|
|
if (!rqpair->delay_cmd_submit) {
|
|
|
|
return nvme_rdma_qpair_submit_recvs(rqpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:39:08 +00:00
|
|
|
#define nvme_rdma_trace_ibv_sge(sg_list) \
|
|
|
|
if (sg_list) { \
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "local addr %p length 0x%x lkey 0x%x\n", \
|
2016-11-28 22:39:08 +00:00
|
|
|
(void *)(sg_list)->addr, (sg_list)->length, (sg_list)->lkey); \
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-11-28 22:04:51 +00:00
|
|
|
nvme_rdma_post_recv(struct nvme_rdma_qpair *rqpair, uint16_t rsp_idx)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2019-07-02 14:58:22 +00:00
|
|
|
struct ibv_recv_wr *wr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
wr = &rqpair->rsp_recv_wrs[rsp_idx];
|
2019-07-02 14:58:22 +00:00
|
|
|
wr->next = NULL;
|
2016-12-08 06:54:53 +00:00
|
|
|
nvme_rdma_trace_ibv_sge(wr->sg_list);
|
2019-07-02 14:58:22 +00:00
|
|
|
return nvme_rdma_qpair_queue_recv_wr(rqpair, wr);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_reg_mr(struct rdma_cm_id *cm_id, union nvme_rdma_mr *mr, void *mem, size_t length)
|
|
|
|
{
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
mr->mr = rdma_reg_msgs(cm_id, mem, length);
|
|
|
|
if (mr->mr == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to register mr: %s (%d)\n",
|
|
|
|
spdk_strerror(errno), errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mr->key = g_nvme_hooks.get_rkey(cm_id->pd, mem, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
static void
|
2020-04-16 21:54:09 +00:00
|
|
|
nvme_rdma_dereg_mr(union nvme_rdma_mr *mr)
|
|
|
|
{
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
if (mr->mr && rdma_dereg_mr(mr->mr)) {
|
|
|
|
SPDK_ERRLOG("Unable to de-register mr\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mr->key) {
|
|
|
|
g_nvme_hooks.put_rkey(mr->key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memset(mr, 0, sizeof(*mr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
nvme_rdma_mr_get_lkey(union nvme_rdma_mr *mr)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2020-04-16 21:54:09 +00:00
|
|
|
uint32_t lkey;
|
|
|
|
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
lkey = mr->mr->lkey;
|
|
|
|
} else {
|
|
|
|
lkey = *((uint64_t *) mr->key);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
return lkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_unregister_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
nvme_rdma_dereg_mr(&rqpair->rsp_mr);
|
2019-05-06 21:35:21 +00:00
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2019-05-06 21:35:21 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_free_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair->rsps);
|
2016-11-28 22:04:51 +00:00
|
|
|
rqpair->rsps = NULL;
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair->rsp_sgls);
|
2016-11-28 22:04:51 +00:00
|
|
|
rqpair->rsp_sgls = NULL;
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair->rsp_recv_wrs);
|
2016-12-08 06:54:53 +00:00
|
|
|
rqpair->rsp_recv_wrs = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_alloc_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2016-11-28 22:04:51 +00:00
|
|
|
rqpair->rsps = NULL;
|
2016-12-08 06:54:53 +00:00
|
|
|
rqpair->rsp_recv_wrs = NULL;
|
2016-11-28 22:04:51 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair->rsp_sgls = nvme_rdma_calloc(rqpair->num_entries, sizeof(*rqpair->rsp_sgls));
|
2016-11-28 22:04:51 +00:00
|
|
|
if (!rqpair->rsp_sgls) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rsp_sgls\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair->rsp_recv_wrs = nvme_rdma_calloc(rqpair->num_entries, sizeof(*rqpair->rsp_recv_wrs));
|
2016-12-08 06:54:53 +00:00
|
|
|
if (!rqpair->rsp_recv_wrs) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rsp_recv_wrs\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair->rsps = nvme_rdma_calloc(rqpair->num_entries, sizeof(*rqpair->rsps));
|
2016-11-28 22:04:51 +00:00
|
|
|
if (!rqpair->rsps) {
|
2016-11-15 05:42:59 +00:00
|
|
|
SPDK_ERRLOG("can not allocate rdma rsps\n");
|
2016-11-28 22:04:51 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:35:21 +00:00
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
nvme_rdma_free_rsps(rqpair);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_register_rsps(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2020-04-09 10:02:09 +00:00
|
|
|
uint16_t i;
|
|
|
|
int rc;
|
2020-04-16 21:54:09 +00:00
|
|
|
uint32_t lkey;
|
2019-05-06 21:35:21 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
rc = nvme_rdma_reg_mr(rqpair->cm_id, &rqpair->rsp_mr,
|
|
|
|
rqpair->rsps, rqpair->num_entries * sizeof(*rqpair->rsps));
|
|
|
|
|
|
|
|
if (rc < 0) {
|
2016-11-28 22:04:51 +00:00
|
|
|
goto fail;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
lkey = nvme_rdma_mr_get_lkey(&rqpair->rsp_mr);
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
for (i = 0; i < rqpair->num_entries; i++) {
|
2016-11-28 22:04:51 +00:00
|
|
|
struct ibv_sge *rsp_sgl = &rqpair->rsp_sgls[i];
|
2020-03-05 18:41:20 +00:00
|
|
|
struct spdk_nvme_rdma_rsp *rsp = &rqpair->rsps[i];
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-05 18:41:20 +00:00
|
|
|
rsp->rqpair = rqpair;
|
|
|
|
rsp->rdma_wr.type = RDMA_WR_TYPE_RECV;
|
|
|
|
rsp->idx = i;
|
2016-11-28 22:04:51 +00:00
|
|
|
rsp_sgl->addr = (uint64_t)&rqpair->rsps[i];
|
2020-03-05 18:41:20 +00:00
|
|
|
rsp_sgl->length = sizeof(struct spdk_nvme_cpl);
|
2020-04-16 21:54:09 +00:00
|
|
|
rsp_sgl->lkey = lkey;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-05 18:41:20 +00:00
|
|
|
rqpair->rsp_recv_wrs[i].wr_id = (uint64_t)&rsp->rdma_wr;
|
2017-02-22 03:00:17 +00:00
|
|
|
rqpair->rsp_recv_wrs[i].next = NULL;
|
|
|
|
rqpair->rsp_recv_wrs[i].sg_list = rsp_sgl;
|
|
|
|
rqpair->rsp_recv_wrs[i].num_sge = 1;
|
|
|
|
|
2019-12-09 13:32:29 +00:00
|
|
|
rc = nvme_rdma_post_recv(rqpair, i);
|
|
|
|
if (rc) {
|
2016-11-15 05:42:59 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 13:32:29 +00:00
|
|
|
rc = nvme_rdma_qpair_submit_recvs(rqpair);
|
|
|
|
if (rc) {
|
2019-07-02 14:58:22 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
2016-11-28 22:04:51 +00:00
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
fail:
|
2019-05-06 21:35:21 +00:00
|
|
|
nvme_rdma_unregister_rsps(rqpair);
|
2019-12-09 13:32:29 +00:00
|
|
|
return rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-06 21:35:21 +00:00
|
|
|
nvme_rdma_unregister_reqs(struct nvme_rdma_qpair *rqpair)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2020-04-16 21:54:09 +00:00
|
|
|
nvme_rdma_dereg_mr(&rqpair->cmd_mr);
|
2019-05-06 21:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_free_reqs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
if (!rqpair->rdma_reqs) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-14 22:48:24 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair->cmds);
|
2016-12-14 22:48:24 +00:00
|
|
|
rqpair->cmds = NULL;
|
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair->rdma_reqs);
|
2016-12-14 22:48:24 +00:00
|
|
|
rqpair->rdma_reqs = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_alloc_reqs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2020-04-09 10:02:09 +00:00
|
|
|
uint16_t i;
|
2019-10-17 20:05:26 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair->rdma_reqs = nvme_rdma_calloc(rqpair->num_entries, sizeof(struct spdk_nvme_rdma_req));
|
2016-12-15 01:06:23 +00:00
|
|
|
if (rqpair->rdma_reqs == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rdma_reqs\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair->cmds = nvme_rdma_calloc(rqpair->num_entries, sizeof(*rqpair->cmds));
|
2016-12-14 22:48:24 +00:00
|
|
|
if (!rqpair->cmds) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate RDMA cmds\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_INIT(&rqpair->free_reqs);
|
2018-06-12 19:58:44 +00:00
|
|
|
TAILQ_INIT(&rqpair->outstanding_reqs);
|
2017-01-05 16:54:00 +00:00
|
|
|
for (i = 0; i < rqpair->num_entries; i++) {
|
2016-12-15 21:21:57 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
2018-10-10 18:07:17 +00:00
|
|
|
struct spdk_nvmf_cmd *cmd;
|
2016-12-15 21:21:57 +00:00
|
|
|
|
|
|
|
rdma_req = &rqpair->rdma_reqs[i];
|
2020-03-05 18:41:20 +00:00
|
|
|
rdma_req->rdma_wr.type = RDMA_WR_TYPE_SEND;
|
2018-10-10 18:07:17 +00:00
|
|
|
cmd = &rqpair->cmds[i];
|
2016-12-15 21:21:57 +00:00
|
|
|
|
|
|
|
rdma_req->id = i;
|
|
|
|
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first RDMA sgl element will always point
|
|
|
|
* at this data structure. Depending on whether
|
|
|
|
* an NVMe-oF SGL is required, the length of
|
|
|
|
* this element may change. */
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_sgl[0].addr = (uint64_t)cmd;
|
2020-03-05 18:41:20 +00:00
|
|
|
rdma_req->send_wr.wr_id = (uint64_t)&rdma_req->rdma_wr;
|
2017-02-22 10:35:52 +00:00
|
|
|
rdma_req->send_wr.next = NULL;
|
|
|
|
rdma_req->send_wr.opcode = IBV_WR_SEND;
|
|
|
|
rdma_req->send_wr.send_flags = IBV_SEND_SIGNALED;
|
2018-10-10 18:07:17 +00:00
|
|
|
rdma_req->send_wr.sg_list = rdma_req->send_sgl;
|
2017-02-22 10:35:52 +00:00
|
|
|
rdma_req->send_wr.imm_data = 0;
|
|
|
|
|
2018-06-12 19:56:05 +00:00
|
|
|
TAILQ_INSERT_TAIL(&rqpair->free_reqs, rdma_req, link);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 20:05:26 +00:00
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
nvme_rdma_free_reqs(rqpair);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_register_reqs(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
|
|
|
int i;
|
2020-04-16 21:54:09 +00:00
|
|
|
int rc;
|
|
|
|
uint32_t lkey;
|
2019-10-17 20:05:26 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
rc = nvme_rdma_reg_mr(rqpair->cm_id, &rqpair->cmd_mr,
|
|
|
|
rqpair->cmds, rqpair->num_entries * sizeof(*rqpair->cmds));
|
|
|
|
|
|
|
|
if (rc < 0) {
|
2019-10-17 20:05:26 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
lkey = nvme_rdma_mr_get_lkey(&rqpair->cmd_mr);
|
|
|
|
|
2019-10-17 20:05:26 +00:00
|
|
|
for (i = 0; i < rqpair->num_entries; i++) {
|
2020-04-16 21:54:09 +00:00
|
|
|
rqpair->rdma_reqs[i].send_sgl[0].lkey = lkey;
|
2019-10-17 20:05:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2019-05-06 21:35:21 +00:00
|
|
|
nvme_rdma_unregister_reqs(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-15 21:10:12 +00:00
|
|
|
nvme_rdma_resolve_addr(struct nvme_rdma_qpair *rqpair,
|
2017-08-25 22:05:01 +00:00
|
|
|
struct sockaddr *src_addr,
|
|
|
|
struct sockaddr *dst_addr,
|
2016-12-15 21:10:12 +00:00
|
|
|
struct rdma_event_channel *cm_channel)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
ret = rdma_resolve_addr(rqpair->cm_id, src_addr, dst_addr,
|
2016-11-15 05:42:59 +00:00
|
|
|
NVME_RDMA_TIME_OUT_IN_MS);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("rdma_resolve_addr, %d\n", errno);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:00:28 +00:00
|
|
|
ret = nvme_rdma_process_event(rqpair, cm_channel, RDMA_CM_EVENT_ADDR_RESOLVED);
|
|
|
|
if (ret) {
|
2016-12-15 21:09:03 +00:00
|
|
|
SPDK_ERRLOG("RDMA address resolution error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-01-21 14:03:40 +00:00
|
|
|
if (rqpair->qpair.ctrlr->opts.transport_ack_timeout != SPDK_NVME_TRANSPORT_ACK_TIMEOUT_DISABLED) {
|
|
|
|
#ifdef SPDK_CONFIG_RDMA_SET_ACK_TIMEOUT
|
|
|
|
uint8_t timeout = rqpair->qpair.ctrlr->opts.transport_ack_timeout;
|
|
|
|
ret = rdma_set_option(rqpair->cm_id, RDMA_OPTION_ID,
|
|
|
|
RDMA_OPTION_ID_ACK_TIMEOUT,
|
|
|
|
&timeout, sizeof(timeout));
|
|
|
|
if (ret) {
|
|
|
|
SPDK_NOTICELOG("Can't apply RDMA_OPTION_ID_ACK_TIMEOUT %d, ret %d\n", timeout, ret);
|
|
|
|
}
|
|
|
|
#else
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "transport_ack_timeout is not supported\n");
|
2020-01-21 14:03:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
ret = rdma_resolve_route(rqpair->cm_id, NVME_RDMA_TIME_OUT_IN_MS);
|
|
|
|
if (ret) {
|
|
|
|
SPDK_ERRLOG("rdma_resolve_route\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2016-12-15 21:09:03 +00:00
|
|
|
|
2019-09-05 21:00:28 +00:00
|
|
|
ret = nvme_rdma_process_event(rqpair, cm_channel, RDMA_CM_EVENT_ROUTE_RESOLVED);
|
|
|
|
if (ret) {
|
2016-12-15 21:09:03 +00:00
|
|
|
SPDK_ERRLOG("RDMA route resolution error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_connect(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2016-12-15 22:22:58 +00:00
|
|
|
struct rdma_conn_param param = {};
|
2018-03-02 19:49:36 +00:00
|
|
|
struct spdk_nvmf_rdma_request_private_data request_data = {};
|
|
|
|
struct ibv_device_attr attr;
|
|
|
|
int ret;
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2019-09-05 22:20:56 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-08 13:45:25 +00:00
|
|
|
ret = ibv_query_device(rqpair->cm_id->verbs, &attr);
|
|
|
|
if (ret != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to query RDMA device attributes.\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-02 17:07:12 +00:00
|
|
|
param.responder_resources = spdk_min(rqpair->num_entries, attr.max_qp_rd_atom);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-01-13 21:44:25 +00:00
|
|
|
ctrlr = rqpair->qpair.ctrlr;
|
|
|
|
if (!ctrlr) {
|
|
|
|
return -1;
|
|
|
|
}
|
2019-09-05 22:20:56 +00:00
|
|
|
rctrlr = nvme_rdma_ctrlr(ctrlr);
|
|
|
|
assert(rctrlr != NULL);
|
2017-01-13 21:44:25 +00:00
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
request_data.qid = rqpair->qpair.id;
|
2017-01-05 16:54:00 +00:00
|
|
|
request_data.hrqsize = rqpair->num_entries;
|
|
|
|
request_data.hsqsize = rqpair->num_entries - 1;
|
2018-06-22 21:20:31 +00:00
|
|
|
request_data.cntlid = ctrlr->cntlid;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
param.private_data = &request_data;
|
|
|
|
param.private_data_len = sizeof(request_data);
|
2020-01-21 09:13:05 +00:00
|
|
|
param.retry_count = ctrlr->opts.transport_retry_count;
|
2018-10-10 18:40:22 +00:00
|
|
|
param.rnr_retry_count = 7;
|
2016-12-15 22:22:58 +00:00
|
|
|
|
2020-03-14 12:08:29 +00:00
|
|
|
/* Fields below are ignored by rdma cm if qpair has been
|
|
|
|
* created using rdma cm API. */
|
|
|
|
param.srq = 0;
|
|
|
|
param.qp_num = rqpair->rdma_qp->qp->qp_num;
|
|
|
|
|
2016-12-15 22:22:58 +00:00
|
|
|
ret = rdma_connect(rqpair->cm_id, ¶m);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (ret) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("nvme rdma connect error\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-12-15 20:57:50 +00:00
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
ret = nvme_rdma_process_event(rqpair, rctrlr->cm_channel, RDMA_CM_EVENT_ESTABLISHED);
|
2019-11-01 22:56:55 +00:00
|
|
|
if (ret == -ESTALE) {
|
|
|
|
SPDK_NOTICELOG("Received a stale connection notice during connection.\n");
|
|
|
|
return -EAGAIN;
|
|
|
|
} else if (ret) {
|
2020-03-14 12:08:29 +00:00
|
|
|
SPDK_ERRLOG("RDMA connect error %d\n", ret);
|
2020-06-26 16:43:36 +00:00
|
|
|
return ret;
|
2019-11-01 22:56:55 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-12 22:30:16 +00:00
|
|
|
nvme_rdma_parse_addr(struct sockaddr_storage *sa, int family, const char *addr, const char *service)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct addrinfo *res;
|
2016-12-12 22:30:16 +00:00
|
|
|
struct addrinfo hints;
|
2016-11-15 05:42:59 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-12-12 22:30:16 +00:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = family;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
|
|
|
|
ret = getaddrinfo(addr, service, &hints, &res);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (ret) {
|
2017-07-14 17:16:03 +00:00
|
|
|
SPDK_ERRLOG("getaddrinfo failed: %s (%d)\n", gai_strerror(ret), ret);
|
2016-11-15 05:42:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:14:47 +00:00
|
|
|
if (res->ai_addrlen > sizeof(*sa)) {
|
|
|
|
SPDK_ERRLOG("getaddrinfo() ai_addrlen %zu too large\n", (size_t)res->ai_addrlen);
|
|
|
|
ret = EINVAL;
|
|
|
|
} else {
|
|
|
|
memcpy(sa, res->ai_addr, res->ai_addrlen);
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
freeaddrinfo(res);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:54:37 +00:00
|
|
|
static int
|
2017-03-08 18:40:15 +00:00
|
|
|
nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map,
|
|
|
|
enum spdk_mem_map_notify_action action,
|
|
|
|
void *vaddr, size_t size)
|
|
|
|
{
|
2018-11-09 17:31:15 +00:00
|
|
|
struct ibv_pd *pd = cb_ctx;
|
2017-03-08 18:40:15 +00:00
|
|
|
struct ibv_mr *mr;
|
2017-08-08 10:54:37 +00:00
|
|
|
int rc;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_REGISTER:
|
2018-11-09 17:31:15 +00:00
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
2018-08-06 23:27:13 +00:00
|
|
|
mr = ibv_reg_mr(pd, vaddr, size,
|
|
|
|
IBV_ACCESS_LOCAL_WRITE |
|
|
|
|
IBV_ACCESS_REMOTE_READ |
|
|
|
|
IBV_ACCESS_REMOTE_WRITE);
|
|
|
|
if (mr == NULL) {
|
|
|
|
SPDK_ERRLOG("ibv_reg_mr() failed\n");
|
|
|
|
return -EFAULT;
|
|
|
|
} else {
|
|
|
|
rc = spdk_mem_map_set_translation(map, (uint64_t)vaddr, size, (uint64_t)mr);
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
} else {
|
2018-08-06 23:27:13 +00:00
|
|
|
rc = spdk_mem_map_set_translation(map, (uint64_t)vaddr, size,
|
2018-11-09 17:31:15 +00:00
|
|
|
g_nvme_hooks.get_rkey(pd, vaddr, size));
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
|
2018-11-09 17:31:15 +00:00
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
2018-08-06 23:27:13 +00:00
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, NULL);
|
|
|
|
if (mr) {
|
|
|
|
ibv_dereg_mr(mr);
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
2018-08-06 23:27:13 +00:00
|
|
|
rc = spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size);
|
2017-03-08 18:40:15 +00:00
|
|
|
break;
|
2017-08-08 10:54:37 +00:00
|
|
|
default:
|
|
|
|
SPDK_UNREACHABLE();
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
2017-08-08 10:54:37 +00:00
|
|
|
|
|
|
|
return rc;
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 21:09:29 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_check_contiguous_entries(uint64_t addr_1, uint64_t addr_2)
|
|
|
|
{
|
|
|
|
/* Two contiguous mappings will point to the same address which is the start of the RDMA MR. */
|
|
|
|
return addr_1 == addr_2;
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2020-03-14 12:08:29 +00:00
|
|
|
struct ibv_pd *pd = rqpair->rdma_qp->qp->pd;
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
2018-09-11 22:03:31 +00:00
|
|
|
const struct spdk_mem_map_ops nvme_rdma_map_ops = {
|
2018-09-11 23:05:50 +00:00
|
|
|
.notify_cb = nvme_rdma_mr_map_notify,
|
2018-11-27 21:09:29 +00:00
|
|
|
.are_contiguous = nvme_rdma_check_contiguous_entries
|
2018-09-11 22:03:31 +00:00
|
|
|
};
|
2018-03-28 21:12:38 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&g_rdma_mr_maps_mutex);
|
|
|
|
|
|
|
|
/* Look up existing mem map registration for this pd */
|
|
|
|
LIST_FOREACH(mr_map, &g_rdma_mr_maps, link) {
|
|
|
|
if (mr_map->pd == pd) {
|
|
|
|
mr_map->ref++;
|
|
|
|
rqpair->mr_map = mr_map;
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
mr_map = nvme_rdma_calloc(1, sizeof(*mr_map));
|
2018-03-28 21:12:38 +00:00
|
|
|
if (mr_map == NULL) {
|
2020-03-31 01:11:04 +00:00
|
|
|
SPDK_ERRLOG("Failed to allocate mr_map\n");
|
2018-03-28 21:12:38 +00:00
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
mr_map->ref = 1;
|
|
|
|
mr_map->pd = pd;
|
2018-11-09 17:31:15 +00:00
|
|
|
mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, &nvme_rdma_map_ops, pd);
|
2018-08-16 14:29:50 +00:00
|
|
|
if (mr_map->map == NULL) {
|
2017-03-08 18:40:15 +00:00
|
|
|
SPDK_ERRLOG("spdk_mem_map_alloc() failed\n");
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(mr_map);
|
|
|
|
|
2018-03-28 21:12:38 +00:00
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->mr_map = mr_map;
|
2018-03-28 21:12:38 +00:00
|
|
|
LIST_INSERT_HEAD(&g_rdma_mr_maps, mr_map, link);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_unregister_mem(struct nvme_rdma_qpair *rqpair)
|
|
|
|
{
|
2018-03-28 21:12:38 +00:00
|
|
|
struct spdk_nvme_rdma_mr_map *mr_map;
|
|
|
|
|
|
|
|
mr_map = rqpair->mr_map;
|
|
|
|
rqpair->mr_map = NULL;
|
|
|
|
|
|
|
|
if (mr_map == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&g_rdma_mr_maps_mutex);
|
|
|
|
|
|
|
|
assert(mr_map->ref > 0);
|
|
|
|
mr_map->ref--;
|
|
|
|
if (mr_map->ref == 0) {
|
|
|
|
LIST_REMOVE(mr_map, link);
|
|
|
|
spdk_mem_map_free(&mr_map->map);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(mr_map);
|
2018-03-28 21:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&g_rdma_mr_maps_mutex);
|
2017-03-08 18:40:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2020-03-03 18:05:48 +00:00
|
|
|
_nvme_rdma_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2017-08-25 22:05:01 +00:00
|
|
|
struct sockaddr_storage dst_addr;
|
|
|
|
struct sockaddr_storage src_addr;
|
|
|
|
bool src_addr_specified;
|
2016-11-15 05:42:59 +00:00
|
|
|
int rc;
|
2019-09-05 22:20:56 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2019-12-27 00:12:33 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair;
|
2016-12-12 22:30:16 +00:00
|
|
|
int family;
|
2019-09-05 19:53:18 +00:00
|
|
|
|
2019-12-27 00:12:33 +00:00
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
2019-09-05 22:20:56 +00:00
|
|
|
rctrlr = nvme_rdma_ctrlr(ctrlr);
|
|
|
|
assert(rctrlr != NULL);
|
2016-12-12 22:30:16 +00:00
|
|
|
|
|
|
|
switch (ctrlr->trid.adrfam) {
|
|
|
|
case SPDK_NVMF_ADRFAM_IPV4:
|
|
|
|
family = AF_INET;
|
|
|
|
break;
|
|
|
|
case SPDK_NVMF_ADRFAM_IPV6:
|
|
|
|
family = AF_INET6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unhandled ADRFAM %d\n", ctrlr->trid.adrfam);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "adrfam %d ai_family %d\n", ctrlr->trid.adrfam, family);
|
2016-12-12 22:30:16 +00:00
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
memset(&dst_addr, 0, sizeof(dst_addr));
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "trsvcid is %s\n", ctrlr->trid.trsvcid);
|
2017-08-25 22:05:01 +00:00
|
|
|
rc = nvme_rdma_parse_addr(&dst_addr, family, ctrlr->trid.traddr, ctrlr->trid.trsvcid);
|
2016-11-23 18:14:47 +00:00
|
|
|
if (rc != 0) {
|
2017-08-25 22:05:01 +00:00
|
|
|
SPDK_ERRLOG("dst_addr nvme_rdma_parse_addr() failed\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
if (ctrlr->opts.src_addr[0] || ctrlr->opts.src_svcid[0]) {
|
|
|
|
memset(&src_addr, 0, sizeof(src_addr));
|
|
|
|
rc = nvme_rdma_parse_addr(&src_addr, family, ctrlr->opts.src_addr, ctrlr->opts.src_svcid);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("src_addr nvme_rdma_parse_addr() failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
src_addr_specified = true;
|
|
|
|
} else {
|
|
|
|
src_addr_specified = false;
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
rc = rdma_create_id(rctrlr->cm_channel, &rqpair->cm_id, rqpair, RDMA_PS_TCP);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("rdma_create_id() failed\n");
|
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 22:05:01 +00:00
|
|
|
rc = nvme_rdma_resolve_addr(rqpair,
|
|
|
|
src_addr_specified ? (struct sockaddr *)&src_addr : NULL,
|
2019-09-05 22:20:56 +00:00
|
|
|
(struct sockaddr *)&dst_addr, rctrlr->cm_channel);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc < 0) {
|
2016-12-15 21:10:12 +00:00
|
|
|
SPDK_ERRLOG("nvme_rdma_resolve_addr() failed\n");
|
2016-12-01 22:35:47 +00:00
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = nvme_rdma_qpair_init(rqpair);
|
|
|
|
if (rc < 0) {
|
2016-12-01 22:35:47 +00:00
|
|
|
SPDK_ERRLOG("nvme_rdma_qpair_init() failed\n");
|
|
|
|
return -1;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2016-12-15 21:23:41 +00:00
|
|
|
|
|
|
|
rc = nvme_rdma_connect(rqpair);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to connect the rqpair\n");
|
2019-11-01 22:56:55 +00:00
|
|
|
return rc;
|
2016-12-15 21:23:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:35:21 +00:00
|
|
|
rc = nvme_rdma_register_reqs(rqpair);
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "rc =%d\n", rc);
|
2019-05-06 21:35:21 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to register rqpair RDMA requests\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "RDMA requests registered\n");
|
2019-05-06 21:35:21 +00:00
|
|
|
|
|
|
|
rc = nvme_rdma_register_rsps(rqpair);
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "rc =%d\n", rc);
|
2019-05-06 21:35:21 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to register rqpair RDMA responses\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "RDMA responses registered\n");
|
2019-05-06 21:35:21 +00:00
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
rc = nvme_rdma_register_mem(rqpair);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to register memory for RDMA\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-22 21:19:53 +00:00
|
|
|
rc = nvme_fabric_qpair_connect(&rqpair->qpair, rqpair->num_entries);
|
2016-12-15 21:33:18 +00:00
|
|
|
if (rc < 0) {
|
2019-11-25 23:17:50 +00:00
|
|
|
rqpair->qpair.transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_UNKNOWN;
|
2016-12-15 21:33:18 +00:00
|
|
|
SPDK_ERRLOG("Failed to send an NVMe-oF Fabric CONNECT command\n");
|
2020-08-18 19:06:34 +00:00
|
|
|
return rc;
|
2016-12-15 21:33:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-03 18:05:48 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int retry_count = 0;
|
|
|
|
|
|
|
|
rc = _nvme_rdma_ctrlr_connect_qpair(ctrlr, qpair);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -EAGAIN represents the special case where the target side still thought it was connected.
|
|
|
|
* Most NICs will fail the first connection attempt, and the NICs will clean up whatever
|
|
|
|
* state they need to. After that, subsequent connection attempts will succeed.
|
|
|
|
*/
|
|
|
|
if (rc == -EAGAIN) {
|
|
|
|
SPDK_NOTICELOG("Detected stale connection on Target side for qpid: %d\n", qpair->id);
|
|
|
|
do {
|
|
|
|
nvme_delay(NVME_RDMA_STALE_CONN_RETRY_DELAY_US);
|
|
|
|
nvme_transport_ctrlr_disconnect_qpair(ctrlr, qpair);
|
|
|
|
rc = _nvme_rdma_ctrlr_connect_qpair(ctrlr, qpair);
|
|
|
|
retry_count++;
|
|
|
|
} while (rc == -EAGAIN && retry_count < NVME_RDMA_STALE_CONN_RETRY_MAX);
|
|
|
|
}
|
|
|
|
|
2020-06-26 16:43:36 +00:00
|
|
|
return rc;
|
2020-03-03 18:05:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
/*
|
|
|
|
* Build SGL describing empty payload.
|
2016-12-01 06:14:07 +00:00
|
|
|
*/
|
2016-12-15 01:29:22 +00:00
|
|
|
static int
|
2018-10-01 20:44:08 +00:00
|
|
|
nvme_rdma_build_null_request(struct spdk_nvme_rdma_req *rdma_req)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2018-10-01 20:44:08 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first element of this SGL is pointing at an
|
|
|
|
* spdk_nvmf_cmd object. For this particular command,
|
|
|
|
* we only need the first 64 bytes corresponding to
|
|
|
|
* the NVMe command. */
|
2018-10-01 20:44:08 +00:00
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd);
|
2018-10-10 18:07:17 +00:00
|
|
|
|
2018-10-10 18:13:08 +00:00
|
|
|
/* The RDMA SGL needs one element describing the NVMe command. */
|
|
|
|
rdma_req->send_wr.num_sge = 1;
|
|
|
|
|
2018-10-10 18:26:53 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
|
|
|
req->cmd.dptr.sgl1.keyed.length = 0;
|
|
|
|
req->cmd.dptr.sgl1.keyed.key = 0;
|
|
|
|
req->cmd.dptr.sgl1.address = 0;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
static inline bool
|
|
|
|
nvme_rdma_get_key(struct spdk_mem_map *map, void *payload, uint64_t size,
|
|
|
|
enum nvme_rdma_key_type key_type, uint32_t *key)
|
|
|
|
{
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
uint64_t real_size = size;
|
|
|
|
uint32_t _key = 0;
|
|
|
|
|
|
|
|
if (!g_nvme_hooks.get_rkey) {
|
|
|
|
mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)payload, &real_size);
|
|
|
|
|
|
|
|
if (spdk_unlikely(!mr)) {
|
|
|
|
SPDK_ERRLOG("No translation for ptr %p, size %lu\n", payload, size);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (key_type) {
|
|
|
|
case NVME_RDMA_MR_RKEY:
|
|
|
|
_key = mr->rkey;
|
|
|
|
break;
|
|
|
|
case NVME_RDMA_MR_LKEY:
|
|
|
|
_key = mr->lkey;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Invalid key type %d\n", key_type);
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_key = spdk_mem_map_translate(map, (uint64_t)payload, &real_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_unlikely(real_size < size)) {
|
|
|
|
SPDK_ERRLOG("Data buffer split over multiple RDMA Memory Regions\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*key = _key;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
/*
|
|
|
|
* Build inline SGL describing contiguous payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nvme_rdma_build_contig_inline_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
|
|
|
struct nvme_request *req = rdma_req->req;
|
2020-05-06 02:58:58 +00:00
|
|
|
uint32_t lkey = 0;
|
2018-08-11 05:50:25 +00:00
|
|
|
void *payload;
|
|
|
|
|
|
|
|
payload = req->payload.contig_or_cb_arg + req->payload_offset;
|
|
|
|
assert(req->payload_size != 0);
|
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
if (spdk_unlikely(!nvme_rdma_get_key(rqpair->mr_map->map, payload, req->payload_size,
|
|
|
|
NVME_RDMA_MR_LKEY, &lkey))) {
|
|
|
|
return -1;
|
2018-08-11 05:50:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
rdma_req->send_sgl[1].lkey = lkey;
|
|
|
|
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first element of this SGL is pointing at an
|
|
|
|
* spdk_nvmf_cmd object. For this particular command,
|
|
|
|
* we only need the first 64 bytes corresponding to
|
|
|
|
* the NVMe command. */
|
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd);
|
|
|
|
|
2018-10-10 18:19:33 +00:00
|
|
|
rdma_req->send_sgl[1].addr = (uint64_t)payload;
|
|
|
|
rdma_req->send_sgl[1].length = (uint32_t)req->payload_size;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
2018-10-10 18:13:08 +00:00
|
|
|
/* The RDMA SGL contains two elements. The first describes
|
|
|
|
* the NVMe command and the second describes the data
|
|
|
|
* payload. */
|
2018-08-11 05:50:25 +00:00
|
|
|
rdma_req->send_wr.num_sge = 2;
|
2018-10-10 18:07:17 +00:00
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.length = (uint32_t)req->payload_size;
|
2018-09-11 23:14:07 +00:00
|
|
|
/* Inline only supported for icdoff == 0 currently. This function will
|
|
|
|
* not get called for controllers with other values. */
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)0;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
/*
|
|
|
|
* Build SGL describing contiguous payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
2018-08-11 05:50:25 +00:00
|
|
|
nvme_rdma_build_contig_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
2017-03-08 18:40:15 +00:00
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2018-06-01 00:52:54 +00:00
|
|
|
void *payload = req->payload.contig_or_cb_arg + req->payload_offset;
|
2020-05-06 02:58:58 +00:00
|
|
|
uint32_t rkey = 0;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
2018-06-01 00:51:16 +00:00
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2020-06-25 12:19:49 +00:00
|
|
|
if (spdk_unlikely(req->payload_size > NVME_RDMA_MAX_KEYED_SGL_LENGTH)) {
|
|
|
|
SPDK_ERRLOG("SGL length %u exceeds max keyed SGL block size %u\n",
|
|
|
|
req->payload_size, NVME_RDMA_MAX_KEYED_SGL_LENGTH);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
if (spdk_unlikely(!nvme_rdma_get_key(rqpair->mr_map->map, payload, req->payload_size,
|
|
|
|
NVME_RDMA_MR_RKEY, &rkey))) {
|
2016-12-01 06:14:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.key = rkey;
|
|
|
|
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first element of this SGL is pointing at an
|
|
|
|
* spdk_nvmf_cmd object. For this particular command,
|
|
|
|
* we only need the first 64 bytes corresponding to
|
|
|
|
* the NVMe command. */
|
2018-10-01 20:44:08 +00:00
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd);
|
2018-10-10 18:07:17 +00:00
|
|
|
|
2018-10-10 18:13:08 +00:00
|
|
|
/* The RDMA SGL needs one element describing the NVMe command. */
|
2018-10-10 18:07:17 +00:00
|
|
|
rdma_req->send_wr.num_sge = 1;
|
|
|
|
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2017-03-08 18:40:15 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
|
|
|
req->cmd.dptr.sgl1.keyed.length = req->payload_size;
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)payload;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build SGL describing scattered payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
2018-08-11 05:50:25 +00:00
|
|
|
nvme_rdma_build_sgl_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
2017-03-08 18:40:15 +00:00
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct nvme_request *req = rdma_req->req;
|
2018-10-01 20:44:08 +00:00
|
|
|
struct spdk_nvmf_cmd *cmd = &rqpair->cmds[rdma_req->id];
|
2018-08-11 05:50:25 +00:00
|
|
|
void *virt_addr;
|
2020-03-25 15:12:24 +00:00
|
|
|
uint32_t remaining_size;
|
2018-10-10 15:09:26 +00:00
|
|
|
uint32_t sge_length;
|
2018-10-01 20:44:08 +00:00
|
|
|
int rc, max_num_sgl, num_sgl_desc;
|
2020-05-06 02:58:58 +00:00
|
|
|
uint32_t rkey = 0;
|
2017-03-08 18:40:15 +00:00
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
2018-06-01 00:51:16 +00:00
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL);
|
2018-06-01 00:52:54 +00:00
|
|
|
assert(req->payload.reset_sgl_fn != NULL);
|
|
|
|
assert(req->payload.next_sge_fn != NULL);
|
|
|
|
req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset);
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2018-10-01 20:44:08 +00:00
|
|
|
max_num_sgl = req->qpair->ctrlr->max_sges;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2018-10-01 20:44:08 +00:00
|
|
|
remaining_size = req->payload_size;
|
|
|
|
num_sgl_desc = 0;
|
|
|
|
do {
|
|
|
|
rc = req->payload.next_sge_fn(req->payload.contig_or_cb_arg, &virt_addr, &sge_length);
|
|
|
|
if (rc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sge_length = spdk_min(remaining_size, sge_length);
|
|
|
|
|
2020-06-25 12:19:49 +00:00
|
|
|
if (spdk_unlikely(sge_length > NVME_RDMA_MAX_KEYED_SGL_LENGTH)) {
|
|
|
|
SPDK_ERRLOG("SGL length %u exceeds max keyed SGL block size %u\n",
|
|
|
|
sge_length, NVME_RDMA_MAX_KEYED_SGL_LENGTH);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
if (spdk_unlikely(!nvme_rdma_get_key(rqpair->mr_map->map, virt_addr, sge_length,
|
|
|
|
NVME_RDMA_MR_RKEY, &rkey))) {
|
2018-10-01 20:44:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
cmd->sgl[num_sgl_desc].keyed.key = rkey;
|
2018-10-01 20:44:08 +00:00
|
|
|
cmd->sgl[num_sgl_desc].keyed.type = SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK;
|
|
|
|
cmd->sgl[num_sgl_desc].keyed.subtype = SPDK_NVME_SGL_SUBTYPE_ADDRESS;
|
|
|
|
cmd->sgl[num_sgl_desc].keyed.length = sge_length;
|
|
|
|
cmd->sgl[num_sgl_desc].address = (uint64_t)virt_addr;
|
|
|
|
|
|
|
|
remaining_size -= sge_length;
|
|
|
|
num_sgl_desc++;
|
|
|
|
} while (remaining_size > 0 && num_sgl_desc < max_num_sgl);
|
|
|
|
|
|
|
|
|
|
|
|
/* Should be impossible if we did our sgl checks properly up the stack, but do a sanity check here. */
|
|
|
|
if (remaining_size > 0) {
|
2017-03-08 18:40:15 +00:00
|
|
|
return -1;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 16:29:58 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
2018-10-10 18:13:08 +00:00
|
|
|
|
|
|
|
/* The RDMA SGL needs one element describing some portion
|
|
|
|
* of the spdk_nvmf_cmd structure. */
|
2018-10-01 20:44:08 +00:00
|
|
|
rdma_req->send_wr.num_sge = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If only one SGL descriptor is required, it can be embedded directly in the command
|
|
|
|
* as a data block descriptor.
|
|
|
|
*/
|
|
|
|
if (num_sgl_desc == 1) {
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first element of this SGL is pointing at an
|
|
|
|
* spdk_nvmf_cmd object. For this particular command,
|
|
|
|
* we only need the first 64 bytes corresponding to
|
|
|
|
* the NVMe command. */
|
2018-10-01 20:44:08 +00:00
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd);
|
2018-10-10 18:07:17 +00:00
|
|
|
|
2018-08-06 23:27:13 +00:00
|
|
|
req->cmd.dptr.sgl1.keyed.type = cmd->sgl[0].keyed.type;
|
|
|
|
req->cmd.dptr.sgl1.keyed.subtype = cmd->sgl[0].keyed.subtype;
|
|
|
|
req->cmd.dptr.sgl1.keyed.length = cmd->sgl[0].keyed.length;
|
|
|
|
req->cmd.dptr.sgl1.keyed.key = cmd->sgl[0].keyed.key;
|
|
|
|
req->cmd.dptr.sgl1.address = cmd->sgl[0].address;
|
2018-10-01 20:44:08 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Otherwise, The SGL descriptor embedded in the command must point to the list of
|
|
|
|
* SGL descriptors used to describe the operation. In that case it is a last segment descriptor.
|
|
|
|
*/
|
2020-09-09 13:19:39 +00:00
|
|
|
uint32_t descriptors_size = sizeof(struct spdk_nvme_sgl_descriptor) * num_sgl_desc;
|
|
|
|
|
|
|
|
if (spdk_unlikely(descriptors_size > rqpair->qpair.ctrlr->ioccsz_bytes)) {
|
|
|
|
SPDK_ERRLOG("Size of SGL descriptors (%u) exceeds ICD (%u)\n",
|
|
|
|
descriptors_size, rqpair->qpair.ctrlr->ioccsz_bytes);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd) + descriptors_size;
|
2018-10-10 18:07:17 +00:00
|
|
|
|
2018-10-01 20:44:08 +00:00
|
|
|
req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_LAST_SEGMENT;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
|
2020-09-09 13:19:39 +00:00
|
|
|
req->cmd.dptr.sgl1.unkeyed.length = descriptors_size;
|
2018-10-01 20:44:08 +00:00
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)0;
|
|
|
|
}
|
2017-03-08 18:40:15 +00:00
|
|
|
|
2016-12-01 06:14:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
/*
|
|
|
|
* Build inline SGL describing sgl payload buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nvme_rdma_build_sgl_inline_request(struct nvme_rdma_qpair *rqpair,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
|
|
|
struct nvme_request *req = rdma_req->req;
|
2020-05-06 02:58:58 +00:00
|
|
|
uint32_t lkey = 0;
|
2018-08-11 05:50:25 +00:00
|
|
|
uint32_t length;
|
|
|
|
void *virt_addr;
|
2020-03-25 15:12:24 +00:00
|
|
|
int rc;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
assert(req->payload_size != 0);
|
|
|
|
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL);
|
|
|
|
assert(req->payload.reset_sgl_fn != NULL);
|
|
|
|
assert(req->payload.next_sge_fn != NULL);
|
|
|
|
req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset);
|
|
|
|
|
2019-04-26 20:17:33 +00:00
|
|
|
rc = req->payload.next_sge_fn(req->payload.contig_or_cb_arg, &virt_addr, &length);
|
|
|
|
if (rc) {
|
|
|
|
return -1;
|
|
|
|
}
|
2018-08-11 05:50:25 +00:00
|
|
|
|
2019-04-26 20:17:33 +00:00
|
|
|
if (length < req->payload_size) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "Inline SGL request split so sending separately.\n");
|
2019-04-26 20:17:33 +00:00
|
|
|
return nvme_rdma_build_sgl_request(rqpair, rdma_req);
|
|
|
|
}
|
2018-12-04 20:07:16 +00:00
|
|
|
|
2019-04-26 20:17:33 +00:00
|
|
|
if (length > req->payload_size) {
|
|
|
|
length = req->payload_size;
|
|
|
|
}
|
2018-12-04 20:07:16 +00:00
|
|
|
|
2020-03-25 15:12:24 +00:00
|
|
|
if (spdk_unlikely(!nvme_rdma_get_key(rqpair->mr_map->map, virt_addr, length,
|
|
|
|
NVME_RDMA_MR_LKEY, &lkey))) {
|
2018-08-11 05:50:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-26 20:17:33 +00:00
|
|
|
rdma_req->send_sgl[1].addr = (uint64_t)virt_addr;
|
|
|
|
rdma_req->send_sgl[1].length = length;
|
2020-03-25 15:12:24 +00:00
|
|
|
rdma_req->send_sgl[1].lkey = lkey;
|
2019-04-26 20:17:33 +00:00
|
|
|
|
|
|
|
rdma_req->send_wr.num_sge = 2;
|
|
|
|
|
2018-10-10 18:07:17 +00:00
|
|
|
/* The first element of this SGL is pointing at an
|
|
|
|
* spdk_nvmf_cmd object. For this particular command,
|
|
|
|
* we only need the first 64 bytes corresponding to
|
|
|
|
* the NVMe command. */
|
|
|
|
rdma_req->send_sgl[0].length = sizeof(struct spdk_nvme_cmd);
|
|
|
|
|
2018-08-11 05:50:25 +00:00
|
|
|
req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_DATA_BLOCK;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
|
|
|
|
req->cmd.dptr.sgl1.unkeyed.length = (uint32_t)req->payload_size;
|
2018-09-11 23:14:07 +00:00
|
|
|
/* Inline only supported for icdoff == 0 currently. This function will
|
|
|
|
* not get called for controllers with other values. */
|
|
|
|
req->cmd.dptr.sgl1.address = (uint64_t)0;
|
2018-08-11 05:50:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-01 06:14:07 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req,
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
2018-08-11 05:50:25 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr = rqpair->qpair.ctrlr;
|
2020-03-25 09:12:07 +00:00
|
|
|
enum nvme_payload_type payload_type;
|
|
|
|
bool icd_supported;
|
2017-03-08 18:40:15 +00:00
|
|
|
int rc;
|
2016-12-01 06:14:07 +00:00
|
|
|
|
2020-04-09 10:14:41 +00:00
|
|
|
assert(rdma_req->req == NULL);
|
2016-12-01 06:14:07 +00:00
|
|
|
rdma_req->req = req;
|
|
|
|
req->cmd.cid = rdma_req->id;
|
2020-03-25 09:12:07 +00:00
|
|
|
payload_type = nvme_payload_type(&req->payload);
|
|
|
|
/*
|
|
|
|
* Check if icdoff is non zero, to avoid interop conflicts with
|
|
|
|
* targets with non-zero icdoff. Both SPDK and the Linux kernel
|
|
|
|
* targets use icdoff = 0. For targets with non-zero icdoff, we
|
|
|
|
* will currently just not use inline data for now.
|
|
|
|
*/
|
|
|
|
icd_supported = spdk_nvme_opc_get_data_transfer(req->cmd.opc) == SPDK_NVME_DATA_HOST_TO_CONTROLLER
|
|
|
|
&& req->payload_size <= ctrlr->ioccsz_bytes && ctrlr->icdoff == 0;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
if (req->payload_size == 0) {
|
2018-10-01 20:44:08 +00:00
|
|
|
rc = nvme_rdma_build_null_request(rdma_req);
|
2020-03-25 09:12:07 +00:00
|
|
|
} else if (payload_type == NVME_PAYLOAD_TYPE_CONTIG) {
|
|
|
|
if (icd_supported) {
|
2018-08-11 05:50:25 +00:00
|
|
|
rc = nvme_rdma_build_contig_inline_request(rqpair, rdma_req);
|
|
|
|
} else {
|
|
|
|
rc = nvme_rdma_build_contig_request(rqpair, rdma_req);
|
|
|
|
}
|
2020-03-25 09:12:07 +00:00
|
|
|
} else if (payload_type == NVME_PAYLOAD_TYPE_SGL) {
|
|
|
|
if (icd_supported) {
|
2018-08-11 05:50:25 +00:00
|
|
|
rc = nvme_rdma_build_sgl_inline_request(rqpair, rdma_req);
|
|
|
|
} else {
|
|
|
|
rc = nvme_rdma_build_sgl_request(rqpair, rdma_req);
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
} else {
|
2017-03-08 18:40:15 +00:00
|
|
|
rc = -1;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
if (rc) {
|
2020-06-12 02:47:02 +00:00
|
|
|
rdma_req->req = NULL;
|
2017-03-08 18:40:15 +00:00
|
|
|
return rc;
|
2016-12-01 06:14:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 22:48:24 +00:00
|
|
|
memcpy(&rqpair->cmds[rdma_req->id], &req->cmd, sizeof(req->cmd));
|
2016-12-15 01:29:22 +00:00
|
|
|
return 0;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_nvme_qpair *
|
2016-12-15 23:39:54 +00:00
|
|
|
nvme_rdma_ctrlr_create_qpair(struct spdk_nvme_ctrlr *ctrlr,
|
|
|
|
uint16_t qid, uint32_t qsize,
|
2017-04-03 22:52:53 +00:00
|
|
|
enum spdk_nvme_qprio qprio,
|
2019-11-18 17:37:09 +00:00
|
|
|
uint32_t num_requests,
|
|
|
|
bool delay_cmd_submit)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
2020-03-03 18:05:48 +00:00
|
|
|
int rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rqpair = nvme_rdma_calloc(1, sizeof(struct nvme_rdma_qpair));
|
2016-11-15 05:42:59 +00:00
|
|
|
if (!rqpair) {
|
|
|
|
SPDK_ERRLOG("failed to get create rqpair\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-05 16:54:00 +00:00
|
|
|
rqpair->num_entries = qsize;
|
2019-11-18 17:37:09 +00:00
|
|
|
rqpair->delay_cmd_submit = delay_cmd_submit;
|
2016-11-15 05:42:59 +00:00
|
|
|
qpair = &rqpair->qpair;
|
2017-04-03 22:52:53 +00:00
|
|
|
rc = nvme_qpair_init(qpair, qid, ctrlr, qprio, num_requests);
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:52:33 +00:00
|
|
|
rc = nvme_rdma_alloc_reqs(rqpair);
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "rc =%d\n", rc);
|
2019-05-06 21:52:33 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate rqpair RDMA requests\n");
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair);
|
2019-05-06 21:52:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "RDMA requests allocated\n");
|
2019-05-06 21:52:33 +00:00
|
|
|
|
|
|
|
rc = nvme_rdma_alloc_rsps(rqpair);
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "rc =%d\n", rc);
|
2019-05-06 21:52:33 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate rqpair RDMA responses\n");
|
2020-03-03 19:19:35 +00:00
|
|
|
nvme_rdma_free_reqs(rqpair);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair);
|
2019-05-06 21:52:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "RDMA responses allocated\n");
|
2019-05-06 21:52:33 +00:00
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
return qpair;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static void
|
2019-12-27 00:12:33 +00:00
|
|
|
nvme_rdma_ctrlr_disconnect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2019-05-09 19:12:29 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
2020-04-27 17:23:53 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr = NULL;
|
2020-01-02 23:54:47 +00:00
|
|
|
struct nvme_rdma_cm_event_entry *entry, *tmp;
|
2016-11-23 17:43:58 +00:00
|
|
|
|
2017-03-08 18:40:15 +00:00
|
|
|
nvme_rdma_unregister_mem(rqpair);
|
2019-05-06 21:35:21 +00:00
|
|
|
nvme_rdma_unregister_reqs(rqpair);
|
|
|
|
nvme_rdma_unregister_rsps(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2019-09-05 21:00:28 +00:00
|
|
|
if (rqpair->evt) {
|
|
|
|
rdma_ack_cm_event(rqpair->evt);
|
|
|
|
rqpair->evt = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-02 23:54:47 +00:00
|
|
|
/*
|
|
|
|
* This works because we have the controller lock both in
|
|
|
|
* this function and in the function where we add new events.
|
|
|
|
*/
|
|
|
|
if (qpair->ctrlr != NULL) {
|
|
|
|
rctrlr = nvme_rdma_ctrlr(qpair->ctrlr);
|
|
|
|
STAILQ_FOREACH_SAFE(entry, &rctrlr->pending_cm_events, link, tmp) {
|
|
|
|
if (nvme_rdma_qpair(entry->evt->id->context) == rqpair) {
|
|
|
|
STAILQ_REMOVE(&rctrlr->pending_cm_events, entry, nvme_rdma_cm_event_entry, link);
|
|
|
|
rdma_ack_cm_event(entry->evt);
|
|
|
|
STAILQ_INSERT_HEAD(&rctrlr->free_cm_events, entry, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rqpair->cm_id) {
|
2020-03-14 09:20:44 +00:00
|
|
|
if (rqpair->rdma_qp) {
|
2020-06-25 08:07:15 +00:00
|
|
|
spdk_rdma_qp_disconnect(rqpair->rdma_qp);
|
|
|
|
if (rctrlr != NULL) {
|
|
|
|
if (nvme_rdma_process_event(rqpair, rctrlr->cm_channel, RDMA_CM_EVENT_DISCONNECTED)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "Target did not respond to qpair disconnect.\n");
|
2020-06-25 08:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-14 09:20:44 +00:00
|
|
|
spdk_rdma_qp_destroy(rqpair->rdma_qp);
|
|
|
|
rqpair->rdma_qp = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2020-06-25 08:07:15 +00:00
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
rdma_destroy_id(rqpair->cm_id);
|
2019-09-26 15:19:18 +00:00
|
|
|
rqpair->cm_id = NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
if (rqpair->cq) {
|
|
|
|
ibv_destroy_cq(rqpair->cq);
|
2019-09-26 15:19:18 +00:00
|
|
|
rqpair->cq = NULL;
|
2017-03-08 17:30:49 +00:00
|
|
|
}
|
2019-05-09 19:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static void nvme_rdma_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr);
|
|
|
|
|
|
|
|
static int
|
2019-12-27 00:12:33 +00:00
|
|
|
nvme_rdma_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
2019-05-09 19:12:29 +00:00
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
2020-04-14 21:41:11 +00:00
|
|
|
nvme_transport_ctrlr_disconnect_qpair(ctrlr, qpair);
|
2020-03-05 21:47:49 +00:00
|
|
|
if (rqpair->defer_deletion_to_pg) {
|
2020-07-01 10:28:22 +00:00
|
|
|
nvme_qpair_set_state(qpair, NVME_QPAIR_DESTROYING);
|
2020-03-05 21:47:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-09 19:12:29 +00:00
|
|
|
nvme_rdma_qpair_abort_reqs(qpair, 1);
|
|
|
|
nvme_qpair_deinit(qpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2019-05-09 19:12:29 +00:00
|
|
|
nvme_rdma_free_reqs(rqpair);
|
|
|
|
nvme_rdma_free_rsps(rqpair);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rqpair);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static struct spdk_nvme_qpair *
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
|
2017-07-14 23:08:05 +00:00
|
|
|
const struct spdk_nvme_io_qpair_opts *opts)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2017-07-14 23:08:05 +00:00
|
|
|
return nvme_rdma_ctrlr_create_qpair(ctrlr, qid, opts->io_queue_size, opts->qprio,
|
2019-11-18 17:37:09 +00:00
|
|
|
opts->io_queue_requests,
|
|
|
|
opts->delay_cmd_submit);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
/* do nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int nvme_rdma_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr);
|
|
|
|
|
|
|
|
static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
|
2016-12-09 22:14:45 +00:00
|
|
|
const struct spdk_nvme_ctrlr_opts *opts,
|
|
|
|
void *devhandle)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2016-11-18 22:21:04 +00:00
|
|
|
union spdk_nvme_cap_register cap;
|
2018-04-24 21:13:14 +00:00
|
|
|
union spdk_nvme_vs_register vs;
|
2019-06-27 06:15:56 +00:00
|
|
|
struct ibv_context **contexts;
|
|
|
|
struct ibv_device_attr dev_attr;
|
2019-09-05 22:20:56 +00:00
|
|
|
int i, flag, rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
rctrlr = nvme_rdma_calloc(1, sizeof(struct nvme_rdma_ctrlr));
|
2016-11-15 05:42:59 +00:00
|
|
|
if (rctrlr == NULL) {
|
|
|
|
SPDK_ERRLOG("could not allocate ctrlr\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-21 09:13:05 +00:00
|
|
|
rctrlr->ctrlr.opts = *opts;
|
2020-03-11 20:51:37 +00:00
|
|
|
rctrlr->ctrlr.trid = *trid;
|
|
|
|
|
|
|
|
if (opts->transport_retry_count > NVME_RDMA_CTRLR_MAX_TRANSPORT_RETRY_COUNT) {
|
2020-01-21 09:13:05 +00:00
|
|
|
SPDK_NOTICELOG("transport_retry_count exceeds max value %d, use max value\n",
|
|
|
|
NVME_RDMA_CTRLR_MAX_TRANSPORT_RETRY_COUNT);
|
|
|
|
rctrlr->ctrlr.opts.transport_retry_count = NVME_RDMA_CTRLR_MAX_TRANSPORT_RETRY_COUNT;
|
|
|
|
}
|
2020-03-11 20:51:37 +00:00
|
|
|
|
|
|
|
if (opts->transport_ack_timeout > NVME_RDMA_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT) {
|
2020-01-21 14:03:40 +00:00
|
|
|
SPDK_NOTICELOG("transport_ack_timeout exceeds max value %d, use max value\n",
|
|
|
|
NVME_RDMA_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT);
|
|
|
|
rctrlr->ctrlr.opts.transport_ack_timeout = NVME_RDMA_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT;
|
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2019-06-27 06:15:56 +00:00
|
|
|
contexts = rdma_get_devices(NULL);
|
|
|
|
if (contexts == NULL) {
|
|
|
|
SPDK_ERRLOG("rdma_get_devices() failed: %s (%d)\n", spdk_strerror(errno), errno);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rctrlr);
|
2019-06-27 06:15:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
rctrlr->max_sge = NVME_RDMA_MAX_SGL_DESCRIPTORS;
|
|
|
|
|
|
|
|
while (contexts[i] != NULL) {
|
|
|
|
rc = ibv_query_device(contexts[i], &dev_attr);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to query RDMA device attributes.\n");
|
|
|
|
rdma_free_devices(contexts);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rctrlr);
|
2019-06-27 06:15:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rctrlr->max_sge = spdk_min(rctrlr->max_sge, (uint16_t)dev_attr.max_sge);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdma_free_devices(contexts);
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
rc = nvme_ctrlr_construct(&rctrlr->ctrlr);
|
|
|
|
if (rc != 0) {
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
STAILQ_INIT(&rctrlr->pending_cm_events);
|
|
|
|
STAILQ_INIT(&rctrlr->free_cm_events);
|
2020-03-31 01:11:04 +00:00
|
|
|
rctrlr->cm_events = nvme_rdma_calloc(NVME_RDMA_NUM_CM_EVENTS, sizeof(*rctrlr->cm_events));
|
2019-09-05 22:20:56 +00:00
|
|
|
if (rctrlr->cm_events == NULL) {
|
|
|
|
SPDK_ERRLOG("unable to allocat buffers to hold CM events.\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2019-09-05 22:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NVME_RDMA_NUM_CM_EVENTS; i++) {
|
|
|
|
STAILQ_INSERT_TAIL(&rctrlr->free_cm_events, &rctrlr->cm_events[i], link);
|
|
|
|
}
|
|
|
|
|
|
|
|
rctrlr->cm_channel = rdma_create_event_channel();
|
|
|
|
if (rctrlr->cm_channel == NULL) {
|
|
|
|
SPDK_ERRLOG("rdma_create_event_channel() failed\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2019-09-05 22:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flag = fcntl(rctrlr->cm_channel->fd, F_GETFL);
|
|
|
|
if (fcntl(rctrlr->cm_channel->fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
|
|
|
SPDK_ERRLOG("Cannot set event channel to non blocking\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2019-09-05 22:20:56 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 23:39:54 +00:00
|
|
|
rctrlr->ctrlr.adminq = nvme_rdma_ctrlr_create_qpair(&rctrlr->ctrlr, 0,
|
2020-03-03 15:27:30 +00:00
|
|
|
rctrlr->ctrlr.opts.admin_queue_size, 0,
|
|
|
|
rctrlr->ctrlr.opts.admin_queue_size, false);
|
2016-12-15 23:36:08 +00:00
|
|
|
if (!rctrlr->ctrlr.adminq) {
|
|
|
|
SPDK_ERRLOG("failed to create admin qpair\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 18:23:08 +00:00
|
|
|
rc = nvme_transport_ctrlr_connect_qpair(&rctrlr->ctrlr, rctrlr->ctrlr.adminq);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("failed to connect admin qpair\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2020-03-03 18:23:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 22:21:04 +00:00
|
|
|
if (nvme_ctrlr_get_cap(&rctrlr->ctrlr, &cap)) {
|
|
|
|
SPDK_ERRLOG("get_cap() failed\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2016-11-18 22:21:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 21:13:14 +00:00
|
|
|
if (nvme_ctrlr_get_vs(&rctrlr->ctrlr, &vs)) {
|
|
|
|
SPDK_ERRLOG("get_vs() failed\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2018-04-24 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 22:57:19 +00:00
|
|
|
if (nvme_ctrlr_add_process(&rctrlr->ctrlr, 0) != 0) {
|
|
|
|
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
|
2020-04-02 10:30:38 +00:00
|
|
|
goto destruct_ctrlr;
|
2018-05-11 22:57:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 21:13:14 +00:00
|
|
|
nvme_ctrlr_init_cap(&rctrlr->ctrlr, &cap, &vs);
|
2016-11-18 22:21:04 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "successfully initialized the nvmf ctrlr\n");
|
2016-11-15 05:42:59 +00:00
|
|
|
return &rctrlr->ctrlr;
|
2020-04-02 10:30:38 +00:00
|
|
|
|
|
|
|
destruct_ctrlr:
|
|
|
|
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
|
|
|
return NULL;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_ctrlr *rctrlr = nvme_rdma_ctrlr(ctrlr);
|
2019-09-05 22:20:56 +00:00
|
|
|
struct nvme_rdma_cm_event_entry *entry;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2016-11-28 22:25:05 +00:00
|
|
|
if (ctrlr->adminq) {
|
2019-12-27 00:12:33 +00:00
|
|
|
nvme_rdma_ctrlr_delete_io_qpair(ctrlr, ctrlr->adminq);
|
2016-11-28 22:25:05 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
STAILQ_FOREACH(entry, &rctrlr->pending_cm_events, link) {
|
|
|
|
rdma_ack_cm_event(entry->evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_INIT(&rctrlr->free_cm_events);
|
|
|
|
STAILQ_INIT(&rctrlr->pending_cm_events);
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rctrlr->cm_events);
|
2019-09-05 22:20:56 +00:00
|
|
|
|
|
|
|
if (rctrlr->cm_channel) {
|
|
|
|
rdma_destroy_event_channel(rctrlr->cm_channel);
|
|
|
|
rctrlr->cm_channel = NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-13 12:33:57 +00:00
|
|
|
nvme_ctrlr_destruct_finish(ctrlr);
|
|
|
|
|
2020-03-31 01:11:04 +00:00
|
|
|
nvme_rdma_free(rctrlr);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair,
|
|
|
|
struct nvme_request *req)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
2019-07-02 14:58:22 +00:00
|
|
|
struct ibv_send_wr *wr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
2016-12-01 06:14:07 +00:00
|
|
|
assert(rqpair != NULL);
|
|
|
|
assert(req != NULL);
|
2016-12-15 01:29:22 +00:00
|
|
|
|
|
|
|
rdma_req = nvme_rdma_req_get(rqpair);
|
2019-05-09 17:40:12 +00:00
|
|
|
if (!rdma_req) {
|
2019-09-27 20:52:21 +00:00
|
|
|
/* Inform the upper layer to try again later. */
|
|
|
|
return -EAGAIN;
|
2016-12-15 01:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nvme_rdma_req_init(rqpair, req, rdma_req)) {
|
|
|
|
SPDK_ERRLOG("nvme_rdma_req_init() failed\n");
|
2020-06-10 20:25:59 +00:00
|
|
|
TAILQ_REMOVE(&rqpair->outstanding_reqs, rdma_req, link);
|
2020-06-22 21:20:38 +00:00
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2016-11-15 05:42:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-08 06:54:53 +00:00
|
|
|
wr = &rdma_req->send_wr;
|
2019-07-02 14:58:22 +00:00
|
|
|
wr->next = NULL;
|
2016-12-08 06:54:53 +00:00
|
|
|
nvme_rdma_trace_ibv_sge(wr->sg_list);
|
2019-07-02 14:58:22 +00:00
|
|
|
return nvme_rdma_qpair_queue_send_wr(rqpair, wr);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_qpair_reset(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
/* Currently, doing nothing here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static void
|
2019-05-06 23:14:24 +00:00
|
|
|
nvme_rdma_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2018-11-02 22:53:17 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_req, *tmp;
|
|
|
|
struct spdk_nvme_cpl cpl;
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
|
2019-01-12 03:09:33 +00:00
|
|
|
cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
|
2018-11-02 22:53:17 +00:00
|
|
|
cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
2019-05-06 23:14:24 +00:00
|
|
|
cpl.status.dnr = dnr;
|
2018-11-02 22:53:17 +00:00
|
|
|
|
2020-04-21 23:19:02 +00:00
|
|
|
/*
|
|
|
|
* We cannot abort requests at the RDMA layer without
|
|
|
|
* unregistering them. If we do, we can still get error
|
|
|
|
* free completions on the shared completion queue.
|
|
|
|
*/
|
|
|
|
if (nvme_qpair_get_state(qpair) > NVME_QPAIR_DISCONNECTING &&
|
|
|
|
nvme_qpair_get_state(qpair) != NVME_QPAIR_DESTROYING) {
|
|
|
|
nvme_ctrlr_disconnect_qpair(qpair);
|
|
|
|
}
|
|
|
|
|
2018-11-02 22:53:17 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rqpair->outstanding_reqs, link, tmp) {
|
2020-06-12 02:47:02 +00:00
|
|
|
nvme_rdma_req_complete(rdma_req, &cpl);
|
2020-06-22 21:20:38 +00:00
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2018-11-02 22:53:17 +00:00
|
|
|
}
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:03:49 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_qpair_check_timeout(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
uint64_t t02;
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req, *tmp;
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr = qpair->ctrlr;
|
|
|
|
struct spdk_nvme_ctrlr_process *active_proc;
|
|
|
|
|
|
|
|
/* Don't check timeouts during controller initialization. */
|
|
|
|
if (ctrlr->state != NVME_CTRLR_STATE_READY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvme_qpair_is_admin_queue(qpair)) {
|
2020-05-15 03:50:18 +00:00
|
|
|
active_proc = nvme_ctrlr_get_current_process(ctrlr);
|
2018-06-12 20:03:49 +00:00
|
|
|
} else {
|
|
|
|
active_proc = qpair->active_proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only check timeouts if the current process has a timeout callback. */
|
|
|
|
if (active_proc == NULL || active_proc->timeout_cb_fn == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t02 = spdk_get_ticks();
|
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rqpair->outstanding_reqs, link, tmp) {
|
|
|
|
assert(rdma_req->req != NULL);
|
|
|
|
|
|
|
|
if (nvme_request_check_timeout(rdma_req->req, rdma_req->id, active_proc, t02)) {
|
|
|
|
/*
|
|
|
|
* The requests are in order, so as soon as one has not timed out,
|
|
|
|
* stop iterating.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:02:09 +00:00
|
|
|
static inline int
|
|
|
|
nvme_rdma_request_ready(struct nvme_rdma_qpair *rqpair, struct spdk_nvme_rdma_req *rdma_req)
|
|
|
|
{
|
2020-06-12 02:47:02 +00:00
|
|
|
nvme_rdma_req_complete(rdma_req, &rqpair->rsps[rdma_req->rsp_idx].cpl);
|
2020-06-22 21:20:38 +00:00
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2020-04-09 10:02:09 +00:00
|
|
|
return nvme_rdma_post_recv(rqpair, rdma_req->rsp_idx);
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
#define MAX_COMPLETIONS_PER_POLL 128
|
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_fail_qpair(struct spdk_nvme_qpair *qpair, int failure_reason)
|
|
|
|
{
|
|
|
|
if (failure_reason == IBV_WC_RETRY_EXC_ERR) {
|
|
|
|
qpair->transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_REMOTE;
|
|
|
|
} else if (qpair->transport_failure_reason == SPDK_NVME_QPAIR_FAILURE_NONE) {
|
|
|
|
qpair->transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_ctrlr_disconnect_qpair(qpair);
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_conditional_fail_qpair(struct nvme_rdma_qpair *rqpair, struct nvme_rdma_poll_group *group)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_destroyed_qpair *qpair_tracker;
|
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
assert(rqpair);
|
2020-03-05 21:47:49 +00:00
|
|
|
if (group) {
|
|
|
|
STAILQ_FOREACH(qpair_tracker, &group->destroyed_qpairs, link) {
|
|
|
|
if (qpair_tracker->destroyed_qpair_tracker == rqpair) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nvme_rdma_fail_qpair(&rqpair->qpair, 0);
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static int
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_cq_process_completions(struct ibv_cq *cq, uint32_t batch_size,
|
2020-05-21 21:35:31 +00:00
|
|
|
struct nvme_rdma_poll_group *group,
|
|
|
|
struct nvme_rdma_qpair *rdma_qpair)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2019-02-05 21:07:36 +00:00
|
|
|
struct ibv_wc wc[MAX_COMPLETIONS_PER_POLL];
|
2020-03-05 19:13:55 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair;
|
2019-02-05 21:07:36 +00:00
|
|
|
struct spdk_nvme_rdma_req *rdma_req;
|
2020-03-05 18:41:20 +00:00
|
|
|
struct spdk_nvme_rdma_rsp *rdma_rsp;
|
|
|
|
struct nvme_rdma_wr *rdma_wr;
|
2020-03-05 19:13:55 +00:00
|
|
|
uint32_t reaped = 0;
|
|
|
|
int completion_rc = 0;
|
|
|
|
int rc, i;
|
|
|
|
|
|
|
|
rc = ibv_poll_cq(cq, batch_size, wc);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Error polling CQ! (%d): %s\n",
|
|
|
|
errno, spdk_strerror(errno));
|
|
|
|
return -ECANCELED;
|
|
|
|
} else if (rc == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < rc; i++) {
|
|
|
|
rdma_wr = (struct nvme_rdma_wr *)wc[i].wr_id;
|
|
|
|
switch (rdma_wr->type) {
|
|
|
|
case RDMA_WR_TYPE_RECV:
|
|
|
|
rdma_rsp = SPDK_CONTAINEROF(rdma_wr, struct spdk_nvme_rdma_rsp, rdma_wr);
|
|
|
|
rqpair = rdma_rsp->rqpair;
|
2020-05-21 21:35:31 +00:00
|
|
|
assert(rqpair->current_num_recvs > 0);
|
|
|
|
rqpair->current_num_recvs--;
|
2020-03-05 19:13:55 +00:00
|
|
|
|
|
|
|
if (wc[i].status) {
|
|
|
|
SPDK_ERRLOG("CQ error on Queue Pair %p, Response Index %lu (%d): %s\n",
|
|
|
|
rqpair, wc[i].wr_id, wc[i].status, ibv_wc_status_str(wc[i].status));
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_conditional_fail_qpair(rqpair, group);
|
2020-03-05 19:13:55 +00:00
|
|
|
completion_rc = -ENXIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "CQ recv completion\n");
|
2020-03-05 19:13:55 +00:00
|
|
|
|
|
|
|
if (wc[i].byte_len < sizeof(struct spdk_nvme_cpl)) {
|
|
|
|
SPDK_ERRLOG("recv length %u less than expected response size\n", wc[i].byte_len);
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_conditional_fail_qpair(rqpair, group);
|
2020-03-05 19:13:55 +00:00
|
|
|
completion_rc = -ENXIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rdma_req = &rqpair->rdma_reqs[rdma_rsp->cpl.cid];
|
|
|
|
rdma_req->completion_flags |= NVME_RDMA_RECV_COMPLETED;
|
|
|
|
rdma_req->rsp_idx = rdma_rsp->idx;
|
|
|
|
|
|
|
|
if ((rdma_req->completion_flags & NVME_RDMA_SEND_COMPLETED) != 0) {
|
|
|
|
if (spdk_unlikely(nvme_rdma_request_ready(rqpair, rdma_req))) {
|
|
|
|
SPDK_ERRLOG("Unable to re-post rx descriptor\n");
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_conditional_fail_qpair(rqpair, group);
|
2020-03-05 19:13:55 +00:00
|
|
|
completion_rc = -ENXIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
reaped++;
|
|
|
|
rqpair->num_completions++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDMA_WR_TYPE_SEND:
|
|
|
|
rdma_req = SPDK_CONTAINEROF(rdma_wr, struct spdk_nvme_rdma_req, rdma_wr);
|
|
|
|
|
2020-04-21 23:11:39 +00:00
|
|
|
/* If we are flushing I/O */
|
2020-03-05 19:13:55 +00:00
|
|
|
if (wc[i].status) {
|
2020-04-21 23:11:39 +00:00
|
|
|
rqpair = rdma_req->req ? nvme_rdma_qpair(rdma_req->req->qpair) : NULL;
|
2020-05-21 21:35:31 +00:00
|
|
|
if (!rqpair) {
|
|
|
|
rqpair = rdma_qpair != NULL ? rdma_qpair : nvme_rdma_poll_group_get_qpair_by_id(group,
|
|
|
|
wc[i].qp_num);
|
|
|
|
}
|
|
|
|
assert(rqpair);
|
|
|
|
assert(rqpair->current_num_sends > 0);
|
|
|
|
rqpair->current_num_sends--;
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_conditional_fail_qpair(rqpair, group);
|
2020-03-05 19:13:55 +00:00
|
|
|
SPDK_ERRLOG("CQ error on Queue Pair %p, Response Index %lu (%d): %s\n",
|
|
|
|
rqpair, wc[i].wr_id, wc[i].status, ibv_wc_status_str(wc[i].status));
|
|
|
|
completion_rc = -ENXIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-21 23:11:39 +00:00
|
|
|
rqpair = nvme_rdma_qpair(rdma_req->req->qpair);
|
|
|
|
rdma_req->completion_flags |= NVME_RDMA_SEND_COMPLETED;
|
2020-05-21 21:35:31 +00:00
|
|
|
rqpair->current_num_sends--;
|
2020-04-21 23:11:39 +00:00
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
if ((rdma_req->completion_flags & NVME_RDMA_RECV_COMPLETED) != 0) {
|
|
|
|
if (spdk_unlikely(nvme_rdma_request_ready(rqpair, rdma_req))) {
|
|
|
|
SPDK_ERRLOG("Unable to re-post rx descriptor\n");
|
2020-03-05 21:47:49 +00:00
|
|
|
nvme_rdma_conditional_fail_qpair(rqpair, group);
|
2020-03-05 19:13:55 +00:00
|
|
|
completion_rc = -ENXIO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
reaped++;
|
|
|
|
rqpair->num_completions++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Received an unexpected opcode on the CQ: %d\n", rdma_wr->type);
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (completion_rc) {
|
|
|
|
return completion_rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return reaped;
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
static void
|
|
|
|
dummy_disconnected_qpair_cb(struct spdk_nvme_qpair *qpair, void *poll_group_ctx)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_process_completions(struct spdk_nvme_qpair *qpair,
|
|
|
|
uint32_t max_completions)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
int rc = 0, batch_size;
|
|
|
|
struct ibv_cq *cq;
|
2019-09-05 22:20:56 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr;
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
/*
|
|
|
|
* This is used during the connection phase. It's possible that we are still reaping error completions
|
|
|
|
* from other qpairs so we need to call the poll group function. Also, it's more correct since the cq
|
|
|
|
* is shared.
|
|
|
|
*/
|
|
|
|
if (qpair->poll_group != NULL) {
|
|
|
|
return spdk_nvme_poll_group_process_completions(qpair->poll_group->group, max_completions,
|
|
|
|
dummy_disconnected_qpair_cb);
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:18:30 +00:00
|
|
|
if (max_completions == 0) {
|
|
|
|
max_completions = rqpair->num_entries;
|
|
|
|
} else {
|
2017-02-02 17:07:12 +00:00
|
|
|
max_completions = spdk_min(max_completions, rqpair->num_entries);
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 22:20:56 +00:00
|
|
|
if (nvme_qpair_is_admin_queue(&rqpair->qpair)) {
|
|
|
|
rctrlr = nvme_rdma_ctrlr(rqpair->qpair.ctrlr);
|
|
|
|
nvme_rdma_poll_events(rctrlr);
|
|
|
|
}
|
|
|
|
nvme_rdma_qpair_process_cm_event(rqpair);
|
|
|
|
|
2020-04-14 22:02:43 +00:00
|
|
|
if (spdk_unlikely(qpair->transport_failure_reason != SPDK_NVME_QPAIR_FAILURE_NONE)) {
|
2020-03-05 19:13:55 +00:00
|
|
|
nvme_rdma_fail_qpair(qpair, 0);
|
|
|
|
return -ENXIO;
|
2019-10-15 16:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 17:30:49 +00:00
|
|
|
cq = rqpair->cq;
|
2016-12-20 19:18:30 +00:00
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
rqpair->num_completions = 0;
|
2016-12-20 19:18:30 +00:00
|
|
|
do {
|
2020-03-05 19:13:55 +00:00
|
|
|
batch_size = spdk_min((max_completions - rqpair->num_completions), MAX_COMPLETIONS_PER_POLL);
|
2020-05-21 21:35:31 +00:00
|
|
|
rc = nvme_rdma_cq_process_completions(cq, batch_size, NULL, rqpair);
|
2017-03-08 17:30:49 +00:00
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
break;
|
|
|
|
/* Handle the case where we fail to poll the cq. */
|
|
|
|
} else if (rc == -ECANCELED) {
|
|
|
|
nvme_rdma_fail_qpair(qpair, 0);
|
|
|
|
return -ENXIO;
|
|
|
|
} else if (rc == -ENXIO) {
|
|
|
|
return rc;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2020-03-05 19:13:55 +00:00
|
|
|
} while (rqpair->num_completions < max_completions);
|
2016-11-15 05:42:59 +00:00
|
|
|
|
2020-04-02 11:23:41 +00:00
|
|
|
if (spdk_unlikely(nvme_rdma_qpair_submit_sends(rqpair) ||
|
|
|
|
nvme_rdma_qpair_submit_recvs(rqpair))) {
|
2020-03-05 19:13:55 +00:00
|
|
|
nvme_rdma_fail_qpair(qpair, 0);
|
|
|
|
return -ENXIO;
|
2020-04-02 11:23:41 +00:00
|
|
|
}
|
2020-03-17 21:53:27 +00:00
|
|
|
|
2018-06-12 20:03:49 +00:00
|
|
|
if (spdk_unlikely(rqpair->qpair.ctrlr->timeout_enabled)) {
|
|
|
|
nvme_rdma_qpair_check_timeout(qpair);
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:13:55 +00:00
|
|
|
return rqpair->num_completions;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static uint32_t
|
2016-11-15 05:42:59 +00:00
|
|
|
nvme_rdma_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2019-06-27 06:15:56 +00:00
|
|
|
/* max_mr_size by ibv_query_device indicates the largest value that we can
|
|
|
|
* set for a registered memory region. It is independent from the actual
|
|
|
|
* I/O size and is very likely to be larger than 2 MiB which is the
|
|
|
|
* granularity we currently register memory regions. Hence return
|
|
|
|
* UINT32_MAX here and let the generic layer use the controller data to
|
|
|
|
* moderate this value.
|
|
|
|
*/
|
|
|
|
return UINT32_MAX;
|
2016-11-15 05:42:59 +00:00
|
|
|
}
|
2016-12-15 00:03:39 +00:00
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static uint16_t
|
2017-08-02 19:03:06 +00:00
|
|
|
nvme_rdma_ctrlr_get_max_sges(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2019-06-27 06:15:56 +00:00
|
|
|
struct nvme_rdma_ctrlr *rctrlr = nvme_rdma_ctrlr(ctrlr);
|
|
|
|
|
|
|
|
return rctrlr->max_sge;
|
2017-08-02 19:03:06 +00:00
|
|
|
}
|
2017-04-21 23:35:11 +00:00
|
|
|
|
2020-05-17 22:05:51 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_qpair_iterate_requests(struct spdk_nvme_qpair *qpair,
|
|
|
|
int (*iter_fn)(struct nvme_request *req, void *arg),
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req, *tmp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert(iter_fn != NULL);
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rqpair->outstanding_reqs, link, tmp) {
|
|
|
|
assert(rdma_req->req != NULL);
|
|
|
|
|
|
|
|
rc = iter_fn(rdma_req->req, arg);
|
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:21:03 +00:00
|
|
|
static void
|
2019-05-06 22:29:24 +00:00
|
|
|
nvme_rdma_admin_qpair_abort_aers(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_rdma_req *rdma_req, *tmp;
|
|
|
|
struct spdk_nvme_cpl cpl;
|
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
|
|
|
|
cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
|
|
|
|
cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(rdma_req, &rqpair->outstanding_reqs, link, tmp) {
|
|
|
|
assert(rdma_req->req != NULL);
|
|
|
|
|
2020-06-12 02:47:02 +00:00
|
|
|
if (rdma_req->req->cmd.opc != SPDK_NVME_OPC_ASYNC_EVENT_REQUEST) {
|
2020-06-10 20:25:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-12 02:47:02 +00:00
|
|
|
nvme_rdma_req_complete(rdma_req, &cpl);
|
2020-06-22 21:20:38 +00:00
|
|
|
nvme_rdma_req_put(rqpair, rdma_req);
|
2019-05-06 22:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_poller_create(struct nvme_rdma_poll_group *group, struct ibv_context *ctx)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_poller *poller;
|
|
|
|
|
|
|
|
poller = calloc(1, sizeof(*poller));
|
|
|
|
if (poller == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate poller.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
poller->device = ctx;
|
|
|
|
poller->cq = ibv_create_cq(poller->device, DEFAULT_NVME_RDMA_CQ_SIZE, group, NULL, 0);
|
|
|
|
|
|
|
|
if (poller->cq == NULL) {
|
|
|
|
free(poller);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_INSERT_HEAD(&group->pollers, poller, link);
|
|
|
|
group->num_pollers++;
|
2020-04-18 21:26:02 +00:00
|
|
|
poller->current_num_wc = DEFAULT_NVME_RDMA_CQ_SIZE;
|
|
|
|
poller->required_num_wc = 0;
|
2020-03-05 21:47:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_rdma_poll_group_free_pollers(struct nvme_rdma_poll_group *group)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_poller *poller, *tmp_poller;
|
|
|
|
|
|
|
|
STAILQ_FOREACH_SAFE(poller, &group->pollers, link, tmp_poller) {
|
|
|
|
if (poller->cq) {
|
|
|
|
ibv_destroy_cq(poller->cq);
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE(&group->pollers, poller, nvme_rdma_poller, link);
|
|
|
|
free(poller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:25:05 +00:00
|
|
|
static struct spdk_nvme_transport_poll_group *
|
|
|
|
nvme_rdma_poll_group_create(void)
|
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
struct nvme_rdma_poll_group *group;
|
|
|
|
struct ibv_context **contexts;
|
|
|
|
int i = 0;
|
2020-02-06 22:23:22 +00:00
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
group = calloc(1, sizeof(*group));
|
2020-02-06 22:23:22 +00:00
|
|
|
if (group == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate poll group.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
STAILQ_INIT(&group->pollers);
|
|
|
|
|
|
|
|
contexts = rdma_get_devices(NULL);
|
|
|
|
if (contexts == NULL) {
|
|
|
|
SPDK_ERRLOG("rdma_get_devices() failed: %s (%d)\n", spdk_strerror(errno), errno);
|
|
|
|
free(group);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (contexts[i] != NULL) {
|
|
|
|
if (nvme_rdma_poller_create(group, contexts[i])) {
|
|
|
|
nvme_rdma_poll_group_free_pollers(group);
|
|
|
|
free(group);
|
|
|
|
rdma_free_devices(contexts);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdma_free_devices(contexts);
|
|
|
|
STAILQ_INIT(&group->destroyed_qpairs);
|
2020-02-06 22:23:22 +00:00
|
|
|
return &group->group;
|
2020-02-05 20:25:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
struct nvme_rdma_qpair *
|
|
|
|
nvme_rdma_poll_group_get_qpair_by_id(struct nvme_rdma_poll_group *group, uint32_t qp_num)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
|
|
|
struct nvme_rdma_destroyed_qpair *rqpair_tracker;
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
|
|
|
|
STAILQ_FOREACH(qpair, &group->group.disconnected_qpairs, poll_group_stailq) {
|
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
if (rqpair->rdma_qp->qp->qp_num == qp_num) {
|
|
|
|
return rqpair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_FOREACH(qpair, &group->group.connected_qpairs, poll_group_stailq) {
|
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
if (rqpair->rdma_qp->qp->qp_num == qp_num) {
|
|
|
|
return rqpair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_FOREACH(rqpair_tracker, &group->destroyed_qpairs, link) {
|
|
|
|
rqpair = rqpair_tracker->destroyed_qpair_tracker;
|
|
|
|
if (rqpair->rdma_qp->qp->qp_num == qp_num) {
|
|
|
|
return rqpair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-18 21:26:02 +00:00
|
|
|
static int
|
|
|
|
nvme_rdma_resize_cq(struct nvme_rdma_qpair *rqpair, struct nvme_rdma_poller *poller)
|
|
|
|
{
|
|
|
|
int current_num_wc, required_num_wc;
|
|
|
|
|
|
|
|
required_num_wc = poller->required_num_wc + WC_PER_QPAIR(rqpair->num_entries);
|
|
|
|
current_num_wc = poller->current_num_wc;
|
|
|
|
if (current_num_wc < required_num_wc) {
|
|
|
|
current_num_wc = spdk_max(current_num_wc * 2, required_num_wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (poller->current_num_wc != current_num_wc) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(nvme, "Resize RDMA CQ from %d to %d\n", poller->current_num_wc,
|
2020-04-18 21:26:02 +00:00
|
|
|
current_num_wc);
|
|
|
|
if (ibv_resize_cq(poller->cq, current_num_wc)) {
|
|
|
|
SPDK_ERRLOG("RDMA CQ resize failed: errno %d: %s\n", errno, spdk_strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
poller->current_num_wc = current_num_wc;
|
|
|
|
}
|
|
|
|
|
|
|
|
poller->required_num_wc = required_num_wc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:25:05 +00:00
|
|
|
static int
|
2020-04-07 17:20:41 +00:00
|
|
|
nvme_rdma_poll_group_connect_qpair(struct spdk_nvme_qpair *qpair)
|
2020-02-05 20:25:05 +00:00
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct nvme_rdma_poll_group *group = nvme_rdma_poll_group(qpair->poll_group);
|
|
|
|
struct nvme_rdma_poller *poller;
|
|
|
|
|
|
|
|
assert(rqpair->cq == NULL);
|
|
|
|
|
|
|
|
STAILQ_FOREACH(poller, &group->pollers, link) {
|
|
|
|
if (poller->device == rqpair->cm_id->verbs) {
|
2020-04-18 21:26:02 +00:00
|
|
|
if (nvme_rdma_resize_cq(rqpair, poller)) {
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
2020-03-05 21:47:49 +00:00
|
|
|
rqpair->cq = poller->cq;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rqpair->cq == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to find a cq for qpair %p on poll group %p\n", qpair, qpair->poll_group);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:25:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-04-07 17:20:41 +00:00
|
|
|
nvme_rdma_poll_group_disconnect_qpair(struct spdk_nvme_qpair *qpair)
|
2020-02-05 20:25:05 +00:00
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
struct nvme_rdma_qpair *rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
struct nvme_rdma_poll_group *group;
|
|
|
|
struct nvme_rdma_destroyed_qpair *destroyed_qpair;
|
|
|
|
enum nvme_qpair_state state;
|
|
|
|
|
|
|
|
if (rqpair->poll_group_disconnect_in_progress) {
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
rqpair->poll_group_disconnect_in_progress = true;
|
|
|
|
state = nvme_qpair_get_state(qpair);
|
|
|
|
group = nvme_rdma_poll_group(qpair->poll_group);
|
|
|
|
rqpair->cq = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to guard against an endless recursive loop while making
|
|
|
|
* sure the qpair is disconnected before we disconnect it from the qpair.
|
|
|
|
*/
|
|
|
|
if (state > NVME_QPAIR_DISCONNECTING && state != NVME_QPAIR_DESTROYING) {
|
|
|
|
nvme_ctrlr_disconnect_qpair(qpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this fails, the system is in serious trouble,
|
|
|
|
* just let the qpair get cleaned up immediately.
|
|
|
|
*/
|
|
|
|
destroyed_qpair = calloc(1, sizeof(*destroyed_qpair));
|
|
|
|
if (destroyed_qpair == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyed_qpair->destroyed_qpair_tracker = rqpair;
|
|
|
|
destroyed_qpair->completed_cycles = 0;
|
|
|
|
STAILQ_INSERT_TAIL(&group->destroyed_qpairs, destroyed_qpair, link);
|
|
|
|
|
|
|
|
rqpair->defer_deletion_to_pg = true;
|
|
|
|
|
|
|
|
rqpair->poll_group_disconnect_in_progress = false;
|
2020-02-05 20:25:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_poll_group_add(struct spdk_nvme_transport_poll_group *tgroup,
|
|
|
|
struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2020-02-06 22:23:22 +00:00
|
|
|
return 0;
|
2020-02-05 20:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_poll_group_remove(struct spdk_nvme_transport_poll_group *tgroup,
|
|
|
|
struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
if (qpair->poll_group_tailq_head == &tgroup->connected_qpairs) {
|
|
|
|
return nvme_poll_group_disconnect_qpair(qpair);
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:23:22 +00:00
|
|
|
return 0;
|
2020-02-05 20:25:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:35:31 +00:00
|
|
|
static void
|
|
|
|
nvme_rdma_poll_group_delete_qpair(struct nvme_rdma_poll_group *group,
|
|
|
|
struct nvme_rdma_destroyed_qpair *qpair_tracker)
|
|
|
|
{
|
|
|
|
struct nvme_rdma_qpair *rqpair = qpair_tracker->destroyed_qpair_tracker;
|
|
|
|
|
|
|
|
rqpair->defer_deletion_to_pg = false;
|
|
|
|
if (nvme_qpair_get_state(&rqpair->qpair) == NVME_QPAIR_DESTROYING) {
|
|
|
|
nvme_rdma_ctrlr_delete_io_qpair(rqpair->qpair.ctrlr, &rqpair->qpair);
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE(&group->destroyed_qpairs, qpair_tracker, nvme_rdma_destroyed_qpair, link);
|
|
|
|
free(qpair_tracker);
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:25:05 +00:00
|
|
|
static int64_t
|
|
|
|
nvme_rdma_poll_group_process_completions(struct spdk_nvme_transport_poll_group *tgroup,
|
2020-04-07 17:20:41 +00:00
|
|
|
uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb)
|
2020-02-05 20:25:05 +00:00
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
struct spdk_nvme_qpair *qpair, *tmp_qpair;
|
|
|
|
struct nvme_rdma_destroyed_qpair *qpair_tracker, *tmp_qpair_tracker;
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
struct nvme_rdma_poll_group *group;
|
|
|
|
struct nvme_rdma_poller *poller;
|
|
|
|
int num_qpairs = 0, batch_size, rc;
|
|
|
|
int64_t total_completions = 0;
|
|
|
|
uint64_t completions_allowed = 0;
|
|
|
|
uint64_t completions_per_poller = 0;
|
|
|
|
uint64_t poller_completions = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (completions_per_qpair == 0) {
|
|
|
|
completions_per_qpair = MAX_COMPLETIONS_PER_POLL;
|
|
|
|
}
|
2020-02-06 22:23:22 +00:00
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
group = nvme_rdma_poll_group(tgroup);
|
2020-02-06 22:23:22 +00:00
|
|
|
STAILQ_FOREACH_SAFE(qpair, &tgroup->disconnected_qpairs, poll_group_stailq, tmp_qpair) {
|
|
|
|
disconnected_qpair_cb(qpair, tgroup->group->ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_FOREACH_SAFE(qpair, &tgroup->connected_qpairs, poll_group_stailq, tmp_qpair) {
|
2020-03-05 21:47:49 +00:00
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
rqpair->num_completions = 0;
|
|
|
|
nvme_rdma_qpair_process_cm_event(rqpair);
|
|
|
|
|
|
|
|
if (spdk_unlikely(qpair->transport_failure_reason != SPDK_NVME_QPAIR_FAILURE_NONE)) {
|
|
|
|
nvme_rdma_fail_qpair(qpair, 0);
|
2020-02-06 22:23:22 +00:00
|
|
|
disconnected_qpair_cb(qpair, tgroup->group->ctx);
|
2020-03-05 21:47:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
num_qpairs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
completions_allowed = completions_per_qpair * num_qpairs;
|
|
|
|
completions_per_poller = spdk_max(completions_allowed / group->num_pollers, 1);
|
|
|
|
|
|
|
|
STAILQ_FOREACH(poller, &group->pollers, link) {
|
|
|
|
poller_completions = 0;
|
|
|
|
do {
|
|
|
|
batch_size = spdk_min((completions_per_poller - poller_completions), MAX_COMPLETIONS_PER_POLL);
|
2020-05-21 21:35:31 +00:00
|
|
|
rc = nvme_rdma_cq_process_completions(poller->cq, batch_size, group, NULL);
|
2020-03-05 21:47:49 +00:00
|
|
|
if (rc <= 0) {
|
|
|
|
if (rc == -ECANCELED) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
poller_completions += rc;
|
|
|
|
} while (poller_completions < completions_per_poller);
|
|
|
|
total_completions += poller_completions;
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_FOREACH_SAFE(qpair, &tgroup->connected_qpairs, poll_group_stailq, tmp_qpair) {
|
|
|
|
rqpair = nvme_rdma_qpair(qpair);
|
|
|
|
if (spdk_unlikely(qpair->ctrlr->timeout_enabled)) {
|
|
|
|
nvme_rdma_qpair_check_timeout(qpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_rdma_qpair_submit_sends(rqpair);
|
|
|
|
nvme_rdma_qpair_submit_recvs(rqpair);
|
|
|
|
nvme_qpair_resubmit_requests(&rqpair->qpair, rqpair->num_completions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Once a qpair is disconnected, we can still get flushed completions for those disconnected qpairs.
|
|
|
|
* For most pieces of hardware, those requests will complete immediately. However, there are certain
|
2020-05-21 21:35:31 +00:00
|
|
|
* cases where flushed requests will linger. Default is to destroy qpair after all completions are freed,
|
|
|
|
* but have a fallback for other cases where we don't get all of our completions back.
|
2020-03-05 21:47:49 +00:00
|
|
|
*/
|
|
|
|
STAILQ_FOREACH_SAFE(qpair_tracker, &group->destroyed_qpairs, link, tmp_qpair_tracker) {
|
|
|
|
qpair_tracker->completed_cycles++;
|
|
|
|
rqpair = qpair_tracker->destroyed_qpair_tracker;
|
2020-07-02 14:33:45 +00:00
|
|
|
if ((rqpair->current_num_sends == 0 && rqpair->current_num_recvs == 0) ||
|
2020-05-21 21:35:31 +00:00
|
|
|
qpair_tracker->completed_cycles > NVME_RDMA_DESTROYED_QPAIR_EXPIRATION_CYCLES) {
|
|
|
|
nvme_rdma_poll_group_delete_qpair(group, qpair_tracker);
|
2020-02-06 22:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total_completions;
|
2020-02-05 20:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvme_rdma_poll_group_destroy(struct spdk_nvme_transport_poll_group *tgroup)
|
|
|
|
{
|
2020-03-05 21:47:49 +00:00
|
|
|
struct nvme_rdma_poll_group *group = nvme_rdma_poll_group(tgroup);
|
|
|
|
struct nvme_rdma_destroyed_qpair *qpair_tracker, *tmp_qpair_tracker;
|
|
|
|
struct nvme_rdma_qpair *rqpair;
|
|
|
|
|
2020-02-06 22:23:22 +00:00
|
|
|
if (!STAILQ_EMPTY(&tgroup->connected_qpairs) || !STAILQ_EMPTY(&tgroup->disconnected_qpairs)) {
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:47:49 +00:00
|
|
|
STAILQ_FOREACH_SAFE(qpair_tracker, &group->destroyed_qpairs, link, tmp_qpair_tracker) {
|
|
|
|
rqpair = qpair_tracker->destroyed_qpair_tracker;
|
|
|
|
if (nvme_qpair_get_state(&rqpair->qpair) == NVME_QPAIR_DESTROYING) {
|
|
|
|
rqpair->defer_deletion_to_pg = false;
|
|
|
|
nvme_rdma_ctrlr_delete_io_qpair(rqpair->qpair.ctrlr, &rqpair->qpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_REMOVE(&group->destroyed_qpairs, qpair_tracker, nvme_rdma_destroyed_qpair, link);
|
|
|
|
free(qpair_tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_rdma_poll_group_free_pollers(group);
|
|
|
|
free(group);
|
2020-02-06 22:23:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2020-02-05 20:25:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:27:13 +00:00
|
|
|
void
|
|
|
|
spdk_nvme_rdma_init_hooks(struct spdk_nvme_rdma_hooks *hooks)
|
|
|
|
{
|
|
|
|
g_nvme_hooks = *hooks;
|
|
|
|
}
|
2019-12-26 17:10:02 +00:00
|
|
|
|
|
|
|
const struct spdk_nvme_transport_ops rdma_ops = {
|
|
|
|
.name = "RDMA",
|
|
|
|
.type = SPDK_NVME_TRANSPORT_RDMA,
|
|
|
|
.ctrlr_construct = nvme_rdma_ctrlr_construct,
|
|
|
|
.ctrlr_scan = nvme_fabric_ctrlr_scan,
|
|
|
|
.ctrlr_destruct = nvme_rdma_ctrlr_destruct,
|
|
|
|
.ctrlr_enable = nvme_rdma_ctrlr_enable,
|
|
|
|
|
|
|
|
.ctrlr_set_reg_4 = nvme_fabric_ctrlr_set_reg_4,
|
|
|
|
.ctrlr_set_reg_8 = nvme_fabric_ctrlr_set_reg_8,
|
|
|
|
.ctrlr_get_reg_4 = nvme_fabric_ctrlr_get_reg_4,
|
|
|
|
.ctrlr_get_reg_8 = nvme_fabric_ctrlr_get_reg_8,
|
|
|
|
|
|
|
|
.ctrlr_get_max_xfer_size = nvme_rdma_ctrlr_get_max_xfer_size,
|
|
|
|
.ctrlr_get_max_sges = nvme_rdma_ctrlr_get_max_sges,
|
|
|
|
|
|
|
|
.ctrlr_create_io_qpair = nvme_rdma_ctrlr_create_io_qpair,
|
|
|
|
.ctrlr_delete_io_qpair = nvme_rdma_ctrlr_delete_io_qpair,
|
|
|
|
.ctrlr_connect_qpair = nvme_rdma_ctrlr_connect_qpair,
|
|
|
|
.ctrlr_disconnect_qpair = nvme_rdma_ctrlr_disconnect_qpair,
|
|
|
|
|
|
|
|
.qpair_abort_reqs = nvme_rdma_qpair_abort_reqs,
|
|
|
|
.qpair_reset = nvme_rdma_qpair_reset,
|
|
|
|
.qpair_submit_request = nvme_rdma_qpair_submit_request,
|
|
|
|
.qpair_process_completions = nvme_rdma_qpair_process_completions,
|
2020-05-17 22:05:51 +00:00
|
|
|
.qpair_iterate_requests = nvme_rdma_qpair_iterate_requests,
|
2019-12-26 17:10:02 +00:00
|
|
|
.admin_qpair_abort_aers = nvme_rdma_admin_qpair_abort_aers,
|
2020-02-05 20:25:05 +00:00
|
|
|
|
|
|
|
.poll_group_create = nvme_rdma_poll_group_create,
|
2020-04-07 17:20:41 +00:00
|
|
|
.poll_group_connect_qpair = nvme_rdma_poll_group_connect_qpair,
|
|
|
|
.poll_group_disconnect_qpair = nvme_rdma_poll_group_disconnect_qpair,
|
2020-02-05 20:25:05 +00:00
|
|
|
.poll_group_add = nvme_rdma_poll_group_add,
|
|
|
|
.poll_group_remove = nvme_rdma_poll_group_remove,
|
|
|
|
.poll_group_process_completions = nvme_rdma_poll_group_process_completions,
|
|
|
|
.poll_group_destroy = nvme_rdma_poll_group_destroy,
|
|
|
|
|
2019-12-26 17:10:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SPDK_NVME_TRANSPORT_REGISTER(rdma, &rdma_ops);
|