diff options
author | Neelesh Gupta <neelegup@linux.vnet.ibm.com> | 2015-08-31 21:12:07 +0530 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-09-01 17:13:03 +1000 |
commit | 87bceba1846dc00e687ed3370eb3fd71fb02c8ca (patch) | |
tree | de957d107feb34be8ef09d8a6cfb93e0304fc207 | |
parent | 2c50e850d01e8387c883decbadfa2a02e78772d6 (diff) | |
download | skiboot-87bceba1846dc00e687ed3370eb3fd71fb02c8ca.zip skiboot-87bceba1846dc00e687ed3370eb3fd71fb02c8ca.tar.gz skiboot-87bceba1846dc00e687ed3370eb3fd71fb02c8ca.tar.bz2 |
external/opal-prd: Refactor the handle_prd_control() function
Depending upon the control message type, the daemon parses the incoming
messages, invoke the corresponding HBRT interface and sends the response
back to the waiting client. Putting all this into one leads to cumbersome
switch-case and a fat function.
This patch creates the individual functions for different types of control
messages keeping the common code into the handle_prd_control(). It also
does clean up and minor fixes.
Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Acked-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Patrick Williams <iawillia@us.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | external/opal-prd/opal-prd.c | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c index f96e145..00ca96e 100644 --- a/external/opal-prd/opal-prd.c +++ b/external/opal-prd/opal-prd.c @@ -1134,71 +1134,85 @@ static int handle_prd_msg(struct opal_prd_ctx *ctx) return 0; } -static int handle_prd_control(struct opal_prd_ctx *ctx, int fd) +static void handle_prd_control_occ_error(struct control_msg *msg) +{ + if (!hservice_runtime->process_occ_error) { + pr_log_nocall("process_occ_error"); + return; + } + + pr_debug("CTRL: calling process_occ_error(0)"); + call_process_occ_error(0); + msg->response = 0; +} + +static void handle_prd_control_occ_reset(struct control_msg *msg) +{ + if (!hservice_runtime->process_occ_reset) { + pr_log_nocall("process_occ_reset"); + return; + } + + pr_debug("CTRL: calling process_occ_reset(0)"); + call_process_occ_reset(0); + msg->response = 0; +} + +static void handle_prd_control_occ_actuation(struct control_msg *msg, + bool enable) +{ + if (!hservice_runtime->enable_occ_actuation) { + pr_log_nocall("enable_occ_actuation"); + return; + } + + pr_debug("CTRL: calling enable_occ_actuation(%s)", + enable ? "true" : "false"); + msg->response = call_enable_occ_actuation(enable); +} + +static void handle_prd_control(struct opal_prd_ctx *ctx, int fd) { struct control_msg msg; - bool enabled; + bool enabled = false; int rc; rc = recv(fd, &msg, sizeof(msg), MSG_TRUNC); if (rc != sizeof(msg)) { - pr_log(LOG_WARNING, "CTRL: failed to receive " - "control message: %m"); - rc = -1; + pr_log(LOG_WARNING, "CTRL: failed to receive control " + "message: %m"); + msg.response = -1; goto out_send; } - enabled = false; - rc = -1; - + msg.response = -1; switch (msg.type) { case CONTROL_MSG_ENABLE_OCCS: enabled = true; /* fall through */ case CONTROL_MSG_DISABLE_OCCS: - if (!hservice_runtime->enable_occ_actuation) { - pr_log_nocall("enable_occ_actuation"); - } else { - pr_debug("CTRL: calling enable_occ_actuation(%s)", - enabled ? "true" : "false"); - rc = call_enable_occ_actuation(enabled); - pr_debug("CTRL: -> %d", rc); - } + handle_prd_control_occ_actuation(&msg, enabled); break; case CONTROL_MSG_TEMP_OCC_RESET: - if (hservice_runtime->process_occ_reset) { - pr_debug("CTRL: calling process_occ_reset(0)"); - call_process_occ_reset(0); - rc = 0; - } else { - pr_log_nocall("process_occ_reset"); - } + handle_prd_control_occ_reset(&msg); break; case CONTROL_MSG_TEMP_OCC_ERROR: - if (hservice_runtime->process_occ_error) { - pr_debug("CTRL: calling process_occ_error(0)"); - call_process_occ_error(0); - rc = 0; - } else { - pr_log_nocall("process_occ_error"); - } + handle_prd_control_occ_error(&msg); break; default: pr_log(LOG_WARNING, "CTRL: Unknown control message action %d", msg.type); + break; } out_send: /* send a response */ - msg.response = rc; rc = send(fd, &msg, sizeof(msg), MSG_DONTWAIT | MSG_NOSIGNAL); if (rc && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE)) pr_debug("CTRL: control send() returned %d, ignoring failure", rc); else if (rc != sizeof(msg)) pr_log(LOG_NOTICE, "CTRL: Failed to send control response: %m"); - - return 0; } static int run_attn_loop(struct opal_prd_ctx *ctx) |