2015-09-21 08:52:41 -07:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 10:47:22 -07:00
|
|
|
* Copyright (c) Intel Corporation.
|
2015-09-21 08:52:41 -07: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.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 11:18:25 -07:00
|
|
|
#include "spdk/stdinc.h"
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2017-02-10 16:34:08 +08:00
|
|
|
#include "spdk/log.h"
|
2015-09-21 08:52:41 -07:00
|
|
|
#include "spdk/nvme.h"
|
2016-08-10 10:41:12 -07:00
|
|
|
#include "spdk/env.h"
|
2015-09-21 08:52:41 -07:00
|
|
|
|
|
|
|
#define MAX_DEVS 64
|
|
|
|
|
|
|
|
struct dev {
|
2016-02-10 11:26:12 -07:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2016-02-09 11:06:48 -07:00
|
|
|
struct spdk_nvme_health_information_page *health_page;
|
2018-04-09 21:05:33 -04:00
|
|
|
struct spdk_nvme_ns_list *changed_ns_list;
|
2016-02-09 11:06:48 -07:00
|
|
|
uint32_t orig_temp_threshold;
|
2018-03-02 12:49:36 -07:00
|
|
|
char name[SPDK_NVMF_TRADDR_MAX_LEN + 1];
|
2015-09-21 08:52:41 -07:00
|
|
|
};
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
static void get_feature_test(struct dev *dev);
|
2017-02-20 10:37:31 +08:00
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
static struct dev devs[MAX_DEVS];
|
|
|
|
static int num_devs = 0;
|
|
|
|
|
|
|
|
#define foreach_dev(iter) \
|
|
|
|
for (iter = devs; iter - devs < num_devs; iter++)
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
static int outstanding_commands = 0;
|
|
|
|
static int aer_done = 0;
|
2015-09-21 08:52:41 -07:00
|
|
|
static int temperature_done = 0;
|
2016-01-05 16:45:33 -07:00
|
|
|
static int failed = 0;
|
2017-02-10 16:34:08 +08:00
|
|
|
static struct spdk_nvme_transport_id g_trid;
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2018-04-02 01:12:27 -04:00
|
|
|
/* Enable AER temperature test */
|
|
|
|
static int enable_temp_test = 0;
|
2018-04-09 21:05:33 -04:00
|
|
|
/* Enable AER namespace attribute notice test, this variable holds
|
|
|
|
* the NSID that is expected to be in the Changed NS List.
|
|
|
|
*/
|
|
|
|
static uint32_t expected_ns_test = 0;
|
2018-04-02 01:12:27 -04:00
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
static void
|
|
|
|
set_temp_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
2016-01-05 16:45:33 -07:00
|
|
|
struct dev *dev = cb_arg;
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
outstanding_commands--;
|
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
2016-01-05 16:45:33 -07:00
|
|
|
printf("%s: set feature (temp threshold) failed\n", dev->name);
|
|
|
|
failed = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
/* Admin command completions are synchronized by the NVMe driver,
|
|
|
|
* so we don't need to do any special locking here. */
|
|
|
|
temperature_done++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_temp_threshold(struct dev *dev, uint32_t temp)
|
|
|
|
{
|
2016-02-09 11:06:48 -07:00
|
|
|
struct spdk_nvme_cmd cmd = {};
|
2017-06-19 10:27:03 -07:00
|
|
|
int rc;
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
cmd.opc = SPDK_NVME_OPC_SET_FEATURES;
|
|
|
|
cmd.cdw10 = SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD;
|
2015-09-21 08:52:41 -07:00
|
|
|
cmd.cdw11 = temp;
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
rc = spdk_nvme_ctrlr_cmd_admin_raw(dev->ctrlr, &cmd, NULL, 0, set_temp_completion, dev);
|
|
|
|
if (rc == 0) {
|
|
|
|
outstanding_commands++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-19 10:27:03 -07:00
|
|
|
get_temp_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
|
|
|
struct dev *dev = cb_arg;
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
outstanding_commands--;
|
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
2015-09-21 08:52:41 -07:00
|
|
|
printf("%s: get feature (temp threshold) failed\n", dev->name);
|
2016-01-05 16:45:33 -07:00
|
|
|
failed = 1;
|
|
|
|
return;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
dev->orig_temp_threshold = cpl->cdw0;
|
|
|
|
printf("%s: original temperature threshold: %u Kelvin (%d Celsius)\n",
|
|
|
|
dev->name, dev->orig_temp_threshold, dev->orig_temp_threshold - 273);
|
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
temperature_done++;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_temp_threshold(struct dev *dev)
|
|
|
|
{
|
2016-02-09 11:06:48 -07:00
|
|
|
struct spdk_nvme_cmd cmd = {};
|
2017-06-19 10:27:03 -07:00
|
|
|
int rc;
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
cmd.opc = SPDK_NVME_OPC_GET_FEATURES;
|
|
|
|
cmd.cdw10 = SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD;
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
rc = spdk_nvme_ctrlr_cmd_admin_raw(dev->ctrlr, &cmd, NULL, 0, get_temp_completion, dev);
|
|
|
|
if (rc == 0) {
|
|
|
|
outstanding_commands++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-09 11:06:48 -07:00
|
|
|
print_health_page(struct dev *dev, struct spdk_nvme_health_information_page *hip)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
|
|
|
printf("%s: Current Temperature: %u Kelvin (%d Celsius)\n",
|
|
|
|
dev->name, hip->temperature, hip->temperature - 273);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-02 01:12:27 -04:00
|
|
|
get_health_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
|
|
|
struct dev *dev = cb_arg;
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
outstanding_commands --;
|
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
2015-09-21 08:52:41 -07:00
|
|
|
printf("%s: get log page failed\n", dev->name);
|
2016-01-05 16:45:33 -07:00
|
|
|
failed = 1;
|
|
|
|
return;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
print_health_page(dev, dev->health_page);
|
2015-09-21 08:52:41 -07:00
|
|
|
aer_done++;
|
|
|
|
}
|
|
|
|
|
2018-04-09 21:05:33 -04:00
|
|
|
static void
|
|
|
|
get_changed_ns_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct dev *dev = cb_arg;
|
|
|
|
bool found = false;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
outstanding_commands --;
|
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
|
|
|
printf("%s: get log page failed\n", dev->name);
|
|
|
|
failed = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Let's compare the expected namespce ID is
|
|
|
|
* in changed namespace list
|
|
|
|
*/
|
|
|
|
if (dev->changed_ns_list->ns_list[0] != 0xffffffffu) {
|
|
|
|
for (i = 0; i < sizeof(*dev->changed_ns_list) / sizeof(uint32_t); i++) {
|
|
|
|
if (expected_ns_test == dev->changed_ns_list->ns_list[i]) {
|
|
|
|
printf("%s: changed NS list contains expected NSID: %u\n",
|
|
|
|
dev->name, expected_ns_test);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2018-08-27 16:24:40 +08:00
|
|
|
printf("%s: Error: Can't find expected NSID %u\n", dev->name, expected_ns_test);
|
2018-04-09 21:05:33 -04:00
|
|
|
failed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
aer_done++;
|
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
static int
|
|
|
|
get_health_log_page(struct dev *dev)
|
|
|
|
{
|
2017-06-19 10:27:03 -07:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_nvme_ctrlr_cmd_get_log_page(dev->ctrlr, SPDK_NVME_LOG_HEALTH_INFORMATION,
|
|
|
|
SPDK_NVME_GLOBAL_NS_TAG, dev->health_page, sizeof(*dev->health_page), 0,
|
2018-04-02 01:12:27 -04:00
|
|
|
get_health_log_page_completion, dev);
|
2018-04-09 21:05:33 -04:00
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
outstanding_commands++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_changed_ns_log_page(struct dev *dev)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_nvme_ctrlr_cmd_get_log_page(dev->ctrlr, SPDK_NVME_LOG_CHANGED_NS_LIST,
|
|
|
|
SPDK_NVME_GLOBAL_NS_TAG, dev->changed_ns_list,
|
|
|
|
sizeof(*dev->changed_ns_list), 0,
|
|
|
|
get_changed_ns_log_page_completion, dev);
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
if (rc == 0) {
|
|
|
|
outstanding_commands++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup(void)
|
|
|
|
{
|
|
|
|
struct dev *dev;
|
|
|
|
|
|
|
|
foreach_dev(dev) {
|
|
|
|
if (dev->health_page) {
|
2017-05-25 14:21:30 -04:00
|
|
|
spdk_dma_free(dev->health_page);
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
2018-04-09 21:05:33 -04:00
|
|
|
if (dev->changed_ns_list) {
|
|
|
|
spdk_dma_free(dev->changed_ns_list);
|
|
|
|
}
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
static void
|
|
|
|
aer_cb(void *arg, const struct spdk_nvme_cpl *cpl)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
|
|
|
uint32_t log_page_id = (cpl->cdw0 & 0xFF0000) >> 16;
|
|
|
|
struct dev *dev = arg;
|
|
|
|
|
2016-02-09 11:06:48 -07:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
2016-01-05 16:45:33 -07:00
|
|
|
printf("%s: AER failed\n", dev->name);
|
|
|
|
failed = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
printf("%s: aer_cb for log page %d\n", dev->name, log_page_id);
|
|
|
|
|
2018-04-09 21:05:33 -04:00
|
|
|
if (log_page_id == SPDK_NVME_LOG_HEALTH_INFORMATION) {
|
|
|
|
/* Set the temperature threshold back to the original value
|
|
|
|
* so the AER doesn't trigger again.
|
|
|
|
*/
|
|
|
|
set_temp_threshold(dev, dev->orig_temp_threshold);
|
|
|
|
get_health_log_page(dev);
|
|
|
|
} else if (log_page_id == SPDK_NVME_LOG_CHANGED_NS_LIST) {
|
|
|
|
get_changed_ns_log_page(dev);
|
|
|
|
}
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
2017-02-10 16:34:08 +08:00
|
|
|
static void
|
|
|
|
usage(const char *program_name)
|
|
|
|
{
|
|
|
|
printf("%s [options]", program_name);
|
|
|
|
printf("\n");
|
|
|
|
printf("options:\n");
|
2018-04-02 01:12:27 -04:00
|
|
|
printf(" -T enable temperature tests\n");
|
2018-04-09 21:05:33 -04:00
|
|
|
printf(" -n expected Namespace attribute notice ID\n");
|
2017-02-10 16:34:08 +08:00
|
|
|
printf(" -r trid remote NVMe over Fabrics target address\n");
|
|
|
|
printf(" Format: 'key:value [key:value] ...'\n");
|
|
|
|
printf(" Keys:\n");
|
|
|
|
printf(" trtype Transport type (e.g. RDMA)\n");
|
|
|
|
printf(" adrfam Address family (e.g. IPv4, IPv6)\n");
|
|
|
|
printf(" traddr Transport address (e.g. 192.168.100.8)\n");
|
|
|
|
printf(" trsvcid Transport service identifier (e.g. 4420)\n");
|
|
|
|
printf(" subnqn Subsystem NQN (default: %s)\n", SPDK_NVMF_DISCOVERY_NQN);
|
|
|
|
printf(" Example: -r 'trtype:RDMA adrfam:IPv4 traddr:192.168.100.8 trsvcid:4420'\n");
|
|
|
|
|
2018-11-26 23:57:58 -07:00
|
|
|
spdk_log_usage(stdout, "-L");
|
2017-02-10 16:34:08 +08:00
|
|
|
|
|
|
|
printf(" -v verbose (enable warnings)\n");
|
|
|
|
printf(" -H show this usage\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_args(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int op, rc;
|
|
|
|
|
|
|
|
g_trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
|
|
|
|
snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
|
|
|
|
|
2018-06-20 02:00:41 +08:00
|
|
|
while ((op = getopt(argc, argv, "n:r:HL:T")) != -1) {
|
2017-02-10 16:34:08 +08:00
|
|
|
switch (op) {
|
2018-04-09 21:05:33 -04:00
|
|
|
case 'n':
|
|
|
|
expected_ns_test = atoi(optarg);
|
|
|
|
break;
|
2018-06-20 02:00:41 +08:00
|
|
|
case 'r':
|
|
|
|
if (spdk_nvme_transport_id_parse(&g_trid, optarg) != 0) {
|
|
|
|
fprintf(stderr, "Error parsing transport address\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
2018-11-26 23:57:58 -07:00
|
|
|
rc = spdk_log_set_flag(optarg);
|
2017-02-10 16:34:08 +08:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "unknown flag\n");
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2017-07-10 10:59:56 -07:00
|
|
|
spdk_log_set_print_level(SPDK_LOG_DEBUG);
|
2017-02-10 16:34:08 +08:00
|
|
|
#ifndef DEBUG
|
2018-06-20 02:00:41 +08:00
|
|
|
fprintf(stderr, "%s must be rebuilt with CONFIG_DEBUG=y for -L flag.\n",
|
2017-02-10 16:34:08 +08:00
|
|
|
argv[0]);
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
break;
|
2018-04-02 01:12:27 -04:00
|
|
|
case 'T':
|
|
|
|
enable_temp_test = 1;
|
|
|
|
break;
|
2017-02-10 16:34:08 +08:00
|
|
|
case 'H':
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-29 13:15:29 -07:00
|
|
|
|
|
|
|
static bool
|
2016-12-09 15:09:28 -07:00
|
|
|
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 16:55:14 -07:00
|
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
2016-01-29 13:15:29 -07:00
|
|
|
{
|
2016-12-09 15:09:28 -07:00
|
|
|
printf("Attaching to %s\n", trid->traddr);
|
2016-01-29 13:15:29 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-09 15:09:28 -07:00
|
|
|
attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 16:55:14 -07:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
2016-01-29 13:15:29 -07:00
|
|
|
{
|
|
|
|
struct dev *dev;
|
|
|
|
|
|
|
|
/* add to dev list */
|
|
|
|
dev = &devs[num_devs++];
|
|
|
|
|
|
|
|
dev->ctrlr = ctrlr;
|
|
|
|
|
2016-12-09 14:23:55 -07:00
|
|
|
snprintf(dev->name, sizeof(dev->name), "%s",
|
2016-12-09 15:09:28 -07:00
|
|
|
trid->traddr);
|
2016-01-29 13:15:29 -07:00
|
|
|
|
|
|
|
printf("Attached to %s\n", dev->name);
|
|
|
|
|
2017-05-25 14:21:30 -04:00
|
|
|
dev->health_page = spdk_dma_zmalloc(sizeof(*dev->health_page), 4096, NULL);
|
2016-01-29 13:15:29 -07:00
|
|
|
if (dev->health_page == NULL) {
|
|
|
|
printf("Allocation error (health page)\n");
|
|
|
|
failed = 1;
|
|
|
|
}
|
2018-04-09 21:05:33 -04:00
|
|
|
dev->changed_ns_list = spdk_dma_zmalloc(sizeof(*dev->changed_ns_list), 4096, NULL);
|
|
|
|
if (dev->changed_ns_list == NULL) {
|
|
|
|
printf("Allocation error (changed namespace list page)\n");
|
|
|
|
failed = 1;
|
|
|
|
}
|
2016-01-29 13:15:29 -07:00
|
|
|
}
|
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
static void
|
2017-06-19 10:27:03 -07:00
|
|
|
get_feature_test_cb(void *cb_arg, const struct spdk_nvme_cpl *cpl)
|
2017-02-20 10:37:31 +08:00
|
|
|
{
|
|
|
|
struct dev *dev = cb_arg;
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
outstanding_commands--;
|
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
|
|
|
printf("%s: get number of queues failed\n", dev->name);
|
|
|
|
failed = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
if (aer_done < num_devs) {
|
|
|
|
/*
|
|
|
|
* Resubmit Get Features command to continue filling admin queue
|
|
|
|
* while the test is running.
|
|
|
|
*/
|
|
|
|
get_feature_test(dev);
|
|
|
|
}
|
2017-02-20 10:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_feature_test(struct dev *dev)
|
|
|
|
{
|
2017-06-19 10:27:03 -07:00
|
|
|
struct spdk_nvme_cmd cmd;
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.opc = SPDK_NVME_OPC_GET_FEATURES;
|
|
|
|
cmd.cdw10 = SPDK_NVME_FEAT_NUMBER_OF_QUEUES;
|
|
|
|
if (spdk_nvme_ctrlr_cmd_admin_raw(dev->ctrlr, &cmd, NULL, 0,
|
|
|
|
get_feature_test_cb, dev) != 0) {
|
|
|
|
printf("Failed to send Get Features command for dev=%p\n", dev);
|
|
|
|
failed = 1;
|
|
|
|
return;
|
2017-02-20 10:37:31 +08:00
|
|
|
}
|
2017-06-19 10:27:03 -07:00
|
|
|
|
|
|
|
outstanding_commands++;
|
2017-02-20 10:37:31 +08:00
|
|
|
}
|
|
|
|
|
2018-04-02 01:12:27 -04:00
|
|
|
static int
|
|
|
|
spdk_aer_temperature_test(void)
|
2015-09-21 08:52:41 -07:00
|
|
|
{
|
2018-04-02 01:12:27 -04:00
|
|
|
struct dev *dev;
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
printf("Getting temperature thresholds of all controllers...\n");
|
2015-09-21 08:52:41 -07:00
|
|
|
foreach_dev(dev) {
|
2017-02-20 10:37:31 +08:00
|
|
|
/* Get the original temperature threshold */
|
2015-09-21 08:52:41 -07:00
|
|
|
get_temp_threshold(dev);
|
|
|
|
}
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
while (!failed && temperature_done < num_devs) {
|
2015-09-21 08:52:41 -07:00
|
|
|
foreach_dev(dev) {
|
2016-02-10 11:26:12 -07:00
|
|
|
spdk_nvme_ctrlr_process_admin_completions(dev->ctrlr);
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
if (failed) {
|
2018-04-02 01:12:27 -04:00
|
|
|
return failed;
|
2017-02-20 10:37:31 +08:00
|
|
|
}
|
|
|
|
temperature_done = 0;
|
2018-04-02 01:12:27 -04:00
|
|
|
aer_done = 0;
|
2017-02-20 10:37:31 +08:00
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
/* Send admin commands to test admin queue wraparound while waiting for the AER */
|
2017-02-20 10:37:31 +08:00
|
|
|
foreach_dev(dev) {
|
|
|
|
get_feature_test(dev);
|
|
|
|
}
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
if (failed) {
|
2018-04-02 01:12:27 -04:00
|
|
|
return failed;
|
2016-01-05 16:45:33 -07:00
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
printf("Waiting for all controllers to trigger AER...\n");
|
2017-02-20 10:37:31 +08:00
|
|
|
foreach_dev(dev) {
|
|
|
|
/* Set the temperature threshold to a low value */
|
|
|
|
set_temp_threshold(dev, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
2018-04-02 01:12:27 -04:00
|
|
|
return failed;
|
2017-02-20 10:37:31 +08:00
|
|
|
}
|
2015-09-21 08:52:41 -07:00
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
while (!failed && (aer_done < num_devs || temperature_done < num_devs)) {
|
2015-09-21 08:52:41 -07:00
|
|
|
foreach_dev(dev) {
|
2016-02-10 11:26:12 -07:00
|
|
|
spdk_nvme_ctrlr_process_admin_completions(dev->ctrlr);
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:12:27 -04:00
|
|
|
if (failed) {
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-09 21:05:33 -04:00
|
|
|
static int
|
|
|
|
spdk_aer_changed_ns_test(void)
|
|
|
|
{
|
|
|
|
struct dev *dev;
|
|
|
|
|
|
|
|
aer_done = 0;
|
|
|
|
|
|
|
|
printf("Starting namespce attribute notice tests for all controllers...\n");
|
|
|
|
|
|
|
|
foreach_dev(dev) {
|
|
|
|
get_feature_test(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!failed && (aer_done < num_devs)) {
|
|
|
|
foreach_dev(dev) {
|
|
|
|
spdk_nvme_ctrlr_process_admin_completions(dev->ctrlr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:12:27 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct dev *dev;
|
|
|
|
int i;
|
|
|
|
struct spdk_env_opts opts;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = parse_args(argc, argv);
|
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_env_opts_init(&opts);
|
|
|
|
opts.name = "aer";
|
|
|
|
opts.core_mask = "0x1";
|
2018-11-09 16:12:19 +01:00
|
|
|
opts.mem_size = 64;
|
2018-04-02 01:12:27 -04:00
|
|
|
if (spdk_env_init(&opts) < 0) {
|
|
|
|
fprintf(stderr, "Unable to initialize SPDK env\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Asynchronous Event Request test\n");
|
|
|
|
|
|
|
|
if (spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL) != 0) {
|
|
|
|
fprintf(stderr, "spdk_nvme_probe() failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-20 10:37:31 +08:00
|
|
|
if (failed) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:12:27 -04:00
|
|
|
printf("Registering asynchronous event callbacks...\n");
|
|
|
|
foreach_dev(dev) {
|
|
|
|
spdk_nvme_ctrlr_register_aer_callback(dev->ctrlr, aer_cb, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AER temperature test */
|
|
|
|
if (enable_temp_test) {
|
|
|
|
if (spdk_aer_temperature_test()) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 21:05:33 -04:00
|
|
|
/* AER changed namespace list test */
|
|
|
|
if (expected_ns_test) {
|
|
|
|
if (spdk_aer_changed_ns_test()) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
printf("Cleaning up...\n");
|
|
|
|
|
2017-06-19 10:27:03 -07:00
|
|
|
while (outstanding_commands) {
|
|
|
|
foreach_dev(dev) {
|
|
|
|
spdk_nvme_ctrlr_process_admin_completions(dev->ctrlr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 08:52:41 -07:00
|
|
|
for (i = 0; i < num_devs; i++) {
|
|
|
|
struct dev *dev = &devs[i];
|
|
|
|
|
2016-02-10 11:26:12 -07:00
|
|
|
spdk_nvme_detach(dev->ctrlr);
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
done:
|
2015-09-21 08:52:41 -07:00
|
|
|
cleanup();
|
|
|
|
|
2016-01-05 16:45:33 -07:00
|
|
|
return failed;
|
2015-09-21 08:52:41 -07:00
|
|
|
}
|