nvme: Eliminate nvme_impl.h and use the swappable env lib.
Change-Id: Ibbc557b732d5b0858a2922a7a442c4b17a0d579a Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
e0196e8124
commit
bfdc02ab48
4
CONFIG
4
CONFIG
@ -53,10 +53,6 @@ CONFIG_ENV?=$(SPDK_ROOT_DIR)/lib/env
|
||||
# when using the default SPDK environment library.
|
||||
CONFIG_DPDK_DIR?=/path/to/dpdk
|
||||
|
||||
# Header file to use for NVMe implementation specific functions.
|
||||
# Defaults to depending on DPDK.
|
||||
CONFIG_NVME_IMPL?=nvme_impl.h
|
||||
|
||||
# Build SPDK FIO plugin. Requires FIO_SOURCE_DIR set to a valid
|
||||
# fio source code directory.
|
||||
CONFIG_FIO_PLUGIN?=n
|
||||
|
@ -758,8 +758,7 @@ WARN_LOGFILE =
|
||||
# spaces.
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = ../lib/nvme/nvme_impl.h \
|
||||
../include/spdk \
|
||||
INPUT = ../include/spdk \
|
||||
mainpage.txt \
|
||||
ioat/index.txt \
|
||||
nvme/index.txt \
|
||||
|
@ -56,7 +56,7 @@ void *
|
||||
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
|
||||
|
||||
/**
|
||||
* Free a memory buffer previously allocated with spdk_malloc.
|
||||
* Free a memory buffer previously allocated with spdk_zmalloc.
|
||||
* This call is never made from the performance path.
|
||||
*/
|
||||
void
|
||||
|
@ -34,7 +34,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
CFLAGS += $(ENV_CFLAGS) -include $(CONFIG_NVME_IMPL)
|
||||
CFLAGS += $(ENV_CFLAGS)
|
||||
C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_ns_cmd.c nvme_ns.c nvme_qpair.c nvme.c nvme_intel.c
|
||||
LIBNAME = nvme
|
||||
|
||||
|
@ -51,8 +51,8 @@ nvme_attach(void *devhandle)
|
||||
int status;
|
||||
uint64_t phys_addr = 0;
|
||||
|
||||
ctrlr = nvme_malloc(sizeof(struct spdk_nvme_ctrlr),
|
||||
64, &phys_addr);
|
||||
ctrlr = spdk_zmalloc(sizeof(struct spdk_nvme_ctrlr),
|
||||
64, &phys_addr);
|
||||
if (ctrlr == NULL) {
|
||||
SPDK_ERRLOG("could not allocate ctrlr\n");
|
||||
return NULL;
|
||||
@ -60,7 +60,7 @@ nvme_attach(void *devhandle)
|
||||
|
||||
status = nvme_ctrlr_construct(ctrlr, devhandle);
|
||||
if (status != 0) {
|
||||
nvme_free(ctrlr);
|
||||
spdk_free(ctrlr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr)
|
||||
|
||||
nvme_ctrlr_destruct(ctrlr);
|
||||
TAILQ_REMOVE(&g_spdk_nvme_driver->attached_ctrlrs, ctrlr, tailq);
|
||||
nvme_free(ctrlr);
|
||||
spdk_free(ctrlr);
|
||||
|
||||
pthread_mutex_unlock(&g_spdk_nvme_driver->lock);
|
||||
return 0;
|
||||
@ -100,7 +100,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size,
|
||||
{
|
||||
struct nvme_request *req = NULL;
|
||||
|
||||
req = nvme_mempool_get(g_spdk_nvme_driver->request_mempool);
|
||||
req = spdk_mempool_get(g_spdk_nvme_driver->request_mempool);
|
||||
if (req == NULL) {
|
||||
return req;
|
||||
}
|
||||
@ -156,7 +156,7 @@ nvme_user_copy_cmd_complete(void *arg, const struct spdk_nvme_cpl *cpl)
|
||||
memcpy(req->user_buffer, req->payload.u.contig, req->payload_size);
|
||||
}
|
||||
|
||||
nvme_free(req->payload.u.contig);
|
||||
spdk_free(req->payload.u.contig);
|
||||
}
|
||||
|
||||
/* Call the user's original callback now that the buffer has been copied */
|
||||
@ -178,7 +178,7 @@ nvme_allocate_request_user_copy(void *buffer, uint32_t payload_size, spdk_nvme_c
|
||||
uint64_t phys_addr;
|
||||
|
||||
if (buffer && payload_size) {
|
||||
contig_buffer = nvme_malloc(payload_size, 4096, &phys_addr);
|
||||
contig_buffer = spdk_zmalloc(payload_size, 4096, &phys_addr);
|
||||
if (!contig_buffer) {
|
||||
return NULL;
|
||||
}
|
||||
@ -190,7 +190,7 @@ nvme_allocate_request_user_copy(void *buffer, uint32_t payload_size, spdk_nvme_c
|
||||
|
||||
req = nvme_allocate_request_contig(contig_buffer, payload_size, nvme_user_copy_cmd_complete, NULL);
|
||||
if (!req) {
|
||||
nvme_free(buffer);
|
||||
spdk_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ nvme_free_request(struct nvme_request *req)
|
||||
assert(req != NULL);
|
||||
assert(req->num_children == 0);
|
||||
|
||||
nvme_mempool_put(g_spdk_nvme_driver->request_mempool, req);
|
||||
spdk_mempool_put(g_spdk_nvme_driver->request_mempool, req);
|
||||
}
|
||||
|
||||
int
|
||||
@ -279,7 +279,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
|
||||
pthread_mutex_lock(&g_spdk_nvme_driver->lock);
|
||||
|
||||
if (g_spdk_nvme_driver->request_mempool == NULL) {
|
||||
g_spdk_nvme_driver->request_mempool = nvme_mempool_create("nvme_request", 8192,
|
||||
g_spdk_nvme_driver->request_mempool = spdk_mempool_create("nvme_request", 8192,
|
||||
sizeof(struct nvme_request), -1);
|
||||
if (g_spdk_nvme_driver->request_mempool == NULL) {
|
||||
SPDK_ERRLOG("Unable to allocate pool of requests\n");
|
||||
@ -316,7 +316,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
|
||||
/* Controller failed to initialize. */
|
||||
TAILQ_REMOVE(&g_spdk_nvme_driver->init_ctrlrs, ctrlr, tailq);
|
||||
nvme_ctrlr_destruct(ctrlr);
|
||||
nvme_free(ctrlr);
|
||||
spdk_free(ctrlr);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -247,8 +247,8 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr)
|
||||
struct nvme_completion_poll_status status;
|
||||
struct spdk_nvme_intel_log_page_directory *log_page_directory;
|
||||
|
||||
log_page_directory = nvme_malloc(sizeof(struct spdk_nvme_intel_log_page_directory),
|
||||
64, &phys_addr);
|
||||
log_page_directory = spdk_zmalloc(sizeof(struct spdk_nvme_intel_log_page_directory),
|
||||
64, &phys_addr);
|
||||
if (log_page_directory == NULL) {
|
||||
SPDK_ERRLOG("could not allocate log_page_directory\n");
|
||||
return -ENXIO;
|
||||
@ -263,13 +263,13 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr)
|
||||
spdk_nvme_qpair_process_completions(&ctrlr->adminq, 0);
|
||||
}
|
||||
if (spdk_nvme_cpl_is_error(&status.cpl)) {
|
||||
nvme_free(log_page_directory);
|
||||
spdk_free(log_page_directory);
|
||||
SPDK_ERRLOG("nvme_ctrlr_cmd_get_log_page failed!\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
nvme_ctrlr_construct_intel_support_log_page_list(ctrlr, log_page_directory);
|
||||
nvme_free(log_page_directory);
|
||||
spdk_free(log_page_directory);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -374,8 +374,8 @@ nvme_ctrlr_construct_io_qpairs(struct spdk_nvme_ctrlr *ctrlr)
|
||||
*/
|
||||
num_trackers = nvme_min(NVME_IO_TRACKERS, (num_entries - 1));
|
||||
|
||||
ctrlr->ioq = nvme_malloc(ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair),
|
||||
64, &phys_addr);
|
||||
ctrlr->ioq = spdk_zmalloc(ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair),
|
||||
64, &phys_addr);
|
||||
|
||||
if (ctrlr->ioq == NULL)
|
||||
return -1;
|
||||
@ -509,7 +509,7 @@ nvme_ctrlr_set_state(struct spdk_nvme_ctrlr *ctrlr, enum nvme_ctrlr_state state,
|
||||
if (timeout_in_ms == NVME_TIMEOUT_INFINITE) {
|
||||
ctrlr->state_timeout_tsc = NVME_TIMEOUT_INFINITE;
|
||||
} else {
|
||||
ctrlr->state_timeout_tsc = nvme_get_tsc() + (timeout_in_ms * nvme_get_tsc_hz()) / 1000;
|
||||
ctrlr->state_timeout_tsc = spdk_get_ticks() + (timeout_in_ms * spdk_get_ticks_hz()) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,13 +660,13 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
||||
nvme_ns_destruct(&ctrlr->ns[i]);
|
||||
}
|
||||
|
||||
nvme_free(ctrlr->ns);
|
||||
spdk_free(ctrlr->ns);
|
||||
ctrlr->ns = NULL;
|
||||
ctrlr->num_ns = 0;
|
||||
}
|
||||
|
||||
if (ctrlr->nsdata) {
|
||||
nvme_free(ctrlr->nsdata);
|
||||
spdk_free(ctrlr->nsdata);
|
||||
ctrlr->nsdata = NULL;
|
||||
}
|
||||
}
|
||||
@ -688,14 +688,14 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
||||
if (nn != ctrlr->num_ns) {
|
||||
nvme_ctrlr_destruct_namespaces(ctrlr);
|
||||
|
||||
ctrlr->ns = nvme_malloc(nn * sizeof(struct spdk_nvme_ns), 64,
|
||||
&phys_addr);
|
||||
ctrlr->ns = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns), 64,
|
||||
&phys_addr);
|
||||
if (ctrlr->ns == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ctrlr->nsdata = nvme_malloc(nn * sizeof(struct spdk_nvme_ns_data), 64,
|
||||
&phys_addr);
|
||||
ctrlr->nsdata = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns_data), 64,
|
||||
&phys_addr);
|
||||
if (ctrlr->nsdata == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
@ -907,7 +907,7 @@ nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr)
|
||||
}
|
||||
|
||||
if (ctrlr->state_timeout_tsc != NVME_TIMEOUT_INFINITE &&
|
||||
nvme_get_tsc() > ctrlr->state_timeout_tsc) {
|
||||
spdk_get_ticks() > ctrlr->state_timeout_tsc) {
|
||||
SPDK_ERRLOG("Initialization timed out in state %d\n", ctrlr->state);
|
||||
nvme_ctrlr_fail(ctrlr);
|
||||
return -1;
|
||||
@ -1163,7 +1163,7 @@ nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
|
||||
}
|
||||
}
|
||||
|
||||
nvme_free(ctrlr->ioq);
|
||||
spdk_free(ctrlr->ioq);
|
||||
|
||||
nvme_qpair_destroy(&ctrlr->adminq);
|
||||
|
||||
|
@ -1,140 +0,0 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* NVMe driver integration callbacks
|
||||
*
|
||||
* This file describes the callback functions required to integrate
|
||||
* the userspace NVMe driver for a specific implementation. This
|
||||
* implementation is specific for DPDK. Users would
|
||||
* revise it as necessary for their own particular environment if not
|
||||
* using it within the DPDK framework.
|
||||
*/
|
||||
|
||||
#ifndef __NVME_IMPL_H__
|
||||
#define __NVME_IMPL_H__
|
||||
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/nvme_spec.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <rte_config.h>
|
||||
#include <rte_mempool.h>
|
||||
#include <rte_version.h>
|
||||
#include <rte_eal.h>
|
||||
|
||||
#include "spdk/pci_ids.h"
|
||||
|
||||
/**
|
||||
* \page nvme_driver_integration NVMe Driver Integration
|
||||
*
|
||||
* Users can integrate the userspace NVMe driver into their environment
|
||||
* by implementing the callbacks in nvme_impl.h. These callbacks
|
||||
* enable users to specify how to allocate pinned and physically
|
||||
* contiguous memory, performance virtual to physical address
|
||||
* translations, log messages, PCI configuration and register mapping,
|
||||
* and a number of other facilities that may differ depending on the
|
||||
* environment.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate a pinned, physically contiguous memory buffer with the
|
||||
* given size and alignment.
|
||||
* Note: these calls are only made during driver initialization.
|
||||
*/
|
||||
#define nvme_malloc spdk_zmalloc
|
||||
|
||||
/**
|
||||
* Free a memory buffer previously allocated with nvme_malloc.
|
||||
*/
|
||||
#define nvme_free spdk_free
|
||||
|
||||
/**
|
||||
* Reserve a named, process shared memory zone with the given size,
|
||||
* socket_id and flags.
|
||||
* Return a pointer to the allocated memory address. If the allocation
|
||||
* cannot be done, return NULL.
|
||||
*/
|
||||
#define nvme_memzone_reserve spdk_memzone_reserve
|
||||
|
||||
/**
|
||||
* Lookup the memory zone identified by the given name.
|
||||
* Return a pointer to the reserved memory address. If the reservation
|
||||
* cannot be found, return NULL.
|
||||
*/
|
||||
#define nvme_memzone_lookup spdk_memzone_lookup
|
||||
|
||||
/**
|
||||
* Free the memory zone identified by the given name.
|
||||
*/
|
||||
#define nvme_memzone_free spdk_memzone_free
|
||||
|
||||
/**
|
||||
* Return true if the calling process is primary process
|
||||
*/
|
||||
#define nvme_process_is_primary spdk_process_is_primary
|
||||
|
||||
/**
|
||||
* Return the physical address for the specified virtual address.
|
||||
*/
|
||||
#define nvme_vtophys(buf) spdk_vtophys(buf)
|
||||
#define NVME_VTOPHYS_ERROR SPDK_VTOPHYS_ERROR
|
||||
|
||||
typedef struct spdk_mempool nvme_mempool_t;
|
||||
|
||||
/**
|
||||
* Create a mempool with the given configuration.
|
||||
* Return a pointer to the allocated memory address. If the allocation
|
||||
* cannot be done, return NULL.
|
||||
*/
|
||||
#define nvme_mempool_create spdk_mempool_create
|
||||
#define nvme_mempool_free spdk_mempool_free
|
||||
#define nvme_mempool_get spdk_mempool_get
|
||||
#define nvme_mempool_put spdk_mempool_put
|
||||
|
||||
/**
|
||||
* Get a monotonic timestamp counter (used for measuring timeouts during initialization).
|
||||
*/
|
||||
#define nvme_get_tsc() spdk_get_ticks()
|
||||
|
||||
/**
|
||||
* Get the tick rate of nvme_get_tsc() per second.
|
||||
*/
|
||||
#define nvme_get_tsc_hz() spdk_get_ticks_hz()
|
||||
|
||||
#endif /* __NVME_IMPL_H__ */
|
@ -465,7 +465,7 @@ struct nvme_driver {
|
||||
pthread_mutex_t lock;
|
||||
TAILQ_HEAD(, spdk_nvme_ctrlr) init_ctrlrs;
|
||||
TAILQ_HEAD(, spdk_nvme_ctrlr) attached_ctrlrs;
|
||||
nvme_mempool_t *request_mempool;
|
||||
struct spdk_mempool *request_mempool;
|
||||
};
|
||||
|
||||
struct pci_id {
|
||||
|
@ -556,18 +556,18 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id,
|
||||
}
|
||||
}
|
||||
if (qpair->sq_in_cmb == false) {
|
||||
qpair->cmd = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cmd),
|
||||
0x1000,
|
||||
&qpair->cmd_bus_addr);
|
||||
qpair->cmd = spdk_zmalloc(qpair->num_entries * sizeof(struct spdk_nvme_cmd),
|
||||
0x1000,
|
||||
&qpair->cmd_bus_addr);
|
||||
if (qpair->cmd == NULL) {
|
||||
SPDK_ERRLOG("alloc qpair_cmd failed\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
qpair->cpl = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cpl),
|
||||
0x1000,
|
||||
&qpair->cpl_bus_addr);
|
||||
qpair->cpl = spdk_zmalloc(qpair->num_entries * sizeof(struct spdk_nvme_cpl),
|
||||
0x1000,
|
||||
&qpair->cpl_bus_addr);
|
||||
if (qpair->cpl == NULL) {
|
||||
SPDK_ERRLOG("alloc qpair_cpl failed\n");
|
||||
goto fail;
|
||||
@ -587,7 +587,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id,
|
||||
* This ensures the PRP list embedded in the nvme_tracker object will not span a
|
||||
* 4KB boundary, while allowing access to trackers in tr[] via normal array indexing.
|
||||
*/
|
||||
qpair->tr = nvme_malloc(num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr);
|
||||
qpair->tr = spdk_zmalloc(num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr);
|
||||
if (qpair->tr == NULL) {
|
||||
SPDK_ERRLOG("nvme_tr failed\n");
|
||||
goto fail;
|
||||
@ -640,15 +640,15 @@ nvme_qpair_destroy(struct spdk_nvme_qpair *qpair)
|
||||
_nvme_admin_qpair_destroy(qpair);
|
||||
}
|
||||
if (qpair->cmd && !qpair->sq_in_cmb) {
|
||||
nvme_free(qpair->cmd);
|
||||
spdk_free(qpair->cmd);
|
||||
qpair->cmd = NULL;
|
||||
}
|
||||
if (qpair->cpl) {
|
||||
nvme_free(qpair->cpl);
|
||||
spdk_free(qpair->cpl);
|
||||
qpair->cpl = NULL;
|
||||
}
|
||||
if (qpair->tr) {
|
||||
nvme_free(qpair->tr);
|
||||
spdk_free(qpair->tr);
|
||||
qpair->tr = NULL;
|
||||
}
|
||||
}
|
||||
@ -678,8 +678,8 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ
|
||||
void *md_payload;
|
||||
void *payload = req->payload.u.contig + req->payload_offset;
|
||||
|
||||
phys_addr = nvme_vtophys(payload);
|
||||
if (phys_addr == NVME_VTOPHYS_ERROR) {
|
||||
phys_addr = spdk_vtophys(payload);
|
||||
if (phys_addr == SPDK_VTOPHYS_ERROR) {
|
||||
_nvme_fail_request_bad_vtophys(qpair, tr);
|
||||
return -1;
|
||||
}
|
||||
@ -692,8 +692,8 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ
|
||||
|
||||
if (req->payload.md) {
|
||||
md_payload = req->payload.md + req->md_offset;
|
||||
tr->req->cmd.mptr = nvme_vtophys(md_payload);
|
||||
if (tr->req->cmd.mptr == NVME_VTOPHYS_ERROR) {
|
||||
tr->req->cmd.mptr = spdk_vtophys(md_payload);
|
||||
if (tr->req->cmd.mptr == SPDK_VTOPHYS_ERROR) {
|
||||
_nvme_fail_request_bad_vtophys(qpair, tr);
|
||||
return -1;
|
||||
}
|
||||
@ -703,14 +703,14 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ
|
||||
tr->req->cmd.dptr.prp.prp1 = phys_addr;
|
||||
if (nseg == 2) {
|
||||
seg_addr = payload + PAGE_SIZE - unaligned;
|
||||
tr->req->cmd.dptr.prp.prp2 = nvme_vtophys(seg_addr);
|
||||
tr->req->cmd.dptr.prp.prp2 = spdk_vtophys(seg_addr);
|
||||
} else if (nseg > 2) {
|
||||
cur_nseg = 1;
|
||||
tr->req->cmd.dptr.prp.prp2 = (uint64_t)tr->prp_sgl_bus_addr;
|
||||
while (cur_nseg < nseg) {
|
||||
seg_addr = payload + cur_nseg * PAGE_SIZE - unaligned;
|
||||
phys_addr = nvme_vtophys(seg_addr);
|
||||
if (phys_addr == NVME_VTOPHYS_ERROR) {
|
||||
phys_addr = spdk_vtophys(seg_addr);
|
||||
if (phys_addr == SPDK_VTOPHYS_ERROR) {
|
||||
_nvme_fail_request_bad_vtophys(qpair, tr);
|
||||
return -1;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
C_SRCS = $(TEST_FILE) $(OTHER_FILES)
|
||||
|
||||
CFLAGS += -I$(SPDK_ROOT_DIR)/lib -include $(SPDK_ROOT_DIR)/test/lib/nvme/unit/nvme_impl.h
|
||||
CFLAGS += -I$(SPDK_ROOT_DIR)/lib
|
||||
CFLAGS += -I$(SPDK_ROOT_DIR)/test
|
||||
|
||||
SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a
|
||||
|
@ -37,6 +37,8 @@
|
||||
|
||||
#include "nvme/nvme.c"
|
||||
|
||||
#include "lib/nvme/unit/test_env.c"
|
||||
|
||||
int
|
||||
spdk_pci_enumerate(enum spdk_pci_device_type type,
|
||||
spdk_pci_enum_cb enum_cb,
|
||||
@ -45,11 +47,6 @@ spdk_pci_enumerate(enum spdk_pci_device_type type,
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t nvme_vtophys(void *buf)
|
||||
{
|
||||
return (uintptr_t)buf;
|
||||
}
|
||||
|
||||
int
|
||||
nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr, void *devhandle)
|
||||
{
|
||||
|
@ -35,6 +35,8 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "lib/nvme/unit/test_env.c"
|
||||
|
||||
bool trace_flag = false;
|
||||
#define SPDK_TRACE_NVME trace_flag
|
||||
|
||||
@ -154,7 +156,7 @@ nvme_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *re
|
||||
* Free the request here so it does not leak.
|
||||
* For the purposes of this unit test, we don't need to bother emulating request submission.
|
||||
*/
|
||||
nvme_mempool_put(_g_nvme_driver.request_mempool, req);
|
||||
spdk_mempool_put(_g_nvme_driver.request_mempool, req);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -321,7 +323,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size,
|
||||
void *cb_arg)
|
||||
{
|
||||
struct nvme_request *req = NULL;
|
||||
req = nvme_mempool_get(_g_nvme_driver.request_mempool);
|
||||
req = spdk_mempool_get(_g_nvme_driver.request_mempool);
|
||||
|
||||
if (req != NULL) {
|
||||
memset(req, 0, offsetof(struct nvme_request, children));
|
||||
|
@ -35,6 +35,8 @@
|
||||
|
||||
#include "nvme/nvme_ns_cmd.c"
|
||||
|
||||
#include "lib/nvme/unit/test_env.c"
|
||||
|
||||
struct nvme_request *g_request = NULL;
|
||||
|
||||
|
||||
@ -55,11 +57,6 @@ static int nvme_request_next_sge(void *cb_arg, uint64_t *address, uint32_t *leng
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t nvme_vtophys(void *buf)
|
||||
{
|
||||
return (uintptr_t)buf;
|
||||
}
|
||||
|
||||
int
|
||||
nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr, void *devhandle)
|
||||
{
|
||||
@ -484,7 +481,7 @@ test_nvme_ns_cmd_dataset_management(void)
|
||||
CU_ASSERT(g_request->cmd.nsid == ns.id);
|
||||
CU_ASSERT(g_request->cmd.cdw10 == 0);
|
||||
CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE);
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
|
||||
/* TRIM 256 LBAs */
|
||||
@ -496,7 +493,7 @@ test_nvme_ns_cmd_dataset_management(void)
|
||||
CU_ASSERT(g_request->cmd.nsid == ns.id);
|
||||
CU_ASSERT(g_request->cmd.cdw10 == 255u);
|
||||
CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE);
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
|
||||
rc = spdk_nvme_ns_cmd_dataset_management(&ns, &qpair, SPDK_NVME_DSM_ATTR_DEALLOCATE,
|
||||
@ -635,7 +632,7 @@ test_nvme_ns_cmd_reservation_register(void)
|
||||
|
||||
CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10);
|
||||
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
free(payload);
|
||||
}
|
||||
@ -672,7 +669,7 @@ test_nvme_ns_cmd_reservation_release(void)
|
||||
|
||||
CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10);
|
||||
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
free(payload);
|
||||
}
|
||||
@ -709,7 +706,7 @@ test_nvme_ns_cmd_reservation_acquire(void)
|
||||
|
||||
CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10);
|
||||
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
free(payload);
|
||||
}
|
||||
@ -738,7 +735,7 @@ test_nvme_ns_cmd_reservation_report(void)
|
||||
|
||||
CU_ASSERT(g_request->cmd.cdw10 == (0x1000 / 4));
|
||||
|
||||
nvme_free(g_request->payload.u.contig);
|
||||
spdk_free(g_request->payload.u.contig);
|
||||
nvme_free_request(g_request);
|
||||
free(payload);
|
||||
}
|
||||
|
@ -37,6 +37,8 @@
|
||||
|
||||
#include "spdk_cunit.h"
|
||||
|
||||
#include "lib/nvme/unit/test_env.c"
|
||||
|
||||
bool trace_flag = false;
|
||||
#define SPDK_TRACE_NVME trace_flag
|
||||
|
||||
@ -51,19 +53,10 @@ int32_t spdk_nvme_retry_count = 1;
|
||||
|
||||
struct nvme_request *g_request = NULL;
|
||||
|
||||
bool fail_vtophys = false;
|
||||
extern bool ut_fail_vtophys;
|
||||
|
||||
bool fail_next_sge = false;
|
||||
|
||||
uint64_t nvme_vtophys(void *buf)
|
||||
{
|
||||
if (fail_vtophys) {
|
||||
return (uint64_t) - 1;
|
||||
} else {
|
||||
return (uintptr_t)buf;
|
||||
}
|
||||
}
|
||||
|
||||
struct io_request {
|
||||
uint64_t address_offset;
|
||||
bool invalid_addr;
|
||||
@ -132,7 +125,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size,
|
||||
{
|
||||
struct nvme_request *req = NULL;
|
||||
|
||||
req = nvme_mempool_get(_g_nvme_driver.request_mempool);
|
||||
req = spdk_mempool_get(_g_nvme_driver.request_mempool);
|
||||
|
||||
if (req == NULL) {
|
||||
return req;
|
||||
@ -176,7 +169,7 @@ nvme_allocate_request_null(spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
||||
void
|
||||
nvme_free_request(struct nvme_request *req)
|
||||
{
|
||||
nvme_mempool_put(_g_nvme_driver.request_mempool, req);
|
||||
spdk_mempool_put(_g_nvme_driver.request_mempool, req);
|
||||
}
|
||||
|
||||
void
|
||||
@ -208,7 +201,7 @@ prepare_submit_request_test(struct spdk_nvme_qpair *qpair,
|
||||
CU_ASSERT(qpair->sq_tail == 0);
|
||||
CU_ASSERT(qpair->cq_head == 0);
|
||||
|
||||
fail_vtophys = false;
|
||||
ut_fail_vtophys = false;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -224,7 +217,7 @@ ut_insert_cq_entry(struct spdk_nvme_qpair *qpair, uint32_t slot)
|
||||
struct nvme_tracker *tr;
|
||||
struct spdk_nvme_cpl *cpl;
|
||||
|
||||
req = nvme_mempool_get(_g_nvme_driver.request_mempool);
|
||||
req = spdk_mempool_get(_g_nvme_driver.request_mempool);
|
||||
SPDK_CU_ASSERT_FATAL(req != NULL);
|
||||
memset(req, 0, sizeof(*req));
|
||||
|
||||
@ -310,7 +303,7 @@ test4(void)
|
||||
* the request with error status to signify
|
||||
* a bad payload buffer.
|
||||
*/
|
||||
fail_vtophys = true;
|
||||
ut_fail_vtophys = true;
|
||||
|
||||
CU_ASSERT(qpair.sq_tail == 0);
|
||||
|
||||
|
@ -31,22 +31,15 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __NVME_IMPL_H__
|
||||
#define __NVME_IMPL_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "spdk/nvme_spec.h"
|
||||
#include "spdk/env.h"
|
||||
|
||||
struct spdk_pci_device;
|
||||
|
||||
static inline void *
|
||||
nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr)
|
||||
void *
|
||||
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr)
|
||||
{
|
||||
void *buf = NULL;
|
||||
if (posix_memalign(&buf, align, size)) {
|
||||
@ -56,58 +49,56 @@ nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr)
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define nvme_free(buf) free(buf)
|
||||
#define nvme_get_num_ioq() 8
|
||||
#define nvme_get_ioq_idx() 0
|
||||
void spdk_free(void *buf)
|
||||
{
|
||||
free(buf);
|
||||
}
|
||||
|
||||
uint64_t nvme_vtophys(void *buf);
|
||||
#define NVME_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
||||
bool ut_fail_vtophys = false;
|
||||
uint64_t spdk_vtophys(void *buf)
|
||||
{
|
||||
if (ut_fail_vtophys) {
|
||||
return (uint64_t) - 1;
|
||||
} else {
|
||||
return (uintptr_t)buf;
|
||||
}
|
||||
}
|
||||
|
||||
extern uint64_t g_ut_tsc;
|
||||
#define nvme_get_tsc() (g_ut_tsc)
|
||||
#define nvme_get_tsc_hz() (1000000)
|
||||
|
||||
static inline void *
|
||||
nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
|
||||
void *
|
||||
spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
|
||||
{
|
||||
return malloc(len);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
nvme_memzone_lookup(const char *name)
|
||||
void *
|
||||
spdk_memzone_lookup(const char *name)
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline int
|
||||
nvme_memzone_free(const char *name)
|
||||
int
|
||||
spdk_memzone_free(const char *name)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
nvme_process_is_primary(void)
|
||||
struct spdk_mempool *
|
||||
spdk_mempool_create(const char *name, size_t count,
|
||||
size_t ele_size, size_t cache_size)
|
||||
{
|
||||
return true;
|
||||
static int mp = 0;
|
||||
|
||||
return (struct spdk_mempool *)∓
|
||||
}
|
||||
|
||||
#define NVME_SOCKET_ID_ANY -1
|
||||
|
||||
typedef unsigned nvme_mempool_t;
|
||||
|
||||
static inline nvme_mempool_t *
|
||||
nvme_mempool_create(const char *name, size_t n,
|
||||
size_t elt_size, size_t cache_size)
|
||||
void
|
||||
spdk_mempool_free(struct spdk_mempool *mp)
|
||||
{
|
||||
static int mp;
|
||||
|
||||
return ∓
|
||||
}
|
||||
|
||||
static inline void *
|
||||
nvme_mempool_get(nvme_mempool_t *mp)
|
||||
void *
|
||||
spdk_mempool_get(struct spdk_mempool *mp)
|
||||
{
|
||||
void *buf;
|
||||
|
||||
@ -118,10 +109,25 @@ nvme_mempool_get(nvme_mempool_t *mp)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline void
|
||||
nvme_mempool_put(nvme_mempool_t *mp, void *buf)
|
||||
void
|
||||
spdk_mempool_put(struct spdk_mempool *mp, void *ele)
|
||||
{
|
||||
free(buf);
|
||||
free(ele);
|
||||
}
|
||||
|
||||
#endif /* __NVME_IMPL_H__ */
|
||||
bool
|
||||
spdk_process_is_primary(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t ut_tsc = 0;
|
||||
uint64_t spdk_get_ticks(void)
|
||||
{
|
||||
return ut_tsc;
|
||||
}
|
||||
|
||||
uint64_t spdk_get_ticks_hz(void)
|
||||
{
|
||||
return 1000000;
|
||||
}
|
Loading…
Reference in New Issue
Block a user