Hi Ravi,
On 03-09-2026 13:03, Ravi Kishore Koppuravuri wrote:
Add support for SET_ERROR_THRESHOLD to set the custom error threshold value Cc: Purkait Soham <soham.purkait@intel.com> Cc: Riana Tauro <riana.tauro@intel.com> Cc: Gupta Anshuman <anshuman.gupta@intel.com> Cc: Jadav Raag <raag.jadav@intel.com> Cc: Nilawar Badal <badal.nilawar@intel.com> Cc: Koujalagi Mallesh <mallesh.koujalagi@intel.com> Cc: Harish Chegondi <harish.chegondi@intel.com> Signed-off-by: Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com> --- v2:Marked this command as response not required v4:Renamed the library functions with prefix "igt_drm_netlink_*" (Nikula Jani & Kamil) --- lib/igt_drm_netlink.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/igt_drm_netlink.h | 1 + 2 files changed, 40 insertions(+) diff --git a/lib/igt_drm_netlink.c b/lib/igt_drm_netlink.c index 1be7d4361..c0e3aff9b 100644 --- a/lib/igt_drm_netlink.c +++ b/lib/igt_drm_netlink.c @@ -26,6 +26,8 @@ static int ras_command_cb(struct nl_msg *msg, void *arg) gnlh = nlmsg_data(nlh); switch (gnlh->cmd) { + case DRM_RAS_CMD_SET_ERROR_THRESHOLD: + break; case DRM_RAS_CMD_GET_ERROR_COUNTER: { struct nlattr *attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_MAX + 1]; @@ -201,6 +203,7 @@ static int send_command(struct app_context *ctx, uint8_t cmd) case DRM_RAS_CMD_GET_ERROR_THRESHOLD: case DRM_RAS_CMD_GET_ERROR_COUNTER: ctx->response_required = true; + case DRM_RAS_CMD_SET_ERROR_THRESHOLD: ret = nla_put_u32(msg, DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID, ctx->node_id); @@ -216,6 +219,16 @@ static int send_command(struct app_context *ctx, uint8_t cmd) nlmsg_free(msg); return ret; } + + if (cmd == DRM_RAS_CMD_SET_ERROR_THRESHOLD) {For this command, better to validate it in the "igt_drm_netlink_set_error_threshold" with error_threshold as a parameter in the same function.
Thanks, Soham
send_command() is the common function across multiple commands to prepare the message.
Here, if the command is DRM_RAS_CMD_SET_ERROR_THRESHOLD, then it adds the attribute DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD to the message otherwise not. it is part of preparing the message before sending. I feel that current location is appropriate for adding the threshold attribute by checking the set_error_threshold command.
Thanks,
Ravi Kishore K.
+ ret = nla_put_u32(msg, + DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD, + ctx->error_threshold); + if (ret < 0) { + nlmsg_free(msg); + return ret; + } + } break; default: nlmsg_free(msg); @@ -314,6 +327,14 @@ static int validate_inputs(struct app_context *ctx, uint8_t cmd) return -EINVAL; } + if (cmd == DRM_RAS_CMD_SET_ERROR_THRESHOLD && + (ctx->error_threshold < 1 || ctx->error_threshold > 16)) { + igt_warn("Invalid error_threshold (%u) provided. " + "error_threshold should be >= 1 and <= 16.\n", + ctx->error_threshold); + return -EINVAL; + } + return 0; } @@ -368,3 +389,21 @@ int igt_drm_netlink_get_error_threshold(struct app_context *ctx) return 0; } + +int igt_drm_netlink_set_error_threshold(struct app_context *ctx) +{ + int ret; + + ret = validate_inputs(ctx, DRM_RAS_CMD_SET_ERROR_THRESHOLD); + if (ret < 0) + return ret; + + ret = send_command(ctx, DRM_RAS_CMD_SET_ERROR_THRESHOLD); + if (ret < 0) + return ret; + + igt_debug("Set error threshold: node_id=%u error_id=%u threshold=%u\n", + ctx->node_id, ctx->error_id, ctx->error_threshold); + + return 0; +} diff --git a/lib/igt_drm_netlink.h b/lib/igt_drm_netlink.h index 89ef58243..9376e3dee 100644 --- a/lib/igt_drm_netlink.h +++ b/lib/igt_drm_netlink.h @@ -26,6 +26,7 @@ void igt_drm_netlink_cleanup(struct app_context *ctx); int igt_drm_netlink_init(struct app_context *ctx); int igt_drm_netlink_get_error_counter(struct app_context *ctx); int igt_drm_netlink_get_error_threshold(struct app_context *ctx); +int igt_drm_netlink_set_error_threshold(struct app_context *ctx); #endif /* IGT_DRM_NETLINK_H */