2016-11-03 22:34:35 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NVMe transport abstraction
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nvme_internal.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static __attribute__((noreturn)) void
|
2016-11-30 21:21:33 +00:00
|
|
|
nvme_transport_unknown(enum spdk_nvme_transport_type trtype)
|
2016-11-03 22:34:35 +00:00
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
SPDK_ERRLOG("Unknown transport %d\n", (int)trtype);
|
2016-11-03 22:34:35 +00:00
|
|
|
abort();
|
|
|
|
}
|
2016-11-30 21:21:33 +00:00
|
|
|
#define TRANSPORT_DEFAULT(trtype) default: nvme_transport_unknown(trtype);
|
2016-11-03 22:34:35 +00:00
|
|
|
#else
|
2016-11-30 21:21:33 +00:00
|
|
|
#define TRANSPORT_DEFAULT(trtype)
|
2016-11-03 22:34:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TRANSPORT_PCIE(func_name, args) case SPDK_NVME_TRANSPORT_PCIE: return nvme_pcie_ ## func_name args;
|
2018-08-02 02:21:45 +00:00
|
|
|
|
|
|
|
#define TRANSPORT_FABRICS_TCP(func_name, args) case SPDK_NVME_TRANSPORT_TCP: return nvme_tcp_ ## func_name args;
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
#ifdef SPDK_CONFIG_RDMA
|
|
|
|
#define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: return nvme_rdma_ ## func_name args;
|
2016-11-21 23:32:23 +00:00
|
|
|
#define TRANSPORT_RDMA_AVAILABLE true
|
2016-11-15 05:42:59 +00:00
|
|
|
#else
|
2016-11-18 21:43:16 +00:00
|
|
|
#define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: SPDK_UNREACHABLE();
|
2016-11-21 23:32:23 +00:00
|
|
|
#define TRANSPORT_RDMA_AVAILABLE false
|
2016-11-15 05:42:59 +00:00
|
|
|
#endif
|
2018-06-19 22:33:52 +00:00
|
|
|
#define TRANSPORT_FABRICS_FC(func_name, args) case SPDK_NVME_TRANSPORT_FC: SPDK_UNREACHABLE();
|
2018-08-02 02:21:45 +00:00
|
|
|
|
2018-03-02 19:49:36 +00:00
|
|
|
#define NVME_TRANSPORT_CALL(trtype, func_name, args) \
|
2016-11-03 22:34:35 +00:00
|
|
|
do { \
|
2016-11-30 21:21:33 +00:00
|
|
|
switch (trtype) { \
|
2016-11-03 22:34:35 +00:00
|
|
|
TRANSPORT_PCIE(func_name, args) \
|
2016-11-15 05:42:59 +00:00
|
|
|
TRANSPORT_FABRICS_RDMA(func_name, args) \
|
2018-06-19 22:33:52 +00:00
|
|
|
TRANSPORT_FABRICS_FC(func_name, args) \
|
2018-08-02 02:21:45 +00:00
|
|
|
TRANSPORT_FABRICS_TCP(func_name, args) \
|
2016-11-30 21:21:33 +00:00
|
|
|
TRANSPORT_DEFAULT(trtype) \
|
2016-11-03 22:34:35 +00:00
|
|
|
} \
|
|
|
|
SPDK_UNREACHABLE(); \
|
|
|
|
} while (0)
|
|
|
|
|
2016-11-21 23:32:23 +00:00
|
|
|
bool
|
2016-11-30 21:57:00 +00:00
|
|
|
spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
|
2016-11-21 23:32:23 +00:00
|
|
|
{
|
|
|
|
switch (trtype) {
|
2016-11-30 21:57:00 +00:00
|
|
|
case SPDK_NVME_TRANSPORT_PCIE:
|
2018-08-02 02:21:45 +00:00
|
|
|
case SPDK_NVME_TRANSPORT_TCP:
|
2016-11-30 21:57:00 +00:00
|
|
|
return true;
|
2016-11-21 23:32:23 +00:00
|
|
|
|
2016-11-30 21:57:00 +00:00
|
|
|
case SPDK_NVME_TRANSPORT_RDMA:
|
|
|
|
return TRANSPORT_RDMA_AVAILABLE;
|
2018-06-19 22:33:52 +00:00
|
|
|
|
|
|
|
case SPDK_NVME_TRANSPORT_FC:
|
|
|
|
return false;
|
2016-11-21 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-03 22:34:35 +00:00
|
|
|
|
2016-12-09 22:14:45 +00:00
|
|
|
struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
|
|
|
|
const struct spdk_nvme_ctrlr_opts *opts,
|
|
|
|
void *devhandle)
|
2016-11-03 22:34:35 +00:00
|
|
|
{
|
2016-12-09 22:14:45 +00:00
|
|
|
NVME_TRANSPORT_CALL(trid->trtype, ctrlr_construct, (trid, opts, devhandle));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:42:59 +00:00
|
|
|
int
|
2019-01-28 09:16:47 +00:00
|
|
|
nvme_transport_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
|
2017-07-21 03:01:03 +00:00
|
|
|
bool direct_connect)
|
2016-11-15 05:42:59 +00:00
|
|
|
{
|
2019-01-28 09:16:47 +00:00
|
|
|
NVME_TRANSPORT_CALL(probe_ctx->trid.trtype, ctrlr_scan, (probe_ctx, direct_connect));
|
2016-12-05 17:59:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 22:34:35 +00:00
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_destruct, (ctrlr));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_enable, (ctrlr));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_4, (ctrlr, offset, value));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_8, (ctrlr, offset, value));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_4, (ctrlr, offset, value));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_8, (ctrlr, offset, value));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nvme_transport_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_xfer_size, (ctrlr));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:03:06 +00:00
|
|
|
uint16_t
|
|
|
|
nvme_transport_ctrlr_get_max_sges(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_sges, (ctrlr));
|
|
|
|
}
|
|
|
|
|
2017-04-21 23:35:11 +00:00
|
|
|
void *
|
|
|
|
nvme_transport_ctrlr_alloc_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, size_t size)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_alloc_cmb_io_buffer, (ctrlr, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_free_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_free_cmb_io_buffer, (ctrlr, buf, size));
|
|
|
|
}
|
|
|
|
|
2016-11-03 22:34:35 +00:00
|
|
|
struct spdk_nvme_qpair *
|
|
|
|
nvme_transport_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-03 22:34:35 +00:00
|
|
|
{
|
2017-07-14 23:08:05 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_create_io_qpair, (ctrlr, qid, opts));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-12-09 22:09:28 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_delete_io_qpair, (ctrlr, qpair));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-05-09 19:05:24 +00:00
|
|
|
nvme_transport_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
2016-11-03 22:34:35 +00:00
|
|
|
{
|
2019-05-09 23:45:46 +00:00
|
|
|
if (nvme_qpair_is_admin_queue(qpair)) {
|
|
|
|
qpair->is_connecting = 1;
|
|
|
|
}
|
2019-05-09 19:05:24 +00:00
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_connect_qpair, (ctrlr, qpair));
|
2019-05-09 23:45:46 +00:00
|
|
|
if (nvme_qpair_is_admin_queue(qpair)) {
|
|
|
|
qpair->is_connecting = 0;
|
|
|
|
}
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 22:40:32 +00:00
|
|
|
volatile struct spdk_nvme_registers *
|
|
|
|
nvme_transport_ctrlr_get_registers(struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_registers, (ctrlr));
|
|
|
|
}
|
|
|
|
|
2019-05-09 19:08:42 +00:00
|
|
|
void
|
|
|
|
nvme_transport_ctrlr_disconnect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_disconnect_qpair, (ctrlr, qpair));
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:14:24 +00:00
|
|
|
void
|
|
|
|
nvme_transport_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr)
|
2016-11-03 22:34:35 +00:00
|
|
|
{
|
2019-05-06 23:14:24 +00:00
|
|
|
assert(dnr <= 1);
|
|
|
|
NVME_TRANSPORT_CALL(qpair->trtype, qpair_abort_reqs, (qpair, dnr));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_qpair_reset(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
NVME_TRANSPORT_CALL(qpair->trtype, qpair_reset, (qpair));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvme_transport_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *req)
|
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
NVME_TRANSPORT_CALL(qpair->trtype, qpair_submit_request, (qpair, req));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
nvme_transport_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions)
|
|
|
|
{
|
2016-11-30 21:21:33 +00:00
|
|
|
NVME_TRANSPORT_CALL(qpair->trtype, qpair_process_completions, (qpair, max_completions));
|
2016-11-03 22:34:35 +00:00
|
|
|
}
|
2019-05-06 22:29:24 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nvme_transport_admin_qpair_abort_aers(struct spdk_nvme_qpair *qpair)
|
|
|
|
{
|
|
|
|
NVME_TRANSPORT_CALL(qpair->trtype, admin_qpair_abort_aers, (qpair));
|
|
|
|
}
|