Skip to content

Commit

Permalink
Miscellaneous NVDIMM cleanup
Browse files Browse the repository at this point in the history
 - Move constants to .C file
 - Use constants for NVDIMM states
 - Clean up rt_cmds NVDIMM protection function

Change-Id: I3ff81c76971e962eb99e2f3b6ea1f109355d337a
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/81261
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Reviewed-by: Matt Derksen <mderkse1@us.ibm.com>
Reviewed-by: Daniel M Crowell <dcrowell@us.ibm.com>
  • Loading branch information
cvswen authored and dcrowell77 committed Jul 31, 2019
1 parent 44c6d59 commit f088a0d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 66 deletions.
2 changes: 2 additions & 0 deletions src/include/usr/isteps/nvdimm/nvdimm.H
Expand Up @@ -204,6 +204,7 @@ bool nvdimmDisarm(TARGETING::TargetHandleList &i_nvdimmTargetList);
* OCC_INACTIVE - set inactive state
* NVDIMM_FATAL_HW_ERROR - set fatal hw state
* NVDIMM_RISKY_HW_ERROR - set risky hw state
* NVDIMM_ENCRYPTION_ERROR - set encryption state
* Note: fatal error will stay with target preventing
* PROTECTED status until power is cycled again
*/
Expand All @@ -215,6 +216,7 @@ enum nvdimm_protection_t
OCC_INACTIVE = 3,
NVDIMM_FATAL_HW_ERROR = 4,
NVDIMM_RISKY_HW_ERROR = 5,
NVDIMM_ENCRYPTION_ERROR = 6,
/* deprecated, still used by PRD */
UNPROTECTED_BECAUSE_ERROR = 4,
};
Expand Down
15 changes: 13 additions & 2 deletions src/usr/isteps/nvdimm/nvdimm.C
Expand Up @@ -110,6 +110,8 @@ typedef union {

// Valid bits to check against (skips reserved and unsupported)
static constexpr uint8_t ENCRYPTION_STATUS_CHECK_MASK = 0x3F;
static constexpr uint8_t ENCRYPTION_STATUS_DISABLED = 0x01;
static constexpr uint8_t ENCRYPTION_STATUS_ENABLED = 0x1F;

// NV_STATUS masks
static constexpr uint8_t NV_STATUS_OR_MASK = 0xFB;
Expand All @@ -119,6 +121,12 @@ static constexpr uint8_t NV_STATUS_UNPROTECTED_CLEAR = 0xFE;
static constexpr uint8_t NV_STATUS_POSSIBLY_UNPROTECTED_SET = 0x40;
static constexpr uint8_t NV_STATUS_POSSIBLY_UNPROTECTED_CLEAR = 0xBF;

// NVDIMM key consts
static constexpr size_t NUM_KEYS_IN_ATTR = 3;
static constexpr size_t MAX_TPM_SIZE = 34;
static constexpr uint8_t KEY_TERMINATE_BYTE = 0x00;
static constexpr uint8_t KEY_ABORT_BYTE = 0xFF;

// Definition of ENCRYPTION_KEY_VALIDATION -- page 5 offset 0x2A
typedef union {
uint8_t whole;
Expand Down Expand Up @@ -2639,7 +2647,7 @@ bool nvdimm_encrypt_enable(TargetHandleList &i_nvdimmList)

// Need to handle these cases?
if (!((l_encStatus.whole & ENCRYPTION_STATUS_CHECK_MASK)
== 0x01))
== ENCRYPTION_STATUS_DISABLED))
{
TRACFCOMP(g_trac_nvdimm, "nvdimm_encrypt_enable() nvdimm[%X] unsupported state 0x%.02X",get_huid(l_nvdimm),l_encStatus.whole);
continue;
Expand Down Expand Up @@ -2702,7 +2710,7 @@ bool nvdimm_encrypt_enable(TargetHandleList &i_nvdimmList)
continue;
}
if (!((l_encStatus.whole & ENCRYPTION_STATUS_CHECK_MASK)
== 0x1F))
== ENCRYPTION_STATUS_ENABLED))
{
TRACFCOMP(g_trac_nvdimm, ERR_MRK"nvdimm_encrypt_enable() nvdimm[%X] encryption enable failed, ENCRYPTION_CONFIG_STATUS=0x%.02X, expected=0x1F ",get_huid(l_nvdimm),l_encStatus.whole);
/*@
Expand Down Expand Up @@ -3039,6 +3047,9 @@ errlHndl_t notifyNvdimmProtectionChange(Target* i_target,
case NVDIMM_RISKY_HW_ERROR:
l_armed_state.risky_error_detected = 1;
break;
case NVDIMM_ENCRYPTION_ERROR:
l_armed_state.encryption_error_detected = 1;
break;
}

// Set the attribute and send it to the FSP if needed
Expand Down
11 changes: 1 addition & 10 deletions src/usr/isteps/nvdimm/nvdimm.H
Expand Up @@ -378,19 +378,10 @@ enum misc
HIGH = 1,
};

const size_t NUM_KEYS_IN_ATTR = 3;
const size_t ENC_KEY_SIZE = 32;
const size_t MAX_TPM_SIZE = 34;
const uint8_t KEY_TERMINATE_BYTE = 0x00;
const uint8_t KEY_ABORT_BYTE = 0xFF;
const uint64_t DARN_ERROR_CODE = 0xFFFFFFFFFFFFFFFFull;
const uint32_t MAX_DARN_ERRORS = 10;
const uint32_t MAX_RANDOM_ATTEMPTS = 100;


/**
* @brief Encryption key data
*/
static constexpr size_t ENC_KEY_SIZE = 32;
struct nvdimmKeyData_t
{
uint8_t rs[ENC_KEY_SIZE]; // Random String (RS)
Expand Down
3 changes: 3 additions & 0 deletions src/usr/isteps/nvdimm/runtime/nvdimm_rt.C
Expand Up @@ -50,6 +50,9 @@ using namespace TARGETING;
namespace NVDIMM
{

static constexpr uint64_t DARN_ERROR_CODE = 0xFFFFFFFFFFFFFFFFull;
static constexpr uint32_t MAX_DARN_ERRORS = 10;

/**
* @brief This function polls the command status register for arm completion
* (does not indicate success or fail)
Expand Down
65 changes: 11 additions & 54 deletions src/usr/util/runtime/rt_cmds.C
Expand Up @@ -1162,63 +1162,20 @@ void cmd_nvdimm_protection_msg( char* &o_output, uint32_t i_huid,
{
errlHndl_t l_err = nullptr;
o_output = new char[500];
uint8_t l_notifyType = 0;

TARGETING::Target* l_targ{};
l_targ = getTargetFromHUID(i_huid);
if (l_targ != NULL)
{
if (protection == NVDIMM::NVDIMM_ARMED)
{
l_notifyType = NVDIMM::NVDIMM_ARMED;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::NVDIMM_ARMED);
}
else if (protection == NVDIMM::NVDIMM_DISARMED)
{
l_notifyType = NVDIMM::NVDIMM_DISARMED;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::NVDIMM_DISARMED);
}
else if (protection == NVDIMM::OCC_ACTIVE)
{
l_notifyType = NVDIMM::OCC_ACTIVE;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::OCC_ACTIVE);
}
else if (protection == NVDIMM::OCC_INACTIVE)
{
l_notifyType = NVDIMM::OCC_INACTIVE;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::OCC_INACTIVE);
}
else if (protection == NVDIMM::NVDIMM_FATAL_HW_ERROR)
{
l_notifyType = NVDIMM::NVDIMM_FATAL_HW_ERROR;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::NVDIMM_FATAL_HW_ERROR);
}
else if (protection == NVDIMM::NVDIMM_RISKY_HW_ERROR)
{
l_notifyType = NVDIMM::NVDIMM_RISKY_HW_ERROR;
l_err = notifyNvdimmProtectionChange(l_targ, NVDIMM::NVDIMM_RISKY_HW_ERROR);
}
else
{
sprintf( o_output,
"cmd_nvdimm_protection_msg: HUID 0x%.8X "
"unknown protection type 0x%.2X",
i_huid, protection );
}
if (l_err)
{
sprintf( o_output, "Error on call to notifyNvdimmProtectionChange"
"(0x%.8X, %d), rc=0x%.8X, plid=0x%.8X",
i_huid, l_notifyType, ERRL_GETRC_SAFE(l_err), l_err->plid() );
errlCommit(l_err, UTIL_COMP_ID);
return;
}
}
else

// protection should match enum from nvdimm_protection_t
// No match will just return, no error generated
l_err = notifyNvdimmProtectionChange( l_targ,
(NVDIMM::nvdimm_protection_t)protection);
if (l_err)
{
sprintf( o_output, "cmd_nvdimm_protection_msg: HUID 0x%.8X not found",
i_huid );
return;
sprintf( o_output, "Error on call to notifyNvdimmProtectionChange"
"(0x%.8X, %d), rc=0x%.8X, plid=0x%.8X",
i_huid, protection, ERRL_GETRC_SAFE(l_err), l_err->plid() );
errlCommit(l_err, UTIL_COMP_ID);
}
}
#endif
Expand Down Expand Up @@ -1543,7 +1500,7 @@ int hbrtCommand( int argc,
}
}
#ifdef CONFIG_NVDIMM
else if( !strcmp( argv[0], "nvdimm_protection" ) )
else if( !strcmp( argv[0], "nvdimm_protection" ) )
{
if (argc >= 3)
{
Expand Down

0 comments on commit f088a0d

Please sign in to comment.