2015-09-21 15:52:41 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
2015-09-21 15:52:41 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nvme_internal.h"
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
static struct nvme_request *_nvme_ns_cmd_rw(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2016-12-13 16:23:52 +00:00
|
|
|
const struct nvme_payload *payload, uint32_t payload_offset, uint32_t md_offset,
|
|
|
|
uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
|
2016-04-07 06:52:43 +00:00
|
|
|
void *cb_arg, uint32_t opc, uint32_t io_flags,
|
2016-12-16 16:41:18 +00:00
|
|
|
uint16_t apptag_mask, uint16_t apptag, bool check_sgl);
|
2015-09-24 23:45:51 +00:00
|
|
|
|
2015-09-28 17:53:57 +00:00
|
|
|
static void
|
2016-02-09 18:06:48 +00:00
|
|
|
nvme_cb_complete_child(void *child_arg, const struct spdk_nvme_cpl *cpl)
|
2015-09-28 17:53:57 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *child = child_arg;
|
|
|
|
struct nvme_request *parent = child->parent;
|
|
|
|
|
2016-04-08 16:55:27 +00:00
|
|
|
nvme_request_remove_child(parent, child);
|
2015-09-28 17:53:57 +00:00
|
|
|
|
2016-02-09 18:06:48 +00:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
2015-09-28 17:53:57 +00:00
|
|
|
memcpy(&parent->parent_status, cpl, sizeof(*cpl));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->num_children == 0) {
|
|
|
|
if (parent->cb_fn) {
|
|
|
|
parent->cb_fn(parent->cb_arg, &parent->parent_status);
|
|
|
|
}
|
|
|
|
nvme_free_request(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_request_add_child(struct nvme_request *parent, struct nvme_request *child)
|
|
|
|
{
|
|
|
|
if (parent->num_children == 0) {
|
|
|
|
/*
|
|
|
|
* Defer initialization of the children TAILQ since it falls
|
|
|
|
* on a separate cacheline. This ensures we do not touch this
|
|
|
|
* cacheline except on request splitting cases, which are
|
|
|
|
* relatively rare.
|
|
|
|
*/
|
|
|
|
TAILQ_INIT(&parent->children);
|
2015-12-22 23:34:53 +00:00
|
|
|
parent->parent = NULL;
|
2016-02-09 18:06:48 +00:00
|
|
|
memset(&parent->parent_status, 0, sizeof(struct spdk_nvme_cpl));
|
2015-09-28 17:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parent->num_children++;
|
|
|
|
TAILQ_INSERT_TAIL(&parent->children, child, child_tailq);
|
|
|
|
child->parent = parent;
|
|
|
|
child->cb_fn = nvme_cb_complete_child;
|
|
|
|
child->cb_arg = child;
|
|
|
|
}
|
|
|
|
|
2016-04-08 16:55:27 +00:00
|
|
|
void
|
|
|
|
nvme_request_remove_child(struct nvme_request *parent, struct nvme_request *child)
|
|
|
|
{
|
2016-08-08 20:55:27 +00:00
|
|
|
assert(parent != NULL);
|
|
|
|
assert(child != NULL);
|
|
|
|
assert(child->parent == parent);
|
|
|
|
assert(parent->num_children != 0);
|
2016-04-08 16:58:44 +00:00
|
|
|
|
2016-04-08 16:55:27 +00:00
|
|
|
parent->num_children--;
|
|
|
|
TAILQ_REMOVE(&parent->children, child, child_tailq);
|
|
|
|
}
|
|
|
|
|
2016-12-13 14:56:44 +00:00
|
|
|
static void
|
|
|
|
nvme_request_free_children(struct nvme_request *req)
|
|
|
|
{
|
|
|
|
struct nvme_request *child, *tmp;
|
|
|
|
|
|
|
|
if (req->num_children == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free all child nvme_request */
|
|
|
|
TAILQ_FOREACH_SAFE(child, &req->children, child_tailq, tmp) {
|
|
|
|
nvme_request_remove_child(req, child);
|
2018-02-22 12:56:25 +00:00
|
|
|
nvme_request_free_children(child);
|
2016-12-13 14:56:44 +00:00
|
|
|
nvme_free_request(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 16:45:33 +00:00
|
|
|
static struct nvme_request *
|
2017-04-03 21:56:26 +00:00
|
|
|
_nvme_add_child_request(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
const struct nvme_payload *payload,
|
2016-12-16 16:45:33 +00:00
|
|
|
uint32_t payload_offset, uint32_t md_offset,
|
|
|
|
uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t opc,
|
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag,
|
2016-12-16 16:41:18 +00:00
|
|
|
struct nvme_request *parent, bool check_sgl)
|
2016-12-16 16:45:33 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *child;
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
child = _nvme_ns_cmd_rw(ns, qpair, payload, payload_offset, md_offset, lba, lba_count, cb_fn,
|
2016-12-16 16:41:18 +00:00
|
|
|
cb_arg, opc, io_flags, apptag_mask, apptag, check_sgl);
|
2016-12-16 16:45:33 +00:00
|
|
|
if (child == NULL) {
|
|
|
|
nvme_request_free_children(parent);
|
|
|
|
nvme_free_request(parent);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_request_add_child(parent, child);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2015-09-24 23:45:51 +00:00
|
|
|
static struct nvme_request *
|
2016-02-10 18:26:12 +00:00
|
|
|
_nvme_ns_cmd_split_request(struct spdk_nvme_ns *ns,
|
2017-04-03 21:56:26 +00:00
|
|
|
struct spdk_nvme_qpair *qpair,
|
2016-01-22 23:56:20 +00:00
|
|
|
const struct nvme_payload *payload,
|
2016-12-13 16:23:52 +00:00
|
|
|
uint32_t payload_offset, uint32_t md_offset,
|
2015-09-24 23:45:51 +00:00
|
|
|
uint64_t lba, uint32_t lba_count,
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t opc,
|
2015-12-30 22:52:17 +00:00
|
|
|
uint32_t io_flags, struct nvme_request *req,
|
2016-04-07 06:52:43 +00:00
|
|
|
uint32_t sectors_per_max_io, uint32_t sector_mask,
|
|
|
|
uint16_t apptag_mask, uint16_t apptag)
|
2015-09-24 23:45:51 +00:00
|
|
|
{
|
2017-01-23 22:32:46 +00:00
|
|
|
uint32_t sector_size;
|
2016-04-07 06:52:43 +00:00
|
|
|
uint32_t md_size = ns->md_size;
|
2015-09-24 23:45:51 +00:00
|
|
|
uint32_t remaining_lba_count = lba_count;
|
2016-12-13 14:56:44 +00:00
|
|
|
struct nvme_request *child;
|
2015-09-24 23:45:51 +00:00
|
|
|
|
2017-01-23 22:32:46 +00:00
|
|
|
sector_size = ns->extended_lba_size;
|
|
|
|
|
|
|
|
if ((io_flags & SPDK_NVME_IO_FLAGS_PRACT) &&
|
|
|
|
(ns->flags & SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED) &&
|
|
|
|
(ns->flags & SPDK_NVME_NS_DPS_PI_SUPPORTED) &&
|
|
|
|
(md_size == 8)) {
|
|
|
|
sector_size -= 8;
|
2016-04-07 06:52:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:45:51 +00:00
|
|
|
while (remaining_lba_count > 0) {
|
|
|
|
lba_count = sectors_per_max_io - (lba & sector_mask);
|
2017-02-02 17:07:12 +00:00
|
|
|
lba_count = spdk_min(remaining_lba_count, lba_count);
|
2015-09-24 23:45:51 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
child = _nvme_add_child_request(ns, qpair, payload, payload_offset, md_offset,
|
2016-12-16 16:45:33 +00:00
|
|
|
lba, lba_count, cb_fn, cb_arg, opc,
|
2016-12-16 16:41:18 +00:00
|
|
|
io_flags, apptag_mask, apptag, req, true);
|
2015-09-24 23:45:51 +00:00
|
|
|
if (child == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-13 16:23:52 +00:00
|
|
|
|
2015-09-24 23:45:51 +00:00
|
|
|
remaining_lba_count -= lba_count;
|
|
|
|
lba += lba_count;
|
2016-12-13 16:23:52 +00:00
|
|
|
payload_offset += lba_count * sector_size;
|
2016-04-07 06:52:43 +00:00
|
|
|
md_offset += lba_count * md_size;
|
2015-09-24 23:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2016-12-13 15:00:43 +00:00
|
|
|
static void
|
|
|
|
_nvme_ns_cmd_setup_request(struct spdk_nvme_ns *ns, struct nvme_request *req,
|
2017-01-03 16:35:37 +00:00
|
|
|
uint32_t opc, uint64_t lba, uint32_t lba_count,
|
2016-12-13 15:00:43 +00:00
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_cmd *cmd;
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
|
|
|
cmd->opc = opc;
|
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
*(uint64_t *)&cmd->cdw10 = lba;
|
|
|
|
|
|
|
|
if (ns->flags & SPDK_NVME_NS_DPS_PI_SUPPORTED) {
|
|
|
|
switch (ns->pi_type) {
|
|
|
|
case SPDK_NVME_FMT_NVM_PROTECTION_TYPE1:
|
|
|
|
case SPDK_NVME_FMT_NVM_PROTECTION_TYPE2:
|
|
|
|
cmd->cdw14 = (uint32_t)lba;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->cdw12 = lba_count - 1;
|
|
|
|
cmd->cdw12 |= io_flags;
|
|
|
|
|
|
|
|
cmd->cdw15 = apptag_mask;
|
|
|
|
cmd->cdw15 = (cmd->cdw15 << 16 | apptag);
|
|
|
|
}
|
|
|
|
|
2016-12-16 16:41:18 +00:00
|
|
|
static struct nvme_request *
|
2017-08-02 19:18:10 +00:00
|
|
|
_nvme_ns_cmd_split_request_prp(struct spdk_nvme_ns *ns,
|
2017-04-03 21:56:26 +00:00
|
|
|
struct spdk_nvme_qpair *qpair,
|
2016-12-16 16:41:18 +00:00
|
|
|
const struct nvme_payload *payload,
|
|
|
|
uint32_t payload_offset, uint32_t md_offset,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t opc,
|
|
|
|
uint32_t io_flags, struct nvme_request *req,
|
|
|
|
uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct nvme_sgl_args *args;
|
|
|
|
bool start_valid, end_valid, last_sge, child_equals_parent;
|
|
|
|
uint64_t child_lba = lba;
|
|
|
|
uint32_t req_current_length = 0;
|
|
|
|
uint32_t child_length = 0;
|
|
|
|
uint32_t sge_length;
|
2017-08-15 23:22:11 +00:00
|
|
|
uint32_t page_size = qpair->ctrlr->page_size;
|
2016-12-16 16:41:18 +00:00
|
|
|
uintptr_t address;
|
|
|
|
|
|
|
|
args = &req->payload.u.sgl;
|
|
|
|
|
|
|
|
args->reset_sgl_fn(args->cb_arg, payload_offset);
|
|
|
|
args->next_sge_fn(args->cb_arg, (void **)&address, &sge_length);
|
|
|
|
while (req_current_length < req->payload_size) {
|
|
|
|
|
|
|
|
if (sge_length == 0) {
|
|
|
|
continue;
|
|
|
|
} else if (req_current_length + sge_length > req->payload_size) {
|
|
|
|
sge_length = req->payload_size - req_current_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The start of the SGE is invalid if the start address is not page aligned,
|
|
|
|
* unless it is the first SGE in the child request.
|
|
|
|
*/
|
2017-08-15 23:22:11 +00:00
|
|
|
start_valid = child_length == 0 || _is_page_aligned(address, page_size);
|
2016-12-16 16:41:18 +00:00
|
|
|
|
|
|
|
/* Boolean for whether this is the last SGE in the parent request. */
|
|
|
|
last_sge = (req_current_length + sge_length == req->payload_size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The end of the SGE is invalid if the end address is not page aligned,
|
|
|
|
* unless it is the last SGE in the parent request.
|
|
|
|
*/
|
2017-08-15 23:22:11 +00:00
|
|
|
end_valid = last_sge || _is_page_aligned(address + sge_length, page_size);
|
2016-12-16 16:41:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This child request equals the parent request, meaning that no splitting
|
|
|
|
* was required for the parent request (the one passed into this function).
|
|
|
|
* In this case, we do not create a child request at all - we just send
|
|
|
|
* the original request as a single request at the end of this function.
|
|
|
|
*/
|
|
|
|
child_equals_parent = (child_length + sge_length == req->payload_size);
|
|
|
|
|
|
|
|
if (start_valid) {
|
|
|
|
/*
|
|
|
|
* The start of the SGE is valid, so advance the length parameters,
|
|
|
|
* to include this SGE with previous SGEs for this child request
|
|
|
|
* (if any). If it is not valid, we do not advance the length
|
|
|
|
* parameters nor get the next SGE, because we must send what has
|
|
|
|
* been collected before this SGE as a child request.
|
|
|
|
*/
|
|
|
|
child_length += sge_length;
|
|
|
|
req_current_length += sge_length;
|
|
|
|
if (req_current_length < req->payload_size) {
|
|
|
|
args->next_sge_fn(args->cb_arg, (void **)&address, &sge_length);
|
|
|
|
}
|
2017-07-31 15:10:44 +00:00
|
|
|
/*
|
|
|
|
* If the next SGE is not page aligned, we will need to create a child
|
|
|
|
* request for what we have so far, and then start a new child request for
|
|
|
|
* the next SGE.
|
|
|
|
*/
|
2017-08-15 23:22:11 +00:00
|
|
|
start_valid = _is_page_aligned(address, page_size);
|
2016-12-16 16:41:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 17:12:51 +00:00
|
|
|
if (start_valid && end_valid && !last_sge) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-16 16:41:18 +00:00
|
|
|
/*
|
2017-03-20 17:12:51 +00:00
|
|
|
* We need to create a split here. Send what we have accumulated so far as a child
|
|
|
|
* request. Checking if child_equals_parent allows us to *not* create a child request
|
|
|
|
* when no splitting is required - in that case we will fall-through and just create
|
|
|
|
* a single request with no children for the entire I/O.
|
2016-12-16 16:41:18 +00:00
|
|
|
*/
|
2017-03-20 17:12:51 +00:00
|
|
|
if (!child_equals_parent) {
|
2016-12-16 16:41:18 +00:00
|
|
|
struct nvme_request *child;
|
|
|
|
uint32_t child_lba_count;
|
|
|
|
|
2017-01-23 22:32:46 +00:00
|
|
|
if ((child_length % ns->extended_lba_size) != 0) {
|
2017-08-02 19:18:10 +00:00
|
|
|
SPDK_ERRLOG("child_length %u not even multiple of lba_size %u\n",
|
|
|
|
child_length, ns->extended_lba_size);
|
2016-12-16 16:41:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-01-23 22:32:46 +00:00
|
|
|
child_lba_count = child_length / ns->extended_lba_size;
|
2016-12-16 16:41:18 +00:00
|
|
|
/*
|
|
|
|
* Note the last parameter is set to "false" - this tells the recursive
|
|
|
|
* call to _nvme_ns_cmd_rw() to not bother with checking for SGL splitting
|
|
|
|
* since we have already verified it here.
|
|
|
|
*/
|
2017-04-03 21:56:26 +00:00
|
|
|
child = _nvme_add_child_request(ns, qpair, payload, payload_offset, md_offset,
|
2016-12-16 16:41:18 +00:00
|
|
|
child_lba, child_lba_count,
|
|
|
|
cb_fn, cb_arg, opc, io_flags,
|
|
|
|
apptag_mask, apptag, req, false);
|
|
|
|
if (child == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
payload_offset += child_length;
|
|
|
|
md_offset += child_lba_count * ns->md_size;
|
|
|
|
child_lba += child_lba_count;
|
|
|
|
child_length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child_length == req->payload_size) {
|
|
|
|
/* No splitting was required, so setup the whole payload as one request. */
|
|
|
|
_nvme_ns_cmd_setup_request(ns, req, opc, lba, lba_count, io_flags, apptag_mask, apptag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:18:10 +00:00
|
|
|
static struct nvme_request *
|
|
|
|
_nvme_ns_cmd_split_request_sgl(struct spdk_nvme_ns *ns,
|
|
|
|
struct spdk_nvme_qpair *qpair,
|
|
|
|
const struct nvme_payload *payload,
|
|
|
|
uint32_t payload_offset, uint32_t md_offset,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t opc,
|
|
|
|
uint32_t io_flags, struct nvme_request *req,
|
|
|
|
uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct nvme_sgl_args *args;
|
|
|
|
uint64_t child_lba = lba;
|
|
|
|
uint32_t req_current_length = 0;
|
|
|
|
uint32_t child_length = 0;
|
|
|
|
uint32_t sge_length;
|
|
|
|
uint16_t max_sges, num_sges;
|
|
|
|
uintptr_t address;
|
|
|
|
|
|
|
|
args = &req->payload.u.sgl;
|
|
|
|
max_sges = ns->ctrlr->max_sges;
|
|
|
|
|
|
|
|
args->reset_sgl_fn(args->cb_arg, payload_offset);
|
|
|
|
num_sges = 0;
|
|
|
|
|
|
|
|
while (req_current_length < req->payload_size) {
|
|
|
|
args->next_sge_fn(args->cb_arg, (void **)&address, &sge_length);
|
|
|
|
|
|
|
|
if (req_current_length + sge_length > req->payload_size) {
|
|
|
|
sge_length = req->payload_size - req_current_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
child_length += sge_length;
|
|
|
|
req_current_length += sge_length;
|
|
|
|
num_sges++;
|
|
|
|
|
|
|
|
if (num_sges < max_sges) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to create a split here. Send what we have accumulated so far as a child
|
|
|
|
* request. Checking if the child equals the full payload allows us to *not*
|
|
|
|
* create a child request when no splitting is required - in that case we will
|
|
|
|
* fall-through and just create a single request with no children for the entire I/O.
|
|
|
|
*/
|
|
|
|
if (child_length != req->payload_size) {
|
|
|
|
struct nvme_request *child;
|
|
|
|
uint32_t child_lba_count;
|
|
|
|
|
|
|
|
if ((child_length % ns->extended_lba_size) != 0) {
|
|
|
|
SPDK_ERRLOG("child_length %u not even multiple of lba_size %u\n",
|
|
|
|
child_length, ns->extended_lba_size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
child_lba_count = child_length / ns->extended_lba_size;
|
|
|
|
/*
|
|
|
|
* Note the last parameter is set to "false" - this tells the recursive
|
|
|
|
* call to _nvme_ns_cmd_rw() to not bother with checking for SGL splitting
|
|
|
|
* since we have already verified it here.
|
|
|
|
*/
|
|
|
|
child = _nvme_add_child_request(ns, qpair, payload, payload_offset, md_offset,
|
|
|
|
child_lba, child_lba_count,
|
|
|
|
cb_fn, cb_arg, opc, io_flags,
|
|
|
|
apptag_mask, apptag, req, false);
|
|
|
|
if (child == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
payload_offset += child_length;
|
|
|
|
md_offset += child_lba_count * ns->md_size;
|
|
|
|
child_lba += child_lba_count;
|
|
|
|
child_length = 0;
|
|
|
|
num_sges = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child_length == req->payload_size) {
|
|
|
|
/* No splitting was required, so setup the whole payload as one request. */
|
|
|
|
_nvme_ns_cmd_setup_request(ns, req, opc, lba, lba_count, io_flags, apptag_mask, apptag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
static struct nvme_request *
|
2017-04-03 21:56:26 +00:00
|
|
|
_nvme_ns_cmd_rw(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
const struct nvme_payload *payload, uint32_t payload_offset, uint32_t md_offset,
|
2016-02-10 18:26:12 +00:00
|
|
|
uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t opc,
|
2016-12-16 16:41:18 +00:00
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag, bool check_sgl)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
uint32_t sector_size;
|
|
|
|
uint32_t sectors_per_max_io;
|
|
|
|
uint32_t sectors_per_stripe;
|
|
|
|
|
2015-12-30 22:52:17 +00:00
|
|
|
if (io_flags & 0xFFFF) {
|
|
|
|
/* The bottom 16 bits must be empty */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-23 22:32:46 +00:00
|
|
|
sector_size = ns->extended_lba_size;
|
2015-09-21 15:52:41 +00:00
|
|
|
sectors_per_max_io = ns->sectors_per_max_io;
|
|
|
|
sectors_per_stripe = ns->sectors_per_stripe;
|
|
|
|
|
2017-01-23 22:32:46 +00:00
|
|
|
if ((io_flags & SPDK_NVME_IO_FLAGS_PRACT) &&
|
|
|
|
(ns->flags & SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED) &&
|
|
|
|
(ns->flags & SPDK_NVME_NS_DPS_PI_SUPPORTED) &&
|
|
|
|
(ns->md_size == 8)) {
|
|
|
|
sector_size -= 8;
|
2016-04-07 06:52:43 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request(qpair, payload, lba_count * sector_size, cb_fn, cb_arg);
|
2015-09-21 15:52:41 +00:00
|
|
|
if (req == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-13 16:23:52 +00:00
|
|
|
req->payload_offset = payload_offset;
|
|
|
|
req->md_offset = md_offset;
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
/*
|
|
|
|
* Intel DC P3*00 NVMe controllers benefit from driver-assisted striping.
|
|
|
|
* If this controller defines a stripe boundary and this I/O spans a stripe
|
|
|
|
* boundary, split the request into multiple requests and submit each
|
|
|
|
* separately to hardware.
|
|
|
|
*/
|
|
|
|
if (sectors_per_stripe > 0 &&
|
|
|
|
(((lba & (sectors_per_stripe - 1)) + lba_count) > sectors_per_stripe)) {
|
2015-09-24 23:45:51 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
return _nvme_ns_cmd_split_request(ns, qpair, payload, payload_offset, md_offset, lba, lba_count,
|
|
|
|
cb_fn,
|
2016-12-13 16:23:52 +00:00
|
|
|
cb_arg, opc,
|
2016-04-07 06:52:43 +00:00
|
|
|
io_flags, req, sectors_per_stripe, sectors_per_stripe - 1, apptag_mask, apptag);
|
2015-09-21 15:52:41 +00:00
|
|
|
} else if (lba_count > sectors_per_max_io) {
|
2017-04-03 21:56:26 +00:00
|
|
|
return _nvme_ns_cmd_split_request(ns, qpair, payload, payload_offset, md_offset, lba, lba_count,
|
|
|
|
cb_fn,
|
2016-12-13 16:23:52 +00:00
|
|
|
cb_arg, opc,
|
2016-04-07 06:52:43 +00:00
|
|
|
io_flags, req, sectors_per_max_io, 0, apptag_mask, apptag);
|
2017-08-02 19:18:10 +00:00
|
|
|
} else if (req->payload.type == NVME_PAYLOAD_TYPE_SGL && check_sgl) {
|
|
|
|
if (ns->ctrlr->flags & SPDK_NVME_CTRLR_SGL_SUPPORTED) {
|
|
|
|
return _nvme_ns_cmd_split_request_sgl(ns, qpair, payload, payload_offset, md_offset,
|
|
|
|
lba, lba_count, cb_fn, cb_arg, opc, io_flags,
|
|
|
|
req, apptag_mask, apptag);
|
|
|
|
} else {
|
|
|
|
return _nvme_ns_cmd_split_request_prp(ns, qpair, payload, payload_offset, md_offset,
|
|
|
|
lba, lba_count, cb_fn, cb_arg, opc, io_flags,
|
|
|
|
req, apptag_mask, apptag);
|
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 15:00:43 +00:00
|
|
|
_nvme_ns_cmd_setup_request(ns, req, opc, lba, lba_count, io_flags, apptag_mask, apptag);
|
2015-09-21 15:52:41 +00:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:11:53 +00:00
|
|
|
int
|
|
|
|
spdk_nvme_ns_cmd_compare(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *buffer,
|
|
|
|
uint64_t lba,
|
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags)
|
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
|
|
|
payload.md = NULL;
|
|
|
|
|
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg,
|
|
|
|
SPDK_NVME_OPC_COMPARE,
|
|
|
|
io_flags, 0,
|
|
|
|
0, true);
|
|
|
|
if (req != NULL) {
|
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
|
|
|
} else {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvme_ns_cmd_compare_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
void *buffer,
|
|
|
|
void *metadata,
|
|
|
|
uint64_t lba,
|
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
|
|
|
payload.md = metadata;
|
|
|
|
|
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg,
|
|
|
|
SPDK_NVME_OPC_COMPARE,
|
|
|
|
io_flags,
|
|
|
|
apptag_mask, apptag, true);
|
|
|
|
if (req != NULL) {
|
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
|
|
|
} else {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvme_ns_cmd_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
|
|
|
|
spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
|
|
|
|
spdk_nvme_req_next_sge_cb next_sge_fn)
|
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
struct nvme_payload payload;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (reset_sgl_fn == NULL || next_sge_fn == NULL) {
|
2017-06-28 00:11:53 +00:00
|
|
|
return -EINVAL;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-06-28 00:11:53 +00:00
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_SGL;
|
|
|
|
payload.md = NULL;
|
|
|
|
payload.u.sgl.reset_sgl_fn = reset_sgl_fn;
|
|
|
|
payload.u.sgl.next_sge_fn = next_sge_fn;
|
|
|
|
payload.u.sgl.cb_arg = cb_arg;
|
|
|
|
|
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg,
|
|
|
|
SPDK_NVME_OPC_COMPARE,
|
|
|
|
io_flags, 0, 0, true);
|
|
|
|
if (req != NULL) {
|
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
|
|
|
} else {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_read(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *buffer,
|
|
|
|
uint64_t lba,
|
2016-02-10 18:26:12 +00:00
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-01-22 23:56:20 +00:00
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
2016-04-07 06:52:43 +00:00
|
|
|
payload.md = NULL;
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_READ,
|
2016-12-13 16:23:52 +00:00
|
|
|
io_flags, 0,
|
2016-12-16 16:41:18 +00:00
|
|
|
0, true);
|
2016-04-07 06:52:43 +00:00
|
|
|
if (req != NULL) {
|
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-04-07 06:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvme_ns_cmd_read_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *buffer,
|
|
|
|
void *metadata,
|
|
|
|
uint64_t lba,
|
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
|
|
|
payload.md = metadata;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_READ,
|
2016-12-13 16:23:52 +00:00
|
|
|
io_flags,
|
2016-12-16 16:41:18 +00:00
|
|
|
apptag_mask, apptag, true);
|
2015-12-04 03:52:37 +00:00
|
|
|
if (req != NULL) {
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-12-04 03:52:37 +00:00
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-12-04 03:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
|
|
|
|
spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
|
|
|
|
spdk_nvme_req_next_sge_cb next_sge_fn)
|
2015-12-04 03:52:37 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-01-22 23:56:20 +00:00
|
|
|
struct nvme_payload payload;
|
2015-12-04 03:52:37 +00:00
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (reset_sgl_fn == NULL || next_sge_fn == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -EINVAL;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-02-04 06:06:46 +00:00
|
|
|
|
2016-01-22 23:56:20 +00:00
|
|
|
payload.type = NVME_PAYLOAD_TYPE_SGL;
|
2016-04-07 06:52:43 +00:00
|
|
|
payload.md = NULL;
|
2016-01-22 23:56:20 +00:00
|
|
|
payload.u.sgl.reset_sgl_fn = reset_sgl_fn;
|
|
|
|
payload.u.sgl.next_sge_fn = next_sge_fn;
|
2016-02-18 21:23:28 +00:00
|
|
|
payload.u.sgl.cb_arg = cb_arg;
|
2016-01-22 23:56:20 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_READ,
|
2016-12-16 16:41:18 +00:00
|
|
|
io_flags, 0, 0, true);
|
2015-09-21 15:52:41 +00:00
|
|
|
if (req != NULL) {
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-09-21 15:52:41 +00:00
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_write(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
void *buffer, uint64_t lba,
|
2016-02-10 18:26:12 +00:00
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-01-22 23:56:20 +00:00
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
2016-04-07 06:52:43 +00:00
|
|
|
payload.md = NULL;
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_WRITE,
|
2016-12-16 16:41:18 +00:00
|
|
|
io_flags, 0, 0, true);
|
2016-04-07 06:52:43 +00:00
|
|
|
if (req != NULL) {
|
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-04-07 06:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvme_ns_cmd_write_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
void *buffer, void *metadata, uint64_t lba,
|
|
|
|
uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
|
|
|
uint32_t io_flags, uint16_t apptag_mask, uint16_t apptag)
|
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
|
|
|
struct nvme_payload payload;
|
|
|
|
|
|
|
|
payload.type = NVME_PAYLOAD_TYPE_CONTIG;
|
|
|
|
payload.u.contig = buffer;
|
|
|
|
payload.md = metadata;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_WRITE,
|
2016-12-16 16:41:18 +00:00
|
|
|
io_flags, apptag_mask, apptag, true);
|
2015-12-04 03:52:37 +00:00
|
|
|
if (req != NULL) {
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-12-04 03:52:37 +00:00
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-12-04 03:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
|
|
|
|
spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
|
|
|
|
spdk_nvme_req_next_sge_cb next_sge_fn)
|
2015-12-04 03:52:37 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-01-22 23:56:20 +00:00
|
|
|
struct nvme_payload payload;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (reset_sgl_fn == NULL || next_sge_fn == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -EINVAL;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-02-04 06:06:46 +00:00
|
|
|
|
2016-01-22 23:56:20 +00:00
|
|
|
payload.type = NVME_PAYLOAD_TYPE_SGL;
|
2016-04-07 06:52:43 +00:00
|
|
|
payload.md = NULL;
|
2016-01-22 23:56:20 +00:00
|
|
|
payload.u.sgl.reset_sgl_fn = reset_sgl_fn;
|
|
|
|
payload.u.sgl.next_sge_fn = next_sge_fn;
|
2016-02-18 21:23:28 +00:00
|
|
|
payload.u.sgl.cb_arg = cb_arg;
|
2015-12-04 03:52:37 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = _nvme_ns_cmd_rw(ns, qpair, &payload, 0, 0, lba, lba_count, cb_fn, cb_arg, SPDK_NVME_OPC_WRITE,
|
2016-12-16 16:41:18 +00:00
|
|
|
io_flags, 0, 0, true);
|
2015-09-21 15:52:41 +00:00
|
|
|
if (req != NULL) {
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-09-21 15:52:41 +00:00
|
|
|
} else {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 07:43:24 +00:00
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg,
|
2016-02-10 18:26:12 +00:00
|
|
|
uint32_t io_flags)
|
2016-01-12 07:43:24 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2016-01-12 07:43:24 +00:00
|
|
|
uint64_t *tmp_lba;
|
|
|
|
|
2017-08-02 20:41:20 +00:00
|
|
|
if (lba_count == 0 || lba_count > UINT16_MAX + 1) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -EINVAL;
|
2016-01-12 07:43:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_null(qpair, cb_fn, cb_arg);
|
2016-01-12 07:43:24 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-01-12 07:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_WRITE_ZEROES;
|
2016-01-12 07:43:24 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
tmp_lba = (uint64_t *)&cmd->cdw10;
|
|
|
|
*tmp_lba = lba;
|
|
|
|
cmd->cdw12 = lba_count - 1;
|
|
|
|
cmd->cdw12 |= io_flags;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2016-01-12 07:43:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
int
|
2016-10-03 17:37:48 +00:00
|
|
|
spdk_nvme_ns_cmd_dataset_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
uint32_t type,
|
|
|
|
const struct spdk_nvme_dsm_range *ranges, uint16_t num_ranges,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-02-09 18:06:48 +00:00
|
|
|
if (num_ranges == 0 || num_ranges > SPDK_NVME_DATASET_MANAGEMENT_MAX_RANGES) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -EINVAL;
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 17:37:48 +00:00
|
|
|
if (ranges == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_user_copy(qpair, (void *)ranges,
|
2016-10-03 17:37:48 +00:00
|
|
|
num_ranges * sizeof(struct spdk_nvme_dsm_range),
|
|
|
|
cb_fn, cb_arg, true);
|
2015-09-21 15:52:41 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_DATASET_MANAGEMENT;
|
2015-09-21 15:52:41 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
cmd->cdw10 = num_ranges - 1;
|
2016-10-03 17:37:48 +00:00
|
|
|
cmd->cdw11 = type;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_null(qpair, cb_fn, cb_arg);
|
2015-09-21 15:52:41 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_FLUSH;
|
2015-09-21 15:52:41 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2015-09-21 15:52:41 +00:00
|
|
|
}
|
2016-01-22 08:39:55 +00:00
|
|
|
|
|
|
|
int
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_ns_cmd_reservation_register(struct spdk_nvme_ns *ns,
|
2016-02-29 21:19:02 +00:00
|
|
|
struct spdk_nvme_qpair *qpair,
|
2016-02-10 18:26:12 +00:00
|
|
|
struct spdk_nvme_reservation_register_data *payload,
|
|
|
|
bool ignore_key,
|
|
|
|
enum spdk_nvme_reservation_register_action action,
|
|
|
|
enum spdk_nvme_reservation_register_cptpl cptpl,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2016-01-22 08:39:55 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2016-01-22 08:39:55 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_user_copy(qpair,
|
|
|
|
payload, sizeof(struct spdk_nvme_reservation_register_data),
|
2016-09-12 21:30:59 +00:00
|
|
|
cb_fn, cb_arg, true);
|
2016-01-22 08:39:55 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_RESERVATION_REGISTER;
|
2016-01-22 08:39:55 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
/* Bits 0-2 */
|
|
|
|
cmd->cdw10 = action;
|
|
|
|
/* Bit 3 */
|
|
|
|
cmd->cdw10 |= ignore_key ? 1 << 3 : 0;
|
|
|
|
/* Bits 30-31 */
|
|
|
|
cmd->cdw10 |= (uint32_t)cptpl << 30;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_ns_cmd_reservation_release(struct spdk_nvme_ns *ns,
|
2016-02-29 21:19:02 +00:00
|
|
|
struct spdk_nvme_qpair *qpair,
|
2016-02-10 18:26:12 +00:00
|
|
|
struct spdk_nvme_reservation_key_data *payload,
|
|
|
|
bool ignore_key,
|
|
|
|
enum spdk_nvme_reservation_release_action action,
|
|
|
|
enum spdk_nvme_reservation_type type,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2016-01-22 08:39:55 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2016-01-22 08:39:55 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_user_copy(qpair,
|
|
|
|
payload, sizeof(struct spdk_nvme_reservation_key_data), cb_fn,
|
2016-09-12 21:30:59 +00:00
|
|
|
cb_arg, true);
|
2016-01-22 08:39:55 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_RESERVATION_RELEASE;
|
2016-01-22 08:39:55 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
/* Bits 0-2 */
|
|
|
|
cmd->cdw10 = action;
|
|
|
|
/* Bit 3 */
|
|
|
|
cmd->cdw10 |= ignore_key ? 1 << 3 : 0;
|
|
|
|
/* Bits 8-15 */
|
|
|
|
cmd->cdw10 |= (uint32_t)type << 8;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-10 18:26:12 +00:00
|
|
|
spdk_nvme_ns_cmd_reservation_acquire(struct spdk_nvme_ns *ns,
|
2016-02-29 21:19:02 +00:00
|
|
|
struct spdk_nvme_qpair *qpair,
|
2016-02-10 18:26:12 +00:00
|
|
|
struct spdk_nvme_reservation_acquire_data *payload,
|
|
|
|
bool ignore_key,
|
|
|
|
enum spdk_nvme_reservation_acquire_action action,
|
|
|
|
enum spdk_nvme_reservation_type type,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2016-01-22 08:39:55 +00:00
|
|
|
{
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2016-01-22 08:39:55 +00:00
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_user_copy(qpair,
|
|
|
|
payload, sizeof(struct spdk_nvme_reservation_acquire_data),
|
2016-09-12 21:30:59 +00:00
|
|
|
cb_fn, cb_arg, true);
|
2016-01-22 08:39:55 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_RESERVATION_ACQUIRE;
|
2016-01-22 08:39:55 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
/* Bits 0-2 */
|
|
|
|
cmd->cdw10 = action;
|
|
|
|
/* Bit 3 */
|
|
|
|
cmd->cdw10 |= ignore_key ? 1 << 3 : 0;
|
|
|
|
/* Bits 8-15 */
|
|
|
|
cmd->cdw10 |= (uint32_t)type << 8;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-02-29 21:19:02 +00:00
|
|
|
spdk_nvme_ns_cmd_reservation_report(struct spdk_nvme_ns *ns,
|
|
|
|
struct spdk_nvme_qpair *qpair,
|
|
|
|
void *payload, uint32_t len,
|
|
|
|
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
2016-01-22 08:39:55 +00:00
|
|
|
{
|
|
|
|
uint32_t num_dwords;
|
|
|
|
struct nvme_request *req;
|
2016-02-09 18:06:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd;
|
2016-01-22 08:39:55 +00:00
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (len % 4) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -EINVAL;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-01-22 08:39:55 +00:00
|
|
|
num_dwords = len / 4;
|
|
|
|
|
2017-04-03 21:56:26 +00:00
|
|
|
req = nvme_allocate_request_user_copy(qpair, payload, len, cb_fn, cb_arg, false);
|
2016-01-22 08:39:55 +00:00
|
|
|
if (req == NULL) {
|
2016-06-14 22:17:33 +00:00
|
|
|
return -ENOMEM;
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd = &req->cmd;
|
2016-02-09 18:06:48 +00:00
|
|
|
cmd->opc = SPDK_NVME_OPC_RESERVATION_REPORT;
|
2016-01-22 08:39:55 +00:00
|
|
|
cmd->nsid = ns->id;
|
|
|
|
|
|
|
|
cmd->cdw10 = num_dwords;
|
|
|
|
|
2016-03-08 22:16:09 +00:00
|
|
|
return nvme_qpair_submit_request(qpair, req);
|
2016-01-22 08:39:55 +00:00
|
|
|
}
|