diff mbox series

[V6,11/21] core/pldm: Encode state effecter request

Message ID 20220913102705.65506-12-clombard@linux.vnet.ibm.com
State Superseded
Headers show
Series Implement MCTP and PLDM features | expand

Commit Message

Christophe Lombard Sept. 13, 2022, 10:26 a.m. UTC
PLDM effecters provide a general mechanism for controlling or configuring a
state or numeric setting of an entity.
The entity state and numeric setting values are written into an effecter.

PLDM commands are specified for writing the state or numeric setting to an
effecter. Effecters are identified by and accessed using an EffecterID that
is unique for each effecter within a given terminus.

PLDM State Effecters provide a regular command structure for setting state
information in order to change the state of an entity.

The SetStateEffecterStates command is used to set the state of one or more
effecters within a PLDM State Effecter.

Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
---
 core/pldm/pldm-platform-requests.c | 76 ++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

Comments

Abhishek Singh Tomar Sept. 29, 2022, 4:55 p.m. UTC | #1
On Tue, Sep 13, 2022 at 12:26:55PM +0200, Christophe Lombard wrote:
> PLDM effecters provide a general mechanism for controlling or configuring a
> state or numeric setting of an entity.
> The entity state and numeric setting values are written into an effecter.
> 
> PLDM commands are specified for writing the state or numeric setting to an
> effecter. Effecters are identified by and accessed using an EffecterID that
> is unique for each effecter within a given terminus.
> 
> PLDM State Effecters provide a regular command structure for setting state
> information in order to change the state of an entity.
> 
> The SetStateEffecterStates command is used to set the state of one or more
> effecters within a PLDM State Effecter.
> 
Reviewed-by: Abhishek Singh Tomar <abhishek@linux.ibm.com>
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> ---
>  core/pldm/pldm-platform-requests.c | 76 ++++++++++++++++++++++++++++++
>  1 file changed, 76 insertions(+)
> 
> diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c
> index 965820c8..93b98438 100644
> --- a/core/pldm/pldm-platform-requests.c
> +++ b/core/pldm/pldm-platform-requests.c
> @@ -39,6 +39,82 @@ static void pdr_init_complete(bool success)
>  	pdr_ready = true;
>  }
> 
> +struct set_effecter_state_response {
> +	uint8_t completion_code;
> +};
> +
> +/*
> + * Create and send a PLDM request message for SetStateEffecterStates.
> + */
> +static int set_state_effecter_states_req(uint16_t effecter_id,
> +					 set_effecter_state_field *field,
> +					 bool no_timeout)
> +{
> +	char request_msg[PKT_SIZE(struct pldm_set_state_effecter_states_req)];
> +	size_t response_len, payload_len;
> +	void *response_msg;
> +	int rc;
> +
> +	struct pldm_set_state_effecter_states_req states_req = {
> +		.effecter_id = effecter_id,
> +		.comp_effecter_count = 1
> +	};
> +
> +	struct set_effecter_state_response response;
> +
> +	/* Encode the state effecter states request */
> +	rc = encode_set_state_effecter_states_req(
> +			DEFAULT_INSTANCE_ID,
> +			states_req.effecter_id,
> +			states_req.comp_effecter_count,
> +			field,
> +			(struct pldm_msg *)request_msg);
> +	if (rc != PLDM_SUCCESS) {
> +		prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n",
> +			      rc);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	/* Send and get the response message bytes.
> +	 * It may happen that for some commands, the responder does not
> +	 * have time to respond.
> +	 */
> +	if (no_timeout) {
> +		rc = pldm_mctp_message_tx(BMC_EID, request_msg, sizeof(request_msg));
> +		if (rc)
> +			prlog(PR_ERR, "Failed to send SetStateEffecter request, rc = %d\n", rc);
> +
> +		return rc;
> +	}
> +
> +	/* Send and get the response message bytes */
> +	rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg),
> +					   &response_msg, &response_len);
> +	if (rc) {
> +		prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc);
> +			free(response_msg);
> +		return rc;
> +	}
> +
> +	/* Decode the message */
> +	payload_len = response_len - sizeof(struct pldm_msg_hdr);
> +
> +	rc = decode_set_state_effecter_states_resp(
> +				response_msg,
> +				payload_len,
> +				&response.completion_code);
> +	if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) {
> +		prlog(PR_ERR, "Decode SetStateEffecter Error, rc: %d, cc: %d\n",
> +			      rc, response.completion_code);
> +		free(response_msg);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	free(response_msg);
> +
> +	return OPAL_SUCCESS;
> +}
> +
>  struct get_pdr_response {
>  	uint8_t completion_code;
>  	uint32_t next_record_hndl;
> -- 
> 2.37.3
> 
> _______________________________________________
> Skiboot mailing list
> Skiboot@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
Frederic Barrat April 12, 2023, 3:25 p.m. UTC | #2
On 13/09/2022 12:26, Christophe Lombard wrote:
> PLDM effecters provide a general mechanism for controlling or configuring a
> state or numeric setting of an entity.
> The entity state and numeric setting values are written into an effecter.
> 
> PLDM commands are specified for writing the state or numeric setting to an
> effecter. Effecters are identified by and accessed using an EffecterID that
> is unique for each effecter within a given terminus.
> 
> PLDM State Effecters provide a regular command structure for setting state
> information in order to change the state of an entity.
> 
> The SetStateEffecterStates command is used to set the state of one or more
> effecters within a PLDM State Effecter.
> 
> Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> ---
>   core/pldm/pldm-platform-requests.c | 76 ++++++++++++++++++++++++++++++
>   1 file changed, 76 insertions(+)
> 
> diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c
> index 965820c8..93b98438 100644
> --- a/core/pldm/pldm-platform-requests.c
> +++ b/core/pldm/pldm-platform-requests.c
> @@ -39,6 +39,82 @@ static void pdr_init_complete(bool success)
>   	pdr_ready = true;
>   }
>   
> +struct set_effecter_state_response {
> +	uint8_t completion_code;
> +};
> +
> +/*
> + * Create and send a PLDM request message for SetStateEffecterStates.
> + */
> +static int set_state_effecter_states_req(uint16_t effecter_id,
> +					 set_effecter_state_field *field,
> +					 bool no_timeout)
> +{
> +	char request_msg[PKT_SIZE(struct pldm_set_state_effecter_states_req)];
> +	size_t response_len, payload_len;
> +	void *response_msg;
> +	int rc;
> +
> +	struct pldm_set_state_effecter_states_req states_req = {
> +		.effecter_id = effecter_id,
> +		.comp_effecter_count = 1
> +	};
> +
> +	struct set_effecter_state_response response;
> +
> +	/* Encode the state effecter states request */
> +	rc = encode_set_state_effecter_states_req(
> +			DEFAULT_INSTANCE_ID,
> +			states_req.effecter_id,
> +			states_req.comp_effecter_count,
> +			field,
> +			(struct pldm_msg *)request_msg);
> +	if (rc != PLDM_SUCCESS) {
> +		prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n",
> +			      rc);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	/* Send and get the response message bytes.
> +	 * It may happen that for some commands, the responder does not
> +	 * have time to respond.
> +	 */
> +	if (no_timeout) {
> +		rc = pldm_mctp_message_tx(BMC_EID, request_msg, sizeof(request_msg));
> +		if (rc)
> +			prlog(PR_ERR, "Failed to send SetStateEffecter request, rc = %d\n", rc);
> +
> +		return rc;
> +	}
> +
> +	/* Send and get the response message bytes */
> +	rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg),
> +					   &response_msg, &response_len);
> +	if (rc) {
> +		prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc);
> +			free(response_msg);

No need to call 'free(response_msg)' in that path (unlike below)

   Fred
Christophe Lombard April 13, 2023, 12:43 p.m. UTC | #3
Le 12/04/2023 à 17:25, Frederic Barrat a écrit :
>
>
> On 13/09/2022 12:26, Christophe Lombard wrote:
>> PLDM effecters provide a general mechanism for controlling or 
>> configuring a
>> state or numeric setting of an entity.
>> The entity state and numeric setting values are written into an 
>> effecter.
>>
>> PLDM commands are specified for writing the state or numeric setting 
>> to an
>> effecter. Effecters are identified by and accessed using an 
>> EffecterID that
>> is unique for each effecter within a given terminus.
>>
>> PLDM State Effecters provide a regular command structure for setting 
>> state
>> information in order to change the state of an entity.
>>
>> The SetStateEffecterStates command is used to set the state of one or 
>> more
>> effecters within a PLDM State Effecter.
>>
>> Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
>> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
>> ---
>>   core/pldm/pldm-platform-requests.c | 76 ++++++++++++++++++++++++++++++
>>   1 file changed, 76 insertions(+)
>>
>> diff --git a/core/pldm/pldm-platform-requests.c 
>> b/core/pldm/pldm-platform-requests.c
>> index 965820c8..93b98438 100644
>> --- a/core/pldm/pldm-platform-requests.c
>> +++ b/core/pldm/pldm-platform-requests.c
>> @@ -39,6 +39,82 @@ static void pdr_init_complete(bool success)
>>       pdr_ready = true;
>>   }
>>   +struct set_effecter_state_response {
>> +    uint8_t completion_code;
>> +};
>> +
>> +/*
>> + * Create and send a PLDM request message for SetStateEffecterStates.
>> + */
>> +static int set_state_effecter_states_req(uint16_t effecter_id,
>> +                     set_effecter_state_field *field,
>> +                     bool no_timeout)
>> +{
>> +    char request_msg[PKT_SIZE(struct 
>> pldm_set_state_effecter_states_req)];
>> +    size_t response_len, payload_len;
>> +    void *response_msg;
>> +    int rc;
>> +
>> +    struct pldm_set_state_effecter_states_req states_req = {
>> +        .effecter_id = effecter_id,
>> +        .comp_effecter_count = 1
>> +    };
>> +
>> +    struct set_effecter_state_response response;
>> +
>> +    /* Encode the state effecter states request */
>> +    rc = encode_set_state_effecter_states_req(
>> +            DEFAULT_INSTANCE_ID,
>> +            states_req.effecter_id,
>> +            states_req.comp_effecter_count,
>> +            field,
>> +            (struct pldm_msg *)request_msg);
>> +    if (rc != PLDM_SUCCESS) {
>> +        prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n",
>> +                  rc);
>> +        return OPAL_PARAMETER;
>> +    }
>> +
>> +    /* Send and get the response message bytes.
>> +     * It may happen that for some commands, the responder does not
>> +     * have time to respond.
>> +     */
>> +    if (no_timeout) {
>> +        rc = pldm_mctp_message_tx(BMC_EID, request_msg, 
>> sizeof(request_msg));
>> +        if (rc)
>> +            prlog(PR_ERR, "Failed to send SetStateEffecter request, 
>> rc = %d\n", rc);
>> +
>> +        return rc;
>> +    }
>> +
>> +    /* Send and get the response message bytes */
>> +    rc = pldm_requester_queue_and_wait(request_msg, 
>> sizeof(request_msg),
>> +                       &response_msg, &response_len);
>> +    if (rc) {
>> +        prlog(PR_ERR, "Communication Error, req: SetStateEffecter, 
>> rc: %d\n", rc);
>> +            free(response_msg);
>
> No need to call 'free(response_msg)' in that path (unlike below)
>
>   Fred

That's correct. Thanks
diff mbox series

Patch

diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c
index 965820c8..93b98438 100644
--- a/core/pldm/pldm-platform-requests.c
+++ b/core/pldm/pldm-platform-requests.c
@@ -39,6 +39,82 @@  static void pdr_init_complete(bool success)
 	pdr_ready = true;
 }
 
+struct set_effecter_state_response {
+	uint8_t completion_code;
+};
+
+/*
+ * Create and send a PLDM request message for SetStateEffecterStates.
+ */
+static int set_state_effecter_states_req(uint16_t effecter_id,
+					 set_effecter_state_field *field,
+					 bool no_timeout)
+{
+	char request_msg[PKT_SIZE(struct pldm_set_state_effecter_states_req)];
+	size_t response_len, payload_len;
+	void *response_msg;
+	int rc;
+
+	struct pldm_set_state_effecter_states_req states_req = {
+		.effecter_id = effecter_id,
+		.comp_effecter_count = 1
+	};
+
+	struct set_effecter_state_response response;
+
+	/* Encode the state effecter states request */
+	rc = encode_set_state_effecter_states_req(
+			DEFAULT_INSTANCE_ID,
+			states_req.effecter_id,
+			states_req.comp_effecter_count,
+			field,
+			(struct pldm_msg *)request_msg);
+	if (rc != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n",
+			      rc);
+		return OPAL_PARAMETER;
+	}
+
+	/* Send and get the response message bytes.
+	 * It may happen that for some commands, the responder does not
+	 * have time to respond.
+	 */
+	if (no_timeout) {
+		rc = pldm_mctp_message_tx(BMC_EID, request_msg, sizeof(request_msg));
+		if (rc)
+			prlog(PR_ERR, "Failed to send SetStateEffecter request, rc = %d\n", rc);
+
+		return rc;
+	}
+
+	/* Send and get the response message bytes */
+	rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg),
+					   &response_msg, &response_len);
+	if (rc) {
+		prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc);
+			free(response_msg);
+		return rc;
+	}
+
+	/* Decode the message */
+	payload_len = response_len - sizeof(struct pldm_msg_hdr);
+
+	rc = decode_set_state_effecter_states_resp(
+				response_msg,
+				payload_len,
+				&response.completion_code);
+	if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Decode SetStateEffecter Error, rc: %d, cc: %d\n",
+			      rc, response.completion_code);
+		free(response_msg);
+		return OPAL_PARAMETER;
+	}
+
+	free(response_msg);
+
+	return OPAL_SUCCESS;
+}
+
 struct get_pdr_response {
 	uint8_t completion_code;
 	uint32_t next_record_hndl;