Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocp lid fid #2641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions plugins/ocp/ocp-clear-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
*/

#include <unistd.h>
#include "util/types.h"
#include "ocp-nvme.h"
#include "ocp-utils.h"
#include "nvme-print.h"

static const __u8 OCP_FID_CLEAR_FW_ACTIVATION_HISTORY = 0xC1;
static const __u8 OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS = 0xC3;

static int ocp_clear_feature(int argc, char **argv, const char *desc, const __u8 fid)
{
__u32 result = 0;
Expand Down Expand Up @@ -80,14 +79,13 @@ int ocp_clear_fw_update_history(int argc, char **argv, struct command *cmd, stru
{
const char *desc = "OCP Clear Firmware Update History";

return ocp_clear_feature(argc, argv, desc, OCP_FID_CLEAR_FW_ACTIVATION_HISTORY);
return ocp_clear_feature(argc, argv, desc, OCP_FID_CFUH);
}

int ocp_clear_pcie_correctable_errors(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
struct plugin *plugin)
{
const char *desc = "OCP Clear PCIe Correctable Error Counters";

return ocp_clear_feature(argc, argv, desc,
OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS);
return ocp_clear_feature(argc, argv, desc, OCP_FID_CPCIE);
}
4 changes: 2 additions & 2 deletions plugins/ocp/ocp-fw-activation-history.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "common.h"
#include "nvme-print.h"

#include "ocp-nvme.h"
#include "ocp-utils.h"
#include "ocp-print.h"

Expand All @@ -26,7 +27,6 @@ static const unsigned char ocp_fw_activation_history_guid[GUID_LEN] = {
int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const __u8 log_id = 0xC2;
const char *description = "Retrieves the OCP firmware activation history log.";

char *format = "normal";
Expand Down Expand Up @@ -59,7 +59,7 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.lid = log_id,
.lid = (enum nvme_cmd_get_log_lid)OCP_LID_FAHL_OBSOLETE,
.len = sizeof(fw_history),
.nsid = NVME_NSID_ALL,
.csi = NVME_CSI_NVM,
Expand Down
36 changes: 24 additions & 12 deletions plugins/ocp/ocp-hardware-component-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
{
int ret = 0;
size_t desc_offset = offsetof(struct hwcomp_log, desc);
long double log_bytes;
nvme_uint128_t log_size;

struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.lid = LID_HWCOMP,
.lid = (enum nvme_cmd_get_log_lid)OCP_LID_HWCOMP,
.nsid = NVME_NSID_ALL,
.log = log,
.len = desc_offset,
Expand All @@ -193,16 +196,25 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
}
#endif /* HWCOMP_DUMMY */

print_info("id: %02Xh\n", LID_HWCOMP);
log_size = le128_to_cpu(log->size);

print_info("id: %02Xh\n", OCP_LID_HWCOMP);
print_info("version: %04Xh\n", log->ver);
print_info_array("guid", log->guid, ARRAY_SIZE(log->guid));
print_info("size: %s\n", uint128_t_to_string(le128_to_cpu(log->size)));
print_info("size: %s\n", uint128_t_to_string(log_size));

log_bytes = uint128_t_to_double(log_size);
if (log->ver == 1)
log_bytes *= sizeof(__le32);

if (log_bytes <= desc_offset) {
print_info_error("error: ocp: invalid hwcomp log size bytes: %.0Lf\n", log_bytes);
return -EINVAL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually it's better style to test and bail out directly, so

if (log_bytes <= desc_offset)
  return err;

args.len = log_bytes - desc_offset;

This keeps the logic in order, that is check if valid, then do the operation if it all is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes right so just fixed the changes as mentioned and rebased with the latest master code. Thank you.


args.len = log_bytes - desc_offset;

if (log->ver > 1)
args.len = uint128_t_to_double(le128_to_cpu(log->size)) - desc_offset;
else
args.len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32)
- desc_offset;
print_info("args.len: %u\n", args.len);

log->desc = calloc(1, args.len);
if (!log->desc) {
Expand All @@ -219,7 +231,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
ret = nvme_get_log_page(dev_fd(dev), NVME_LOG_PAGE_PDU_SIZE, &args);
if (ret) {
print_info_error("error: ocp: failed to get log page (hwcomp: %02X, ret: %d)\n",
LID_HWCOMP, ret);
OCP_LID_HWCOMP, ret);
return ret;
}
#endif /* HWCOMP_DUMMY */
Expand All @@ -246,7 +258,7 @@ static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list)
ret = get_hwcomp_log_data(dev, &log);
if (ret) {
print_info_error("error: ocp: failed get hwcomp log: %02X data, ret: %d\n",
LID_HWCOMP, ret);
OCP_LID_HWCOMP, ret);
return ret;
}

Expand Down Expand Up @@ -293,8 +305,8 @@ int ocp_hwcomp_log(int argc, char **argv, struct command *cmd, struct plugin *pl

ret = get_hwcomp_log(dev, cfg.id, cfg.list);
if (ret)
fprintf(stderr, "error: ocp: failed to get hwcomp log: %02X, ret: %d\n", LID_HWCOMP,
ret);
fprintf(stderr, "error: ocp: failed to get hwcomp log: %02X, ret: %d\n",
OCP_LID_HWCOMP, ret);

return ret;
}
1 change: 0 additions & 1 deletion plugins/ocp/ocp-hardware-component-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef OCP_HARDWARE_COMPONENT_LOG_H
#define OCP_HARDWARE_COMPONENT_LOG_H

#define LID_HWCOMP 0xc6
#define HWCOMP_RSVD2_LEN 14
#define HWCOMP_SIZE_LEN 16
#define HWCOMP_RSVD48_LEN 16
Expand Down
Loading
Loading