1 /*
2 * Copyright (c) 2019-2020, Broadcom
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef FRU_H
8 #define FRU_H
9
10 #include <stdbool.h>
11 #include <stdint.h>
12
13 /* max string length */
14 #define FRU_MAX_STR_LEN 32
15
16 /* max number of DDR channels */
17 #define BCM_MAX_NR_DDR 3
18
19 /* max supported FRU table size */
20 #define BCM_MAX_FRU_LEN 512
21
22 /* FRU table starting offset */
23 #define BCM_FRU_TBL_OFFSET 0x300000
24
25 /* FRU time constants */
26 #define MINS_PER_DAY 1440
27 #define MINS_PER_HOUR 60
28 #define FRU_YEAR_START 1996
29 #define FRU_MONTH_START 1
30 #define FRU_DAY_START 1
31 #define MONTHS_PER_YEAR 12
32
33 /*
34 * FRU areas based on the spec
35 */
36 enum fru_area_name {
37 FRU_AREA_INTERNAL = 0,
38 FRU_AREA_CHASSIS_INFO,
39 FRU_AREA_BOARD_INFO,
40 FRU_AREA_PRODUCT_INFO,
41 FRU_AREA_MRECORD_INFO,
42 FRU_MAX_NR_AREAS
43 };
44
45 /*
46 * FRU area information
47 *
48 * @use: indicate this area is being used
49 * @version: format version
50 * @offset: offset of this area from the beginning of the FRU table
51 * @len: total length of the area
52 */
53 struct fru_area_info {
54 bool use;
55 uint8_t version;
56 unsigned int offset;
57 unsigned int len;
58 };
59
60 /*
61 * DDR MCB information
62 *
63 * @idx: DDR channel index
64 * @size_mb: DDR size of this channel in MB
65 * @ref_id: DDR MCB reference ID
66 */
67 struct ddr_mcb {
68 unsigned int idx;
69 unsigned int size_mb;
70 uint32_t ref_id;
71 };
72
73 /*
74 * DDR information
75 *
76 * @ddr_info: array that contains MCB related info for each channel
77 */
78 struct ddr_info {
79 struct ddr_mcb mcb[BCM_MAX_NR_DDR];
80 };
81
82 /*
83 * FRU board area information
84 *
85 * @lang: Language code
86 * @mfg_date: Manufacturing date
87 * @manufacturer: Manufacturer
88 * @product_name: Product name
89 * @serial_number: Serial number
90 * @part_number: Part number
91 * @file_id: FRU file ID
92 */
93 struct fru_board_info {
94 unsigned char lang;
95 unsigned int mfg_date;
96 unsigned char manufacturer[FRU_MAX_STR_LEN];
97 unsigned char product_name[FRU_MAX_STR_LEN];
98 unsigned char serial_number[FRU_MAX_STR_LEN];
99 unsigned char part_number[FRU_MAX_STR_LEN];
100 unsigned char file_id[FRU_MAX_STR_LEN];
101 };
102
103 /*
104 * FRU manufacture date in human readable format
105 */
106 struct fru_time {
107 unsigned int min;
108 unsigned int hour;
109 unsigned int day;
110 unsigned int month;
111 unsigned int year;
112 };
113
114 #ifdef USE_FRU
115 int fru_validate(uint8_t *data, struct fru_area_info *fru_area);
116 int fru_parse_ddr(uint8_t *data, struct fru_area_info *area,
117 struct ddr_info *ddr);
118 int fru_parse_board(uint8_t *data, struct fru_area_info *area,
119 struct fru_board_info *board);
120 void fru_format_time(unsigned int min, struct fru_time *tm);
121 #else
fru_validate(uint8_t * data,struct fru_area_info * fru_area)122 static inline int fru_validate(uint8_t *data, struct fru_area_info *fru_area)
123 {
124 return -1;
125 }
126
fru_parse_ddr(uint8_t * data,struct fru_area_info * area,struct ddr_info * ddr)127 static inline int fru_parse_ddr(uint8_t *data, struct fru_area_info *area,
128 struct ddr_info *ddr)
129 {
130 return -1;
131 }
132
fru_parse_board(uint8_t * data,struct fru_area_info * area,struct fru_board_info * board)133 static inline int fru_parse_board(uint8_t *data, struct fru_area_info *area,
134 struct fru_board_info *board)
135 {
136 return -1;
137 }
138
fru_format_time(unsigned int min,struct fru_time * tm)139 static inline void fru_format_time(unsigned int min, struct fru_time *tm)
140 {
141 }
142 #endif /* USE_FRU */
143
144 #endif /* FRU_H */
145