[Skiboot] [PATCH V6 08/21] core/pldm: Encode GetPLDMVersion response

Abhishek SIngh Tomar abhishek at linux.ibm.com
Fri Sep 30 00:30:11 AEST 2022


On Tue, Sep 13, 2022 at 12:26:52PM +0200, Christophe Lombard wrote:
> The GetPLDMVersion command can be used to retrieve the PLDM base
> specification versions that the PLDM terminus supports, as well as the
> PLDM Type specification versions supported for each PLDM Type.
> 
> The reported version for Type 0 (PLDMbase) shall be encoded as 0xF1F1F000.
> 
Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
> Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
> ---
>  core/pldm/pldm-responder.c | 84 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 84 insertions(+)
> 
> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
> index 88545685..230b9c05 100644
> --- a/core/pldm/pldm-responder.c
> +++ b/core/pldm/pldm-responder.c
> @@ -208,6 +208,7 @@ static struct pldm_cmd pldm_base_get_types = {
>  /*
>   * Extended error codes defined for the Base command set.
>   */
> +#define INVALID_TRANSFER_OPERATION_FLAG        0x80
>  #define INVALID_PLDM_TYPE_IN_REQUEST_DATA      0x83
>  #define INVALID_PLDM_VERSION_IN_REQUEST_DATA   0x84
> 
> @@ -294,6 +295,88 @@ static struct pldm_cmd pldm_base_get_commands = {
>  	.handler = base_get_commands_handler,
>  };
> 
> +/*
> + * GetPLDMVersion (0x03)
> + * The GetPLDMVersion command can be used to retrieve the PLDM base
> + * specification versions that the PLDM terminus supports, as well as
> + * the PLDM Type specification versions supported for each PLDM Type.
> + */
> +static int base_get_version_handler(const struct pldm_rx_data *req)
> +{
> +	uint32_t tmp[2];
> +	char response_msg[PKT_SIZE(struct pldm_get_version_resp) + sizeof(tmp)];
> +	const struct pldm_type *type;
> +	uint8_t type_id, opflag;
> +	size_t payload_len;
> +	uint32_t xfer_handle;
> +	int rc;
> +
> +	payload_len = req->msg_len - sizeof(struct pldm_msg_hdr);
> +	rc = decode_get_version_req(req->msg, payload_len,
> +				    &xfer_handle,
> +				    &opflag,
> +				    &type_id);
> +	if (rc) {
> +		prlog(PR_ERR, "Failed to decode GetPLDMVersion request, rc = %d", rc);
> +		cc_resp(req, req->hdrinf.pldm_type,
> +			req->hdrinf.command, PLDM_ERROR);
> +		return OPAL_INTERNAL_ERROR;
> +	}
> +
> +	/* reject multipart requests */
> +	if (opflag != PLDM_GET_FIRSTPART) {
> +		cc_resp(req, req->hdrinf.pldm_type,
> +			req->hdrinf.command,
> +			INVALID_TRANSFER_OPERATION_FLAG);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	type = find_type(type_id);
> +	if (!type) {
> +		cc_resp(req, req->hdrinf.pldm_type,
> +			req->hdrinf.command,
> +			INVALID_PLDM_TYPE_IN_REQUEST_DATA);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	/* pack a scratch buffer with our version(s) and CRC32 the lot */
> +	memcpy(&tmp[0], &type->version, 4);
> +
> +	tmp[1] = cpu_to_le32(pldm_crc32(&type->version, 4));
> +
> +	memset(response_msg, 0, sizeof(response_msg));
> +
> +	/* create a PLDM response for GetPLDMVersion */
> +	rc = encode_get_version_resp(req->hdrinf.instance,
> +				     PLDM_SUCCESS,
> +				     0x0, /* no handle */
> +				     PLDM_START_AND_END,
> +				     (ver32_t *) tmp,
> +				     sizeof(tmp),
> +				     (struct pldm_msg *)response_msg);
> +	if (rc != PLDM_SUCCESS) {
> +		prlog(PR_ERR, "Encode GetPLDMVersion Error, rc: %d\n", rc);
> +		cc_resp(req, req->hdrinf.pldm_type,
> +			req->hdrinf.command, PLDM_ERROR);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	/* send PLDM message over MCTP */
> +	rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg));
> +	if (rc) {
> +		prlog(PR_ERR, "Failed to send GetPLDMVersion response, rc = %d\n", rc);
> +		return OPAL_HARDWARE;
> +	}
> +
> +	return OPAL_SUCCESS;
> +}
> +
> +static struct pldm_cmd pldm_base_get_version = {
> +	.name = "PLDM_GET_PLDM_VERSION",
> +	.pldm_cmd_id = PLDM_GET_PLDM_VERSION,
> +	.handler = base_get_version_handler,
> +};
> +
>  int pldm_responder_handle_request(struct pldm_rx_data *rx)
>  {
>  	const struct pldm_type *type;
> @@ -332,6 +415,7 @@ int pldm_responder_init(void)
>  	add_cmd(&pldm_base_type, &pldm_base_get_tid);
>  	add_cmd(&pldm_base_type, &pldm_base_get_types);
>  	add_cmd(&pldm_base_type, &pldm_base_get_commands);
> +	add_cmd(&pldm_base_type, &pldm_base_get_version);
> 
>  	return OPAL_SUCCESS;
>  }
> -- 
> 2.37.3
> 
> _______________________________________________
> Skiboot mailing list
> Skiboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot


More information about the Skiboot mailing list