blob: 3ec9e4333daf490dd4370b2d665adc9dfe8a19c4 [file] [log] [blame]
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05301#ifndef FRU_H
2#define FRU_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <asm/byteorder.h>
9#include <stddef.h>
10#include <stdint.h>
11
12#include "base.h"
John Wang9fa87cf2020-06-10 17:53:40 +080013#include "utils.h"
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053014
Christian Geddes3bdb3c22020-05-01 14:55:39 -050015#define PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES 0
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053016#define PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES 19
PriyangaRamasamy497665a2019-07-30 12:48:25 +053017#define PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES 5
18#define PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES 6
John Wang9fa87cf2020-06-10 17:53:40 +080019#define PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES 6
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053020
Christian Geddes3bdb3c22020-05-01 14:55:39 -050021#define FRU_TABLE_CHECKSUM_SIZE 4
22
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053023/** @brief PLDM FRU commands
24 */
25enum pldm_fru_commands {
26 PLDM_GET_FRU_RECORD_TABLE_METADATA = 0X01,
PriyangaRamasamy497665a2019-07-30 12:48:25 +053027 PLDM_GET_FRU_RECORD_TABLE = 0X02,
PriyangaRamasamyf3295be2019-07-23 12:18:40 +053028 PLDM_SET_FRU_RECORD_TABLE = 0X03,
29 PLDM_GET_FRU_RECORD_BY_OPTION = 0X04
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053030};
31
Tom Joseph93d68712020-01-07 10:24:41 +053032/** @brief FRU record types
33 */
34enum pldm_fru_record_type {
35 PLDM_FRU_RECORD_TYPE_GENERAL = 0X01,
36 PLDM_FRU_RECORD_TYPE_OEM = 0XFE,
37};
38
39/** @brief Encoding type for FRU fields
40 */
41enum pldm_fru_field_encoding {
42 PLDM_FRU_ENCODING_UNSPECIFIED = 0X00,
43 PLDM_FRU_ENCODING_ASCII = 0X01,
44 PLDM_FRU_ENCODING_UTF8 = 0X02,
45 PLDM_FRU_ENCODING_UTF16 = 0X03,
46 PLDM_FRU_ENCODING_UTF16LE = 0X04,
47 PLDM_FRU_ENCODING_UTF16BE = 0X05,
48};
49
50/** @brief FRU field types
51 */
52enum pldm_fru_field_type {
53 PLDM_FRU_FIELD_TYPE_CHASSIS = 0X01,
54 PLDM_FRU_FIELD_TYPE_MODEL = 0X02,
55 PLDM_FRU_FIELD_TYPE_PN = 0X03,
56 PLDM_FRU_FIELD_TYPE_SN = 0X04,
57 PLDM_FRU_FIELD_TYPE_MANUFAC = 0X05,
58 PLDM_FRU_FIELD_TYPE_MANUFAC_DATE = 0X06,
59 PLDM_FRU_FIELD_TYPE_VENDOR = 0X07,
60 PLDM_FRU_FIELD_TYPE_NAME = 0X08,
61 PLDM_FRU_FIELD_TYPE_SKU = 0X09,
62 PLDM_FRU_FIELD_TYPE_VERSION = 0X0A,
63 PLDM_FRU_FIELD_TYPE_ASSET_TAG = 0X0B,
64 PLDM_FRU_FIELD_TYPE_DESC = 0X0C,
65 PLDM_FRU_FIELD_TYPE_EC_LVL = 0X0D,
66 PLDM_FRU_FIELD_TYPE_OTHER = 0X0E,
67 PLDM_FRU_FIELD_TYPE_IANA = 0X0F,
68};
69
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053070/** @struct pldm_get_fru_record_table_metadata_resp
71 *
72 * Structure representing PLDM get FRU table metadata response.
73 */
74struct pldm_get_fru_record_table_metadata_resp {
75 uint8_t completion_code; //!< completion code
76 uint8_t fru_data_major_version; //!< The major version of the FRU Record
77 uint8_t fru_data_minor_version; //!< The minor version of the FRU Record
78 uint32_t
79 fru_table_maximum_size; //!< The size of the largest FRU Record data
80 uint32_t fru_table_length; //!< The total length of the FRU Record Table
81 uint16_t total_record_set_identifiers; //!< The total number of FRU
82 //!< Record Data structures
83 uint16_t
84 total_table_records; //!< The total number of records in the table
85 uint32_t
86 checksum; //!< The integrity checksum on the FRU Record Table data
87} __attribute__((packed));
88
PriyangaRamasamy497665a2019-07-30 12:48:25 +053089/** @struct pldm_get_fru_record_table_req
90 *
91 * Structure representing PLDM get FRU record table request.
92 */
93struct pldm_get_fru_record_table_req {
94 uint32_t data_transfer_handle;
95 uint8_t transfer_operation_flag;
96} __attribute__((packed));
97
98/** @struct pldm_get_fru_record_table_resp
99 *
100 * Structure representing PLDM get FRU record table response.
101 */
102struct pldm_get_fru_record_table_resp {
103 uint8_t completion_code;
104 uint32_t next_data_transfer_handle;
105 uint8_t transfer_flag;
106 uint8_t fru_record_table_data[1];
107} __attribute__((packed));
108
John Wang9fa87cf2020-06-10 17:53:40 +0800109struct pldm_get_fru_record_by_option_req {
110 uint32_t data_transfer_handle;
111 uint16_t fru_table_handle;
112 uint16_t record_set_identifier;
113 uint8_t record_type;
114 uint8_t field_type;
115 uint8_t transfer_op_flag;
116} __attribute__((packed));
117
118struct pldm_get_fru_record_by_option_resp {
119 uint8_t completion_code;
120 uint32_t next_data_transfer_handle;
121 uint8_t transfer_flag;
122 uint8_t fru_structure_data[1];
123} __attribute__((packed));
124
Tom Joseph93d68712020-01-07 10:24:41 +0530125/** @struct pldm_fru_record_tlv
126 *
127 * Structure representing each FRU field entry (type, length, value)
128 */
129struct pldm_fru_record_tlv {
130 uint8_t type;
131 uint8_t length;
132 uint8_t value[1];
133} __attribute__((packed));
134
135/** @struct pldm_fru_record_data_format
136 *
137 * Structure representing the FRU record data format
138 */
139struct pldm_fru_record_data_format {
140 uint16_t record_set_id;
141 uint8_t record_type;
142 uint8_t num_fru_fields;
143 uint8_t encoding_type;
144 struct pldm_fru_record_tlv tlvs[1];
145} __attribute__((packed));
146
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530147/* Requester */
148
149/* GetFRURecordTableMetadata */
150
151/** @brief Create a PLDM request message for GetFRURecordTableMetadata
152 *
153 * @param[in] instance_id - Message's instance id
154 * @param[in,out] msg - Message will be written to this
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500155 * @param[in] payload_length - Length of the request message payload
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530156 * @return pldm_completion_codes
157 * @note Caller is responsible for memory alloc and dealloc of param
158 * 'msg.payload'
159 */
160int encode_get_fru_record_table_metadata_req(uint8_t instance_id,
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500161 struct pldm_msg *msg,
162 size_t payload_length);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530163
164/** @brief Decode GetFruRecordTable response data
165 *
George Liu684a7162019-12-06 15:10:52 +0800166 * Note:
167 * * If the return value is not PLDM_SUCCESS, it represents a
168 * transport layer error.
169 * * If the completion_code value is not PLDM_SUCCESS, it represents a
170 * protocol layer error and all the out-parameters are invalid.
171 *
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530172 * @param[in] msg - Response message
173 * @param[in] payload_length - Length of response message payload
174 * @param[out] completion_code - Pointer to response msg's PLDM completion code
175 * @param[out] fru_data_major_version - Major version of the FRU Record
176 * @param[out] fru_data_minor_version - Minor version of the FRU Record
177 * @param[out] fru_table_maximum_size - Size of the largest FRU Record data
178 * @param[out] fru_table_length - Total length of the FRU Record Table
179 * @param[out] total_Record_Set_Identifiers - Total number of FRU Record Data
180 * structures
181 * @param[out] total_table_records - Total number of records in the table
182 * @param[out] checksum - integrity checksum on the FRU Record Table data
183 * @return pldm_completion_codes
184 */
185int decode_get_fru_record_table_metadata_resp(
186 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
187 uint8_t *fru_data_major_version, uint8_t *fru_data_minor_version,
188 uint32_t *fru_table_maximum_size, uint32_t *fru_table_length,
189 uint16_t *total_record_set_identifiers, uint16_t *total_table_records,
190 uint32_t *checksum);
191
192/* Responder */
193
194/* GetFRURecordTableMetadata */
195
196/** @brief Create a PLDM response message for GetFRURecordTableMetadata
197 *
198 * @param[in] instance_id - Message's instance id
199 * @param[in] completion_code - PLDM completion code
200 * @param[in] fru_data_major_version - Major version of the FRU Record
201 * @param[in] fru_data_minor_version - Minor version of the FRU Record
202 * @param[in] fru_table_maximum_size - Size of the largest FRU Record data
203 * @param[in] fru_table_length - Total length of the FRU Record Table
204 * @param[in] total_Record_Set_Identifiers - Total number of FRU Record Data
205 * structures
206 * @param[in] total_table_records - Total number of records in the table
207 * @param[in] checksum - integrity checksum on the FRU Record Table data
208 * @param[in,out] msg - Message will be written to this
209 * @return pldm_completion_codes
210 * @note Caller is responsible for memory alloc and dealloc of param
211 * 'msg.payload'
212 */
213
214int encode_get_fru_record_table_metadata_resp(
215 uint8_t instance_id, uint8_t completion_code,
216 uint8_t fru_data_major_version, uint8_t fru_data_minor_version,
217 uint32_t fru_table_maximum_size, uint32_t fru_table_length,
218 uint16_t total_record_set_identifiers, uint16_t total_table_records,
219 uint32_t checksum, struct pldm_msg *msg);
220
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530221/* GetFruRecordTable */
222
223/** @brief Decode GetFruRecordTable request data
224 *
225 * @param[in] msg - PLDM request message payload
226 * @param[in] payload_length - Length of request payload
227 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
228 * Table data transfer
229 * @param[out] transfer_operation_flag - A flag that indicates whether this is
230 * the start of the transfer
231 * @return pldm_completion_codes
232 */
233int decode_get_fru_record_table_req(const struct pldm_msg *msg,
234 size_t payload_length,
235 uint32_t *data_transfer_handle,
236 uint8_t *transfer_operation_flag);
237
238/** @brief Create a PLDM response message for GetFruRecordTable
239 *
240 * @param[in] instance_id - Message's instance id
241 * @param[in] completion_code - PLDM completion code
242 * @param[in] next_data_transfer_handle - A handle that is used to identify the
243 * next portion of the transfer
244 * @param[in] transfer_flag - The transfer flag that indicates what part of the
245 * transfer this response represents
246 * @param[in,out] msg - Message will be written to this
247 * @return pldm_completion_codes
248 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
249 * and for appending the FRU table to the msg.
250 */
251int encode_get_fru_record_table_resp(uint8_t instance_id,
252 uint8_t completion_code,
253 uint32_t next_data_transfer_handle,
254 uint8_t transfer_flag,
255 struct pldm_msg *msg);
John Wang9fa87cf2020-06-10 17:53:40 +0800256
257/* GetFRURecordByOption */
258
259/** @brief Decode GetFRURecordByOption request data
260 *
261 * @param[in] msg - PLDM request message payload
262 * @param[in] payload_length - Length of request payload
263 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
264 * Table data transfer
265 * @param[out] fru_table_handle - A handle, used to identify a FRU DATA
266 * records
267 * @param[out] record_set_identifier - FRU record set identifier
268 * @param[out] record_type - FRU record type
269 * @param[out] field_type - FRU field type
270 * @param[out] transfer_op_flag - A flag that indicates whether this is
271 * the start of the transfer
272 * @return pldm_completion_codes
273 */
274int decode_get_fru_record_by_option_req(
275 const struct pldm_msg *msg, size_t payload_length,
276 uint32_t *data_transfer_handle, uint16_t *fru_table_handle,
277 uint16_t *record_set_identifier, uint8_t *record_type, uint8_t *field_type,
278 uint8_t *transfer_op_flag);
279
280/** @brief Encode GetFRURecordByOption response data
281 *
282 * @param[in] instance_id - Message's instance id
283 * @param[in] completion_code - PLDM completion code
284 * @param[in] next_data_transfer_handle - A handle that is used to identify the
285 * next portion of the transfer
286 * @param[in] transfer_flag - The transfer flag that indicates what part of the
287 * transfer this response represents
288 * @param[in] fru_structure_data - FRU Structure Data
289 * @param[in] data_size - Size of FRU Structrue Data
290 * @param[in,out] msg - Message will be written to this
291 * @return pldm_completion_codes
292 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
293 * and for appending the FRU table to the msg.
294 */
295int encode_get_fru_record_by_option_resp(uint8_t instance_id,
296 uint8_t completion_code,
297 uint32_t next_data_transfer_handle,
298 uint8_t transfer_flag,
299 const void *fru_structure_data,
300 size_t data_size, struct pldm_msg *msg,
301 size_t payload_length);
302
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530303/* Requester */
304
305/* GetFruRecordTable */
306
307/** @brief Create a PLDM request message for GetFruRecordTable
308 *
309 * @param[in] instance_id - Message's instance id
310 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
311 * Table data transfer
312 * @param[in] transfer_operation_flag - A flag that indicates whether this is
313 * the start of the transfer
314 * @param[in,out] msg - Message will be written to this
315 * @param[in] payload_length - Length of request message payload
316 * @return pldm_completion_codes
317 * @note Caller is responsible for memory alloc and dealloc of param
318 * 'msg.payload'
319 */
320
321int encode_get_fru_record_table_req(uint8_t instance_id,
322 uint32_t data_transfer_handle,
323 uint8_t transfer_operation_flag,
324 struct pldm_msg *msg,
325 size_t payload_length);
326
327/** @brief Decode GetFruRecordTable response data
328 *
329 * @param[in] msg - Response message
330 * @param[in] payload_length - Length of response message payload
331 * @param[out] completion_code - Pointer to response msg's PLDM completion code
332 * @param[out] next_data_transfer_handle - A handle used to identify the next
333 * portion of the transfer
334 * @param[out] transfer_flag - The transfer flag that indicates what part of
335 * the transfer this response represents
336 * @param[out] fru_record_table_data - This data is a portion of the overall
337 * FRU Record Table
338 * @param[out] fru_record_table_length - Length of the FRU record table data
339 * @return pldm_completion_codes
340 */
341
342int decode_get_fru_record_table_resp(
343 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
344 uint32_t *next_data_transfer_handle, uint8_t *transfer_flag,
345 uint8_t *fru_record_table_data, size_t *fru_record_table_length);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530346
Tom Joseph93d68712020-01-07 10:24:41 +0530347/** @brief Encode the FRU record in the FRU table
348 *
349 * @param[in/out] fru_table - Pointer to the FRU table
350 * @param[in] total_size - The size of the table,including the size of FRU
351 * record to be added to the table.
352 * @param[in/out] curr_size - The size of the table, excluding the size of FRU
353 * record to be added to the table.
354 * @param[in] record_set_id - FRU record set identifier
355 * @param[in] record_type - FRU record type
356 * @param[in] num_frus - Number of FRU fields
357 * @param[in] encoding - Encoding type for FRU fields
358 * @param[in] tlvs - Pointer to the buffer with all the FRU fields
359 * @param[in] tlvs_size - Size of the buffer with all the FRU fields
360 *
361 * @return pldm_completion_codes
362 */
363int encode_fru_record(uint8_t *fru_table, size_t total_size, size_t *curr_size,
364 uint16_t record_set_id, uint8_t record_type,
365 uint8_t num_frus, uint8_t encoding, uint8_t *tlvs,
366 size_t tlvs_size);
367
John Wang9fa87cf2020-06-10 17:53:40 +0800368/* GetFRURecordByOption */
369
370/** @brief Create a PLDM request message for GetFRURecordByOption
371 *
372 * @param[in] instance_id - Message's instance id
373 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
374 * Table data transfer
375 * @param[in] fru_table_handle - A handle, used to identify a FRU DATA records
376 * @param[in] record_set_identifier - FRU record set identifier
377 * @param[in] record_type - FRU record type
378 * @param[in] field_type - FRU field type
379 * @param[in] transfer_op_flag - A flag that indicates whether this is
380 * the start of the transfer
381 * @param[in,out] msg - Message will be written to this
382 * @param[in] payload_length - Length of request message payload
383 * @return pldm_completion_codes
384 * @note Caller is responsible for memory alloc and dealloc of param
385 * 'msg.payload'
386 */
387int encode_get_fru_record_by_option_req(
388 uint8_t instance_id, uint32_t data_transfer_handle,
389 uint16_t fru_table_handle, uint16_t record_set_identifier,
390 uint8_t record_type, uint8_t field_type, uint8_t transfer_op_flag,
391 struct pldm_msg *msg, size_t payload_length);
392
393/** @brief Decode GetFRURecordByOption response data
394 *
395 * @param[in] msg - Response message
396 * @param[in] payload_length - Length of response message payload
397 * @param[out] completion_code - Pointer to response msg's PLDM completion code
398 * @param[out] next_data_transfer_handle - A handle used to identify the next
399 * portion of the transfer
400 * @param[out] transfer_flag - The transfer flag that indicates what part of
401 * the transfer this response represents
402 * @param[out] fru_structure_data - FRU Structure Data
403 * @return pldm_completion_codes
404 */
405int decode_get_fru_record_by_option_resp(
406 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
407 uint32_t *next_transfer_handle, uint8_t *transfer_flag,
408 struct variable_field *fru_structure_data);
409
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530410#ifdef __cplusplus
411}
412#endif
413
414#endif