aboutsummaryrefslogtreecommitdiff
path: root/core/pldm/pldm-base-requests.c
blob: d8984277f50e1baa3bd588d93e343c9010c2c045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
// Copyright 2022 IBM Corp.

#define pr_fmt(fmt) "PLDM: " fmt

#include <cpu.h>
#include <opal.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <libpldm/base.h>
#include "pldm.h"

static uint8_t bmc_tid = -1;

uint8_t pldm_base_get_bmc_tid(void)
{
	return bmc_tid;
}

/*
 * Create a PLDM request message for GetTID.
 */
int pldm_base_get_tid_req(void)
{
	size_t data_size = PLDM_MSG_SIZE(0); /* the command doesn't have a message payload */
	size_t response_len, payload_len;
	struct pldm_tx_data *tx = NULL;
	void *response_msg;
	int rc;

	struct pldm_get_tid_resp response;

	/* Encode the get tid request */
	tx = zalloc(sizeof(struct pldm_tx_data) + data_size);
	if (!tx)
		return OPAL_NO_MEM;
	tx->data_size = data_size;

	rc = encode_get_tid_req(DEFAULT_INSTANCE_ID,
				(struct pldm_msg *)tx->data);
	if (rc != PLDM_SUCCESS) {
		prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc);
		free(tx);
		return OPAL_PARAMETER;
	}

	/* Send and get the response message bytes */
	rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len);
	if (rc) {
		prlog(PR_ERR, "Communication Error, req: GetTID, rc: %d\n", rc);
		free(tx);
		return rc;
	}

	/* Decode the message */
	payload_len = response_len - sizeof(struct pldm_msg_hdr);

	rc = decode_get_tid_resp(response_msg, payload_len,
				 &response.completion_code,
				 &response.tid);
	if ((rc != PLDM_SUCCESS) || (response.completion_code != PLDM_SUCCESS)) {
		prlog(PR_ERR, "Decode GetTID Error, rc: %d, cc: %d\n",
			      rc, response.completion_code);
		free(tx);
		free(response_msg);
		return OPAL_PARAMETER;
	}

	prlog(PR_INFO, "BMC's TID is %d\n", response.tid);
	bmc_tid = response.tid;
	free(tx);
	free(response_msg);

	return OPAL_SUCCESS;
}