@@ -199,6 +199,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
@@ -286,6 +287,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);
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command, PLDM_ERROR);
+ return OPAL_INTERNAL_ERROR;
+ }
+
+ /* reject multipart requests */
+ if (opflag != PLDM_GET_FIRSTPART) {
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command,
+ INVALID_TRANSFER_OPERATION_FLAG);
+ return OPAL_PARAMETER;
+ }
+
+ type = find_type(type_id);
+ if (!type) {
+ pldm_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);
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command, PLDM_ERROR);
+ return OPAL_PARAMETER;
+ }
+
+ /* send PLDM message over MCTP */
+ rc = pldm_send(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_rx_handle_request(struct pldm_rx_data *rx)
{
const struct pldm_type *t;
@@ -324,6 +407,7 @@ int pldm_mctp_responder_init(void)
pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid);
pldm_add_cmd(&pldm_base_type, &pldm_base_get_types);
pldm_add_cmd(&pldm_base_type, &pldm_base_get_commands);
+ pldm_add_cmd(&pldm_base_type, &pldm_base_get_version);
return OPAL_SUCCESS;
}