[Skiboot] [PATCH V6 07/21] core/pldm: Encode GetPLDMCommands response
Frederic Barrat
fbarrat at linux.ibm.com
Thu Apr 13 00:48:58 AEST 2023
On 13/09/2022 12:26, Christophe Lombard wrote:
> The GetPLDMCommands command can be used to discover the PLDM command
> capabilities supported by a PLDM terminus for a specific PLDM Type and
> version as a responder.
>
> 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 | 90 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 90 insertions(+)
>
> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
> index 6058af51..88545685 100644
> --- a/core/pldm/pldm-responder.c
> +++ b/core/pldm/pldm-responder.c
> @@ -205,6 +205,95 @@ static struct pldm_cmd pldm_base_get_types = {
> .handler = base_get_types_handler,
> };
>
> +/*
> + * Extended error codes defined for the Base command set.
> + */
> +#define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83
> +#define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84
> +
> +/*
> + * GetPLDMCommands (0x05)
> + * The GetPLDMCommands command can be used to discover the PLDM command
> + * capabilities supported by aPLDM terminus for a specific PLDM Type and
> + * version as a responder.
> + */
> +static int base_get_commands_handler(const struct pldm_rx_data *req)
> +{
> + char response_msg[PKT_SIZE(struct pldm_get_commands_resp)];
> + bitmap_elem_t cmd_map[BITMAP_ELEMS(256)];
Like in the previous patch, libpldm gives a macro:
#define PLDM_MAX_CMDS_PER_TYPE 256
Fred
> + const struct pldm_type *type;
> + const struct pldm_cmd *iter;
> + size_t payload_len;
> + ver32_t version;
> + uint8_t type_id;
> + int rc;
> +
> + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr);
> + rc = decode_get_commands_req(req->msg, payload_len,
> + &type_id, &version);
> + if (rc) {
> + prlog(PR_ERR, "Failed to decode GetPLDMCommands request, rc = %d", rc);
> + cc_resp(req, req->hdrinf.pldm_type,
> + req->hdrinf.command, PLDM_ERROR);
> + return OPAL_INTERNAL_ERROR;
> + }
> +
> + 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;
> + }
> +
> + if (memcmp(&type->version, &version, sizeof(version))) {
> + cc_resp(req, req->hdrinf.pldm_type,
> + req->hdrinf.command,
> + INVALID_PLDM_VERSION_IN_REQUEST_DATA);
> + return OPAL_PARAMETER;
> + }
> +
> + /*
> + * build the supported type list from the registered type
> + * handlers
> + */
> + memset(cmd_map, 0, sizeof(cmd_map));
> + list_for_each(&type->commands, iter, link)
> + bitmap_set_bit(cmd_map, iter->pldm_cmd_id);
> + /* fix the endian */
> + for (int i = 0; i < BITMAP_ELEMS(256); i++)
> + cmd_map[i] = cpu_to_le64(cmd_map[i]);
> +
> + memset(response_msg, 0, sizeof(response_msg));
> +
> + /* create a PLDM response message for GetPLDMCommands */
> + rc = encode_get_commands_resp(req->hdrinf.instance,
> + PLDM_SUCCESS,
> + (bitfield8_t *)cmd_map,
> + (struct pldm_msg *)response_msg);
> + if (rc != PLDM_SUCCESS) {
> + prlog(PR_ERR, "Encode GetPLDMCommands 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 GetPLDMCommands response, rc = %d\n", rc);
> + return OPAL_HARDWARE;
> + }
> +
> + return OPAL_SUCCESS;
> +}
> +
> +static struct pldm_cmd pldm_base_get_commands = {
> + .name = "PLDM_GET_PLDM_COMMANDS",
> + .pldm_cmd_id = PLDM_GET_PLDM_COMMANDS,
> + .handler = base_get_commands_handler,
> +};
> +
> int pldm_responder_handle_request(struct pldm_rx_data *rx)
> {
> const struct pldm_type *type;
> @@ -242,6 +331,7 @@ int pldm_responder_init(void)
> add_type(&pldm_base_type);
> 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);
>
> return OPAL_SUCCESS;
> }
More information about the Skiboot
mailing list