Skip to content

Commit ff6cbb9

Browse files
jeff-lien-sndkigaw
authored andcommitted
sndk: Add drive-resize support for SN861 Drives
This commit will add support for the drive-resize sandisk pluging command on SN-861 drives. Signed-off-by: jeff-lien-sndk <[email protected]> Reviewed-by: Brandon Paupore <[email protected]>
1 parent cfc2a93 commit ff6cbb9

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

plugins/sandisk/sandisk-nvme.c

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,88 @@ static int sndk_clear_assert_dump(int argc, char **argv,
487487
return run_wdc_clear_assert_dump(argc, argv, command, plugin);
488488
}
489489

490+
#define SNDK_NVME_SN861_DRIVE_RESIZE_OPCODE 0xD1
491+
#define SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE 0x1000
492+
493+
static int sndk_do_sn861_drive_resize(struct nvme_dev *dev,
494+
uint64_t new_size,
495+
__u32 *result)
496+
{
497+
int ret;
498+
struct nvme_passthru_cmd admin_cmd;
499+
uint8_t buffer[SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE] = {0};
500+
501+
memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd));
502+
admin_cmd.opcode = SNDK_NVME_SN861_DRIVE_RESIZE_OPCODE;
503+
admin_cmd.cdw10 = 0x00000040;
504+
admin_cmd.cdw12 = 0x00000103;
505+
admin_cmd.cdw13 = 0x00000001;
506+
507+
memcpy(buffer, &new_size, sizeof(new_size));
508+
admin_cmd.addr = (__u64)(uintptr_t)buffer;
509+
admin_cmd.data_len = SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE;
510+
511+
ret = nvme_submit_admin_passthru(dev_fd(dev), &admin_cmd, result);
512+
return ret;
513+
}
514+
490515
static int sndk_drive_resize(int argc, char **argv,
491516
struct command *command,
492517
struct plugin *plugin)
493518
{
494-
return run_wdc_drive_resize(argc, argv, command, plugin);
519+
const char *desc = "Send a Resize command.";
520+
const char *size = "The new size (in GB) to resize the drive to.";
521+
uint64_t capabilities = 0;
522+
struct nvme_dev *dev;
523+
nvme_root_t r;
524+
int ret;
525+
uint32_t device_id = -1, vendor_id = -1;
526+
__u32 result;
527+
528+
struct config {
529+
uint64_t size;
530+
};
531+
532+
struct config cfg = {
533+
.size = 0,
534+
};
535+
536+
OPT_ARGS(opts) = {
537+
OPT_UINT("size", 's', &cfg.size, size),
538+
OPT_END()
539+
};
540+
541+
ret = parse_and_open(&dev, argc, argv, desc, opts);
542+
if (ret)
543+
return ret;
544+
545+
r = nvme_scan(NULL);
546+
sndk_check_device(r, dev);
547+
capabilities = sndk_get_drive_capabilities(r, dev);
548+
ret = sndk_get_pci_ids(r, dev, &device_id, &vendor_id);
549+
550+
if (((capabilities & SNDK_DRIVE_CAP_RESIZE) == SNDK_DRIVE_CAP_RESIZE) &&
551+
((device_id == SNDK_NVME_SN861_DEV_ID_U2) ||
552+
(device_id == SNDK_NVME_SN861_DEV_ID_E3S))) {
553+
ret = sndk_do_sn861_drive_resize(dev, cfg.size, &result);
554+
555+
if (!ret) {
556+
fprintf(stderr, "The drive-resize command was successful. A system ");
557+
fprintf(stderr, "shutdown is required to complete the operation.\n");
558+
} else
559+
fprintf(stderr, "ERROR: SNDK: %s failure, ret: %d, result: 0x%x\n",
560+
__func__, ret, result);
561+
} else {
562+
/* Fallback to WDC plugin command if otherwise not supported */
563+
nvme_free_tree(r);
564+
dev_close(dev);
565+
return run_wdc_drive_resize(argc, argv, command, plugin);
566+
}
567+
568+
nvme_show_status(ret);
569+
nvme_free_tree(r);
570+
dev_close(dev);
571+
return ret;
495572
}
496573

497574
static int sndk_vs_fw_activate_history(int argc, char **argv,

plugins/sandisk/sandisk-nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if !defined(SANDISK_NVME) || defined(CMD_HEADER_MULTI_READ)
66
#define SANDISK_NVME
77

8-
#define SANDISK_PLUGIN_VERSION "3.0.4"
8+
#define SANDISK_PLUGIN_VERSION "3.0.5"
99
#include "cmd.h"
1010

1111
PLUGIN(NAME("sndk", "Sandisk vendor specific extensions", SANDISK_PLUGIN_VERSION),

plugins/sandisk/sandisk-utils.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ __u64 sndk_get_drive_capabilities(nvme_root_t r, struct nvme_dev *dev)
172172
SNDK_DRIVE_CAP_SET_LATENCY_MONITOR);
173173
break;
174174

175+
case SNDK_NVME_SN861_DEV_ID_E1S:
176+
case SNDK_NVME_SN861_DEV_ID_U2:
177+
case SNDK_NVME_SN861_DEV_ID_E3S:
178+
capabilities |= (SNDK_DRIVE_CAP_C0_LOG_PAGE |
179+
SNDK_DRIVE_CAP_C3_LOG_PAGE |
180+
SNDK_DRIVE_CAP_CA_LOG_PAGE |
181+
SNDK_DRIVE_CAP_OCP_C4_LOG_PAGE |
182+
SNDK_DRIVE_CAP_OCP_C5_LOG_PAGE |
183+
SNDK_DRIVE_CAP_INTERNAL_LOG |
184+
SNDK_DRIVE_CAP_FW_ACTIVATE_HISTORY_C2 |
185+
SNDK_DRIVE_CAP_VU_FID_CLEAR_PCIE |
186+
SNDK_DRIVE_CAP_VU_FID_CLEAR_FW_ACT_HISTORY |
187+
SNDK_DRIVE_CAP_INFO |
188+
SNDK_DRIVE_CAP_CLOUD_SSD_VERSION |
189+
SNDK_DRIVE_CAP_LOG_PAGE_DIR |
190+
SNDK_DRIVE_CAP_DRIVE_STATUS |
191+
SNDK_DRIVE_CAP_RESIZE |
192+
SNDK_DRIVE_CAP_SET_LATENCY_MONITOR);
193+
break;
194+
175195
default:
176196
capabilities = 0;
177197
}

plugins/sandisk/sandisk-utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
#define SNDK_NVME_SN650_DEV_ID_4 0x2721
4141
#define SNDK_NVME_SN655_DEV_ID 0x2722
4242
#define SNDK_NVME_SN655_DEV_ID_1 0x2723
43-
#define SNDK_NVME_SN861_DEV_ID 0x2750
44-
#define SNDK_NVME_SN861_DEV_ID_1 0x2751
45-
#define SNDK_NVME_SN861_DEV_ID_2 0x2752
43+
#define SNDK_NVME_SN861_DEV_ID_E1S 0x2750
44+
#define SNDK_NVME_SN861_DEV_ID_U2 0x2751
45+
#define SNDK_NVME_SN861_DEV_ID_E3S 0x2752
4646
#define SNDK_NVME_SNTMP_DEV_ID 0x2761
4747
#define SNDK_NVME_SNTMP_DEV_ID_1 0x2763
4848

0 commit comments

Comments
 (0)