Skip to content

Commit

Permalink
feat: Adding test unit ready command if request sense does not report…
Browse files Browse the repository at this point in the history
… power mode

Adding in issuing a test unit ready command to try and determine if the drive is in a low-power mode by checking if the sense data reports a need for a spin-up command.

[Seagate/openSeaChest#155]

Signed-off-by: Tyler Erickson <[email protected]>
  • Loading branch information
vonericsen committed Sep 6, 2024
1 parent bcf45cf commit 7dc76a5
Showing 1 changed file with 50 additions and 30 deletions.
80 changes: 50 additions & 30 deletions src/power_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,23 @@ eReturnValues print_Current_Power_Mode(tDevice *device)
ret = FAILURE;
}
}
else if (device->drive_info.drive_type == SCSI_DRIVE)
else if (device->drive_info.drive_type == NVME_DRIVE)
{
uint32_t powerMode = 0;
ret = get_Power_State(device, &powerMode, CURRENT_VALUE);
if (ret == SUCCESS)
{
printf("Device is in Power State %" PRIu32 "\n", powerMode);
}
else
{
if (VERBOSITY_QUIET < device->deviceVerbosity)
{
printf("Unable to retrive current power state!\n");
}
}
}
else
{
/*
NOTE: Removed the code which was checking to see if the power mode is supported
Expand All @@ -207,6 +223,7 @@ eReturnValues print_Current_Power_Mode(tDevice *device)
}
if (SUCCESS == scsi_Request_Sense_Cmd(device, false, senseData, SPC3_SENSE_LEN))
{
bool issuetur = false;
//requested fixed format sensedata, so parse it. If we don't find what we are looking for post the "unable to retrieve current power mode" message
if ((senseData[0] & 0x7F) == SCSI_SENSE_CUR_INFO_FIXED || (senseData[0] & 0x7F) == SCSI_SENSE_DEFER_ERR_FIXED)
{
Expand Down Expand Up @@ -253,50 +270,53 @@ eReturnValues print_Current_Power_Mode(tDevice *device)
printf("Standby_Y state activated by host command\n");
break;
default:
printf("Active State or in an Unknown state.\n");
issuetur = true;
break;
}
break;
default:
printf("Active State or in an Unknown state.\n");
issuetur = true;
break;
}

}
else
{
if (VERBOSITY_QUIET < device->deviceVerbosity)
issuetur = true;
}
if (issuetur == true)
{
scsiStatus returnedStatus;
memset(&returnedStatus, 0, sizeof(scsiStatus));
ret = scsi_Test_Unit_Ready(device, &returnedStatus);
if ((ret == SUCCESS) && (returnedStatus.senseKey == SENSE_KEY_NO_ERROR))
{
printf("Unable to retrive current power mode!\n");
//assume active state
printf("Device is in active state or an unknown power state.\n");
}
else if (returnedStatus.senseKey == SENSE_KEY_NOT_READY)
{
//check asc and ascq if spinup command is required
if (returnedStatus.asc == 0x04 && returnedStatus.ascq == 0x02)
{
printf("Standby state\n");//activated by host command???
}
else
{
printf("Unknown power state. Unit reports: ");
show_Test_Unit_Ready_Status(device);
}
}
else
{
printf("Unknown power state. Unit reports: ");
show_Test_Unit_Ready_Status(device);
ret = FAILURE;
}
ret = FAILURE;
}
}
safe_free_aligned(&senseData);
}
else if (device->drive_info.drive_type == NVME_DRIVE)
{
uint32_t powerMode = 0;
ret = get_Power_State(device, &powerMode, CURRENT_VALUE);
if (ret == SUCCESS)
{
printf("Device is in Power State %" PRIu32 "\n", powerMode);
}
else
{
if (VERBOSITY_QUIET < device->deviceVerbosity)
{
printf("Unable to retrive current power state!\n");
}
}
}
else
{
if (VERBOSITY_QUIET < device->deviceVerbosity)
{
printf("Showing the current power mode is not supported on this drive type at this time\n");
}
ret = NOT_SUPPORTED;
}
return ret;
}

Expand Down

0 comments on commit 7dc76a5

Please sign in to comment.