140 lines
4.2 KiB
C
140 lines
4.2 KiB
C
|
/*-
|
||
|
* 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 over Fabrics transport-independent functions
|
||
|
*/
|
||
|
|
||
|
#include "nvme_internal.h"
|
||
|
|
||
|
static int
|
||
|
nvme_fabric_prop_set_cmd(struct spdk_nvme_ctrlr *ctrlr,
|
||
|
uint32_t offset, uint8_t size, uint64_t value)
|
||
|
{
|
||
|
struct spdk_nvmf_fabric_prop_set_cmd cmd = {};
|
||
|
struct nvme_completion_poll_status status;
|
||
|
int rc;
|
||
|
|
||
|
assert(size == SPDK_NVMF_PROP_SIZE_4 || size == SPDK_NVMF_PROP_SIZE_8);
|
||
|
|
||
|
cmd.opcode = SPDK_NVME_OPC_FABRIC;
|
||
|
cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_SET;
|
||
|
cmd.ofst = offset;
|
||
|
cmd.attrib.size = size;
|
||
|
cmd.value.u64 = value;
|
||
|
|
||
|
rc = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, (struct spdk_nvme_cmd *)&cmd,
|
||
|
NULL, 0,
|
||
|
nvme_completion_poll_cb, &status);
|
||
|
if (rc < 0) {
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
if (spdk_nvme_wait_for_completion(ctrlr->adminq, &status)) {
|
||
|
SPDK_ERRLOG("Property Set failed\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
nvme_fabric_prop_get_cmd(struct spdk_nvme_ctrlr *ctrlr,
|
||
|
uint32_t offset, uint8_t size, uint64_t *value)
|
||
|
{
|
||
|
struct spdk_nvmf_fabric_prop_set_cmd cmd = {};
|
||
|
struct nvme_completion_poll_status status;
|
||
|
struct spdk_nvmf_fabric_prop_get_rsp *response;
|
||
|
int rc;
|
||
|
|
||
|
assert(size == SPDK_NVMF_PROP_SIZE_4 || size == SPDK_NVMF_PROP_SIZE_8);
|
||
|
|
||
|
cmd.opcode = SPDK_NVME_OPC_FABRIC;
|
||
|
cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET;
|
||
|
cmd.ofst = offset;
|
||
|
cmd.attrib.size = size;
|
||
|
|
||
|
rc = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, (struct spdk_nvme_cmd *)&cmd,
|
||
|
NULL, 0, nvme_completion_poll_cb,
|
||
|
&status);
|
||
|
if (rc < 0) {
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
if (spdk_nvme_wait_for_completion(ctrlr->adminq, &status)) {
|
||
|
SPDK_ERRLOG("Property Get failed\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
response = (struct spdk_nvmf_fabric_prop_get_rsp *)&status.cpl;
|
||
|
|
||
|
if (size == SPDK_NVMF_PROP_SIZE_4) {
|
||
|
*value = response->value.u32.low;
|
||
|
} else {
|
||
|
*value = response->value.u64;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
nvme_fabric_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value)
|
||
|
{
|
||
|
return nvme_fabric_prop_set_cmd(ctrlr, offset, SPDK_NVMF_PROP_SIZE_4, value);
|
||
|
}
|
||
|
|
||
|
int
|
||
|
nvme_fabric_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value)
|
||
|
{
|
||
|
return nvme_fabric_prop_set_cmd(ctrlr, offset, SPDK_NVMF_PROP_SIZE_8, value);
|
||
|
}
|
||
|
|
||
|
int
|
||
|
nvme_fabric_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value)
|
||
|
{
|
||
|
uint64_t tmp_value;
|
||
|
int rc;
|
||
|
rc = nvme_fabric_prop_get_cmd(ctrlr, offset, SPDK_NVMF_PROP_SIZE_4, &tmp_value);
|
||
|
|
||
|
if (!rc) {
|
||
|
*value = (uint32_t)tmp_value;
|
||
|
}
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
nvme_fabric_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value)
|
||
|
{
|
||
|
return nvme_fabric_prop_get_cmd(ctrlr, offset, SPDK_NVMF_PROP_SIZE_8, value);
|
||
|
}
|