blob: bdecc20b7655ea944a972f23b958d1e612d1db11 [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#ifndef BASE_H
2#define BASE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <asm/byteorder.h>
9#include <stddef.h>
10#include <stdint.h>
11
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060012#include "pldm_types.h"
13
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060014/** @brief PLDM Types
15 */
16enum pldm_supported_types {
17 PLDM_BASE = 0x00,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050018 PLDM_PLATFORM = 0x02,
Sampa Misra032bd502019-03-06 05:03:22 -060019 PLDM_BIOS = 0x03,
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053020 PLDM_FRU = 0x04,
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050021 PLDM_OEM = 0x3F,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060022};
23
24/** @brief PLDM Commands
25 */
26enum pldm_supported_commands {
John Wang5c4f80d2019-07-29 11:12:18 +080027 PLDM_GET_TID = 0x2,
Sampa Misra432e1872019-02-13 03:49:43 -060028 PLDM_GET_PLDM_VERSION = 0x3,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060029 PLDM_GET_PLDM_TYPES = 0x4,
30 PLDM_GET_PLDM_COMMANDS = 0x5
31};
32
33/** @brief PLDM base codes
34 */
35enum pldm_completion_codes {
36 PLDM_SUCCESS = 0x00,
37 PLDM_ERROR = 0x01,
38 PLDM_ERROR_INVALID_DATA = 0x02,
39 PLDM_ERROR_INVALID_LENGTH = 0x03,
40 PLDM_ERROR_NOT_READY = 0x04,
41 PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
42 PLDM_ERROR_INVALID_PLDM_TYPE = 0x20
43};
44
Sampa Misra432e1872019-02-13 03:49:43 -060045enum transfer_op_flag {
46 PLDM_GET_NEXTPART = 0,
47 PLDM_GET_FIRSTPART = 1,
48};
49
50enum transfer_resp_flag {
51 PLDM_START = 0x01,
52 PLDM_MIDDLE = 0x02,
53 PLDM_END = 0x04,
54 PLDM_START_AND_END = 0x05,
55};
56
Tom Joseph41251042019-02-07 16:17:07 +053057/** @enum MessageType
58 *
59 * The different message types supported by the PLDM specification.
60 */
61typedef enum {
62 PLDM_RESPONSE, //!< PLDM response
63 PLDM_REQUEST, //!< PLDM request
64 PLDM_RESERVED, //!< Reserved
65 PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
66} MessageType;
67
68#define PLDM_INSTANCE_MAX 31
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060069#define PLDM_MAX_TYPES 64
70#define PLDM_MAX_CMDS_PER_TYPE 256
71
72/* Message payload lengths */
73#define PLDM_GET_COMMANDS_REQ_BYTES 5
Sampa Misra432e1872019-02-13 03:49:43 -060074#define PLDM_GET_VERSION_REQ_BYTES 6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060075
76/* Response lengths are inclusive of completion code */
77#define PLDM_GET_TYPES_RESP_BYTES 9
John Wang5c4f80d2019-07-29 11:12:18 +080078#define PLDM_GET_TID_RESP_BYTES 2
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060079#define PLDM_GET_COMMANDS_RESP_BYTES 33
Sampa Misra432e1872019-02-13 03:49:43 -060080/* Response data has only one version and does not contain the checksum */
81#define PLDM_GET_VERSION_RESP_BYTES 10
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060082
83/** @struct pldm_msg_hdr
84 *
85 * Structure representing PLDM message header fields
86 */
87struct pldm_msg_hdr {
88#if defined(__LITTLE_ENDIAN_BITFIELD)
89 uint8_t instance_id : 5; //!< Instance ID
90 uint8_t reserved : 1; //!< Reserved
91 uint8_t datagram : 1; //!< Datagram bit
92 uint8_t request : 1; //!< Request bit
93#elif defined(__BIG_ENDIAN_BITFIELD)
94 uint8_t request : 1; //!< Request bit
95 uint8_t datagram : 1; //!< Datagram bit
96 uint8_t reserved : 1; //!< Reserved
97 uint8_t instance_id : 5; //!< Instance ID
98#endif
99
100#if defined(__LITTLE_ENDIAN_BITFIELD)
101 uint8_t type : 6; //!< PLDM type
102 uint8_t header_ver : 2; //!< Header version
103#elif defined(__BIG_ENDIAN_BITFIELD)
104 uint8_t header_ver : 2; //!< Header version
105 uint8_t type : 6; //!< PLDM type
106#endif
107 uint8_t command; //!< PLDM command code
108} __attribute__((packed));
109
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600110/** @struct pldm_msg
111 *
112 * Structure representing PLDM message
113 */
114struct pldm_msg {
vkaverapa6575b82019-04-03 05:33:52 -0500115 struct pldm_msg_hdr hdr; //!< PLDM message header
116 uint8_t payload[1]; //!< &payload[0] is the beginning of the payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600117} __attribute__((packed));
118
Tom Joseph41251042019-02-07 16:17:07 +0530119/** @struct pldm_header_info
120 *
121 * The information needed to prepare PLDM header and this is passed to the
122 * pack_pldm_header and unpack_pldm_header API.
123 */
124struct pldm_header_info {
125 MessageType msg_type; //!< PLDM message type
126 uint8_t instance; //!< PLDM instance id
127 uint8_t pldm_type; //!< PLDM type
128 uint8_t command; //!< PLDM command code
129 uint8_t completion_code; //!< PLDM completion code, applies for response
130};
131
Priyanga4b790ce2019-06-10 01:30:09 -0500132/** @struct pldm_get_types_resp
133 *
134 * Structure representing PLDM get types response.
135 */
136struct pldm_get_types_resp {
137 uint8_t completion_code; //!< completion code
138 bitfield8_t types[8]; //!< each bit represents whether a given PLDM Type
139 //!< is supported
140} __attribute__((packed));
141
142/** @struct pldm_get_commands_req
143 *
144 * Structure representing PLDM get commands request.
145 */
146struct pldm_get_commands_req {
147 uint8_t type; //!< PLDM Type for which command support information is
148 //!< being requested
149 ver32_t version; //!< version for the specified PLDM Type
150} __attribute__((packed));
151
152/** @struct pldm_get_commands_resp
153 *
154 * Structure representing PLDM get commands response.
155 */
156struct pldm_get_commands_resp {
157 uint8_t completion_code; //!< completion code
158 bitfield8_t commands[32]; //!< each bit represents whether a given PLDM
159 //!< command is supported
160} __attribute__((packed));
161
162/** @struct pldm_get_version_req
163 *
164 * Structure representing PLDM get version request.
165 */
166struct pldm_get_version_req {
167 uint32_t
168 transfer_handle; //!< handle to identify PLDM version data transfer
169 uint8_t transfer_opflag; //!< PLDM GetVersion operation flag
170 uint8_t type; //!< PLDM Type for which version information is being
171 //!< requested
172} __attribute__((packed));
173
174/** @struct pldm_get_version_resp
175 *
176 * Structure representing PLDM get version response.
177 */
178
179struct pldm_get_version_resp {
180 uint8_t completion_code; //!< completion code
181 uint32_t next_transfer_handle; //!< next portion of PLDM version data
182 //!< transfer
183 uint8_t transfer_flag; //!< PLDM GetVersion transfer flag
184 uint8_t version_data[1]; //!< PLDM GetVersion version field
185} __attribute__((packed));
186
John Wang5c4f80d2019-07-29 11:12:18 +0800187/** @struct pldm_get_tid_resp
188 *
189 * Structure representing PLDM get tid response.
190 */
191
192struct pldm_get_tid_resp {
193 uint8_t completion_code; //!< completion code
194 uint8_t tid; //!< PLDM GetTID TID field
195} __attribute__((packed));
196
Tom Joseph41251042019-02-07 16:17:07 +0530197/**
198 * @brief Populate the PLDM message with the PLDM header.The caller of this API
199 * allocates buffer for the PLDM header when forming the PLDM message.
200 * The buffer is passed to this API to pack the PLDM header.
201 *
202 * @param[in] hdr - Pointer to the PLDM header information
203 * @param[out] msg - Pointer to PLDM message header
204 *
205 * @return 0 on success, otherwise PLDM error codes.
206 */
207int pack_pldm_header(const struct pldm_header_info *hdr,
208 struct pldm_msg_hdr *msg);
209
210/**
211 * @brief Unpack the PLDM header from the PLDM message.
212 *
213 * @param[in] msg - Pointer to the PLDM message header
214 * @param[out] hdr - Pointer to the PLDM header information
215 *
216 * @return 0 on success, otherwise PLDM error codes.
217 */
218int unpack_pldm_header(const struct pldm_msg_hdr *msg,
219 struct pldm_header_info *hdr);
220
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600221/* Requester */
222
223/* GetPLDMTypes */
224
225/** @brief Create a PLDM request message for GetPLDMTypes
226 *
227 * @param[in] instance_id - Message's instance id
228 * @param[in,out] msg - Message will be written to this
229 * @return pldm_completion_codes
230 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500231 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600232 */
233int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg);
234
235/** @brief Decode a GetPLDMTypes response message
236 *
George Liu684a7162019-12-06 15:10:52 +0800237 * Note:
238 * * If the return value is not PLDM_SUCCESS, it represents a
239 * transport layer error.
240 * * If the completion_code value is not PLDM_SUCCESS, it represents a
241 * protocol layer error and all the out-parameters are invalid.
242 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500243 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500244 * @param[in] payload_length - Length of response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600245 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600246 * @param[out] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600247 * types (MAX_TYPES/8) = 8), as per DSP0240
248 * @return pldm_completion_codes
249 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500250int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600251 uint8_t *completion_code, bitfield8_t *types);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600252
253/* GetPLDMCommands */
254
255/** @brief Create a PLDM request message for GetPLDMCommands
256 *
257 * @param[in] instance_id - Message's instance id
258 * @param[in] type - PLDM Type
259 * @param[in] version - Version for PLDM Type
260 * @param[in,out] msg - Message will be written to this
261 * @return pldm_completion_codes
262 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500263 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600264 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600265int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
266 struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600267
268/** @brief Decode a GetPLDMCommands response message
269 *
George Liu684a7162019-12-06 15:10:52 +0800270 * Note:
271 * * If the return value is not PLDM_SUCCESS, it represents a
272 * transport layer error.
273 * * If the completion_code value is not PLDM_SUCCESS, it represents a
274 * protocol layer error and all the out-parameters are invalid.
275 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500276 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500277 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600278 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600279 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600280 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
281 * @return pldm_completion_codes
282 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500283int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600284 uint8_t *completion_code, bitfield8_t *commands);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600285
Sampa Misra432e1872019-02-13 03:49:43 -0600286/* GetPLDMVersion */
287
288/** @brief Create a PLDM request for GetPLDMVersion
289 *
290 * @param[in] instance_id - Message's instance id
291 * @param[in] transfer_handle - Handle to identify PLDM version data transfer.
292 * This handle is ignored by the responder when the
293 * transferop_flag is set to getFirstPart.
294 * @param[in] transfer_opflag - flag to indicate whether it is start of
295 * transfer
296 * @param[in] type - PLDM Type for which version is requested
297 * @param[in,out] msg - Message will be written to this
298 * @return pldm_completion_codes
299 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500300 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600301 */
302int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
303 uint8_t transfer_opflag, uint8_t type,
304 struct pldm_msg *msg);
305
306/** @brief Decode a GetPLDMVersion response message
307 *
George Liu684a7162019-12-06 15:10:52 +0800308 * Note:
309 * * If the return value is not PLDM_SUCCESS, it represents a
310 * transport layer error.
311 * * If the completion_code value is not PLDM_SUCCESS, it represents a
312 * protocol layer error and all the out-parameters are invalid.
313 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500314 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500315 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600316 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Sampa Misra432e1872019-02-13 03:49:43 -0600317 * @param[out] next_transfer_handle - the next handle for the next part of data
318 * @param[out] transfer_flag - flag to indicate the part of data
319 * @return pldm_completion_codes
320 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500321int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600322 uint8_t *completion_code,
Sampa Misra432e1872019-02-13 03:49:43 -0600323 uint32_t *next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600324 uint8_t *transfer_flag, ver32_t *version);
Sampa Misra432e1872019-02-13 03:49:43 -0600325
John Wang5c4f80d2019-07-29 11:12:18 +0800326/* GetTID */
327
328/** @brief Decode a GetTID response message
329 *
George Liu684a7162019-12-06 15:10:52 +0800330 * Note:
331 * * If the return value is not PLDM_SUCCESS, it represents a
332 * transport layer error.
333 * * If the completion_code value is not PLDM_SUCCESS, it represents a
334 * protocol layer error and all the out-parameters are invalid.
335 *
John Wang5c4f80d2019-07-29 11:12:18 +0800336 * @param[in] msg - Response message
337 * @param[in] payload_length - Length of response message payload
338 * @param[out] completion_code - Pointer to response msg's PLDM completion code
339 * @param[out] tid - Pointer to the terminus id
340 * @return pldm_completion_codes
341 */
342int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
343 uint8_t *completion_code, uint8_t *tid);
344
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600345/* Responder */
346
347/* GetPLDMTypes */
348
349/** @brief Create a PLDM response message for GetPLDMTypes
350 *
351 * @param[in] instance_id - Message's instance id
352 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600353 * @param[in] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600354 * types (MAX_TYPES/8) = 8), as per DSP0240
355 * @param[in,out] msg - Message will be written to this
356 * @return pldm_completion_codes
357 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500358 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600359 */
360int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600361 const bitfield8_t *types, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600362
363/* GetPLDMCommands */
364
365/** @brief Decode GetPLDMCommands' request data
366 *
vkaverapa6575b82019-04-03 05:33:52 -0500367 * @param[in] msg - Request message
368 * @param[in] payload_length - Length of request message payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600369 * @param[out] type - PLDM Type
370 * @param[out] version - Version for PLDM Type
371 * @return pldm_completion_codes
372 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500373int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length,
vkaverapa6575b82019-04-03 05:33:52 -0500374 uint8_t *type, ver32_t *version);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600375
376/** @brief Create a PLDM response message for GetPLDMCommands
377 *
378 * @param[in] instance_id - Message's instance id
379 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600380 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600381 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
382 * @param[in,out] msg - Message will be written to this
383 * @return pldm_completion_codes
384 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500385 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600386 */
387int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600388 const bitfield8_t *commands, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600389
Sampa Misra432e1872019-02-13 03:49:43 -0600390/* GetPLDMVersion */
391
392/** @brief Create a PLDM response for GetPLDMVersion
393 *
394 * @param[in] instance_id - Message's instance id
395 * @param[in] completion_code - PLDM completion code
396 * @param[in] next_transfer_handle - Handle to identify next portion of
397 * data transfer
398 * @param[in] transfer_flag - Represents the part of transfer
399 * @param[in] version_data - the version data
400 * @param[in] version_size - size of version data
401 * @param[in,out] msg - Message will be written to this
402 * @return pldm_completion_codes
403 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500404 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600405 */
406int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
407 uint32_t next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600408 uint8_t transfer_flag, const ver32_t *version_data,
Sampa Misra432e1872019-02-13 03:49:43 -0600409 size_t version_size, struct pldm_msg *msg);
410
411/** @brief Decode a GetPLDMVersion request message
412 *
vkaverapa6575b82019-04-03 05:33:52 -0500413 * @param[in] msg - Request message
414 * @param[in] payload_length - length of request message payload
Sampa Misra432e1872019-02-13 03:49:43 -0600415 * @param[out] transfer_handle - the handle of data
416 * @param[out] transfer_opflag - Transfer Flag
417 * @param[out] type - PLDM type for which version is requested
418 * @return pldm_completion_codes
419 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500420int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra432e1872019-02-13 03:49:43 -0600421 uint32_t *transfer_handle, uint8_t *transfer_opflag,
422 uint8_t *type);
423
Sridevi Rameshbc6ff262019-12-12 04:58:35 -0600424/* Requester */
425
John Wang5c4f80d2019-07-29 11:12:18 +0800426/* GetTID */
427
Sridevi Rameshbc6ff262019-12-12 04:58:35 -0600428/** @brief Create a PLDM request message for GetTID
429 *
430 * @param[in] instance_id - Message's instance id
431 * @param[in,out] msg - Message will be written to this
432 * @return pldm_completion_codes
433 * @note Caller is responsible for memory alloc and dealloc of param
434 * 'msg.payload'
435 */
436int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg);
437
John Wang5c4f80d2019-07-29 11:12:18 +0800438/** @brief Create a PLDM response message for GetTID
439 *
440 * @param[in] instance_id - Message's instance id
441 * @param[in] completion_code - PLDM completion code
442 * @param[in] tid - Terminus ID
443 * @param[in,out] msg - Message will be written to this
444 * @return pldm_completion_codes
445 * @note Caller is responsible for memory alloc and dealloc of param
446 * 'msg.payload'
447 */
448int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
449 uint8_t tid, struct pldm_msg *msg);
450
John Wang7f02d702019-12-03 13:38:14 +0800451/** @brief Create a PLDM response message containing only cc
452 *
453 * @param[in] instance_id - Message's instance id
454 * @param[in] type - PLDM Type
455 * @param[in] command - PLDM Command
456 * @param[in] cc - PLDM Completion Code
457 * @param[out] msg - Message will be written to this
458 * @return pldm_completion_codes
459 */
460int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
461 uint8_t cc, struct pldm_msg *msg);
462
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600463#ifdef __cplusplus
464}
465#endif
466
467#endif /* BASE_H */