[Skiboot] [PATCH V3 07/21] core/pldm: Encode GetPLDMCommands response
Christophe Lombard
clombard at linux.vnet.ibm.com
Sat Mar 19 01:36:05 AEDT 2022
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 | 70 ++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index 01a4b1ef..88cf47ba 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -163,6 +163,75 @@ static struct pldm_cmd base_get_types = {
.handler = 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 get_commands_handler(const struct pldm_rx_data *req)
+{
+ char resp_buf[PKT_SIZE(struct pldm_get_commands_resp)];
+ bitmap_elem_t cmd_map[BITMAP_ELEMS(256)];
+ 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) {
+ pldm_cc_resp(req, PLDM_ERROR);
+ return OPAL_INTERNAL_ERROR;
+ }
+
+ type = find_type(type_id);
+ if (!type) {
+ pldm_cc_resp(req, INVALID_PLDM_TYPE_IN_REQUEST_DATA);
+ return OPAL_PARAMETER;
+ }
+
+ if (memcmp(&type->version, &version, sizeof(version))) {
+ pldm_cc_resp(req, 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(resp_buf, 0, sizeof(resp_buf));
+ encode_get_commands_resp(req->hdrinf.instance,
+ PLDM_SUCCESS,
+ (bitfield8_t *)cmd_map,
+ (void *) resp_buf);
+ pldm_send(req->source_eid, resp_buf, sizeof(resp_buf));
+
+ return 0;
+}
+static struct pldm_cmd base_get_commands = {
+ .name = "GetPLDMCommands",
+ .pldm_cmd_id = PLDM_GET_PLDM_COMMANDS,
+ .handler = get_commands_handler,
+};
+
int pldm_rx_handle_request(struct pldm_rx_data *rx)
{
const struct pldm_type *t;
@@ -190,6 +259,7 @@ int pldm_mctp_responder_init(void)
pldm_add_cmd(&pldm_base_type, &base_get_tid);
pldm_add_cmd(&pldm_base_type, &base_get_types);
+ pldm_add_cmd(&pldm_base_type, &base_get_commands);
return OPAL_SUCCESS;
}
--
2.35.1
More information about the Skiboot
mailing list