[Skiboot] [PATCH V3 05/15] core/pldm: Decode the SetStateEffecterStates request
Christophe Lombard
clombard at linux.vnet.ibm.com
Tue Sep 13 20:27:14 AEST 2022
The SetStateEffecterStates command is used to set the state of one or more
effecters within a PLDM State Effecter.
The field comp_effecter_count indicates the number of individual sets of
state effecter information that are accessed by this command.
The Event Receiver acknowledges receiving the PLDM Event Message in the
response to this command.
Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
core/pldm/pldm-responder.c | 130 +++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index 0224ea75..bbfd167d 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -8,9 +8,11 @@
#include <opal.h>
#include <stdio.h>
#include <string.h>
+#include <opal-msg.h>
#include <debug_descriptor.h>
#include <pldm/ibm/libpldm/platform_oem_ibm.h>
#include <pldm/libpldm/platform.h>
+#include <pldm/libpldm/state_set.h>
#include <pldm/libpldm/utils.h>
#include "pldm.h"
@@ -660,6 +662,132 @@ static struct pldm_cmd pldm_platform_get_state_sensor_readings = {
.handler = platform_get_state_sensor_readings,
};
+#define SOFT_OFF 0x00
+#define SOFT_REBOOT 0x01
+#define CHASSIS_PWR_DOWN 0x00
+#define DEFAULT_CHIP_ID 0
+
+struct effecter_states_req {
+ uint16_t effecter_id;
+ uint8_t comp_effecter_count;
+ set_effecter_state_field field[8];
+};
+
+/*
+ * SetStateEffecterStates (0x39)
+ * The SetStateEffecterStates command is used to set the state of one
+ * or more effecters within a PLDM State Effecter.
+ */
+static int platform_set_state_effecter_states_handler(const struct pldm_rx_data *req)
+{
+ struct effecter_states_req states_req;
+ set_effecter_state_field *field;
+ int rc, i;
+
+ /* decode SetStateEffecterStates request data */
+ rc = decode_set_state_effecter_states_req(
+ req->msg,
+ PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES,
+ &states_req.effecter_id,
+ &states_req.comp_effecter_count,
+ states_req.field);
+ if (rc) {
+ prlog(PR_ERR, "Failed to decode SetStateEffecterStates request, rc = %d\n", rc);
+ cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command, PLDM_ERROR);
+ return OPAL_INTERNAL_ERROR;
+ }
+
+ /* invoke the appropriate callback handler */
+ prlog(PR_DEBUG, "%s - effecter_id: %d, comp_effecter_count: %d\n",
+ __func__,
+ states_req.effecter_id,
+ states_req.comp_effecter_count);
+
+ for (i = 0; i < states_req.comp_effecter_count; i++) {
+ field = states_req.field;
+
+ /* other set_request not supported */
+ if (field->set_request != PLDM_REQUEST_SET) {
+ prlog(PR_ERR, "Got invalid set request 0x%x in "
+ "SetStateEffecterStates request\n",
+ field->set_request);
+ cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command,
+ PLDM_PLATFORM_INVALID_STATE_VALUE);
+ return OPAL_PARAMETER;
+ }
+
+ switch (field->effecter_state) {
+ case PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED:
+ case PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL:
+ prlog(PR_NOTICE, "Soft shutdown requested\n");
+ cc_resp(req, PLDM_PLATFORM,
+ PLDM_SET_STATE_EFFECTER_STATES,
+ PLDM_SUCCESS);
+
+ if (opal_booting() && platform.cec_power_down) {
+ prlog(PR_NOTICE, "Host not up, shutting down now\n");
+ platform.cec_power_down(CHASSIS_PWR_DOWN);
+ } else {
+ opal_queue_msg(OPAL_MSG_SHUTDOWN,
+ NULL, NULL,
+ cpu_to_be64(SOFT_OFF));
+ }
+
+ break;
+
+ case PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED:
+ prlog(PR_NOTICE, "Soft reboot requested\n");
+ cc_resp(req, PLDM_PLATFORM,
+ PLDM_SET_STATE_EFFECTER_STATES,
+ PLDM_SUCCESS);
+
+ if (opal_booting() && platform.cec_reboot) {
+ prlog(PR_NOTICE, "Host not up, rebooting now\n");
+ platform.cec_reboot();
+ } else {
+ opal_queue_msg(OPAL_MSG_SHUTDOWN,
+ NULL, NULL,
+ cpu_to_be64(SOFT_REBOOT));
+ }
+
+ break;
+
+ case PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET:
+ case PLDM_STATE_SET_BOOT_RESTART_CAUSE_HARD_RESET:
+ prlog(PR_NOTICE, "OCC reset requested\n");
+ cc_resp(req, PLDM_PLATFORM,
+ PLDM_SET_STATE_EFFECTER_STATES,
+ PLDM_SUCCESS);
+
+ /* invoke the appropriate callback handler */
+ prd_occ_reset(DEFAULT_CHIP_ID); /* FIXME, others chip ? */
+ break;
+
+ default:
+ prlog(PR_ERR, "Got invalid effecter state 0x%x in "
+ "SetStateEffecterStates request\n",
+ field->effecter_state);
+ cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command,
+ PLDM_PLATFORM_INVALID_STATE_VALUE);
+ return OPAL_PARAMETER;
+ }
+
+ /* next */
+ field++;
+ }
+
+ return OPAL_SUCCESS;
+}
+
+static struct pldm_cmd pldm_platform_set_state_effecter_states = {
+ .name = "PLDM_SET_STATE_EFFECTER_STATES",
+ .pldm_cmd_id = PLDM_SET_STATE_EFFECTER_STATES,
+ .handler = platform_set_state_effecter_states_handler,
+};
+
int pldm_responder_handle_request(struct pldm_rx_data *rx)
{
const struct pldm_type *type;
@@ -704,6 +832,8 @@ int pldm_responder_init(void)
add_type(&pldm_platform_type);
add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver);
add_cmd(&pldm_platform_type, &pldm_platform_event_message);
+ add_cmd(&pldm_platform_type, &pldm_platform_get_state_sensor_readings);
+ add_cmd(&pldm_platform_type, &pldm_platform_set_state_effecter_states);
return OPAL_SUCCESS;
}
--
2.37.3
More information about the Skiboot
mailing list