blob: bf7b2f79d67321c677abf838cc67b81161c7bfb6 [file] [log] [blame]
Matt Spinlera906c942019-10-08 13:42:05 -05001#pragma once
2
3#include "stream.hpp"
4
5#include <optional>
6
7namespace openpower
8{
9namespace pels
10{
11namespace src
12{
13
14/**
15 * @class FRUIdentity
16 *
17 * This represents the FRU Identity substructure in the
18 * callout subsection of the SRC PEL section.
19 *
20 * It provides information about the FRU being called out,
21 * such as serial number and part number. A maintenance
22 * procedure name may be used instead of the part number,
23 * and this would be indicated in the flags field.
24 */
25class FRUIdentity
26{
27 public:
28 /**
29 * @brief The failing component type
30 *
31 * Upper nibble of the flags byte
32 */
33 enum FailingComponentType
34 {
35 hardwareFRU = 0x10,
36 codeFRU = 0x20,
37 configError = 0x30,
38 maintenanceProc = 0x40,
39 externalFRU = 0x90,
40 externalCodeFRU = 0xA0,
41 toolFRU = 0xB0,
42 symbolicFRU = 0xC0,
43 symbolicFRUTrustedLocCode = 0xE0
44 };
45
46 /**
47 * @brief The lower nibble of the flags byte
48 */
49 enum Flags
50 {
51 pnSupplied = 0x08,
52 ccinSupplied = 0x04,
53 maintProcSupplied = 0x02,
54 snSupplied = 0x01
55 };
56
57 FRUIdentity() = delete;
58 ~FRUIdentity() = default;
59 FRUIdentity(const FRUIdentity&) = default;
60 FRUIdentity& operator=(const FRUIdentity&) = default;
61 FRUIdentity(FRUIdentity&&) = default;
62 FRUIdentity& operator=(FRUIdentity&&) = default;
63
64 /**
65 * @brief Constructor
66 *
67 * Fills in this class's data fields from the stream.
68 *
69 * @param[in] pel - the PEL data stream
70 */
71 explicit FRUIdentity(Stream& pel);
72
73 /**
74 * @brief Flatten the object into the stream
75 *
76 * @param[in] stream - The stream to write to
77 */
Matt Spinler724d0d82019-11-06 10:05:36 -060078 void flatten(Stream& pel) const;
Matt Spinlera906c942019-10-08 13:42:05 -050079
80 /**
81 * @brief Returns the size of this structure when flattened into a PEL
82 *
83 * @return size_t - The size of the section
84 */
Matt Spinlera09354b2020-03-13 10:24:52 -050085 size_t flattenedSize() const;
Matt Spinlera906c942019-10-08 13:42:05 -050086
87 /**
88 * @brief The failing component type for this FRU callout.
89 *
90 * @return FailingComponentType
91 */
92 FailingComponentType failingComponentType() const
93 {
94 return static_cast<FailingComponentType>(_flags & 0xF0);
95 }
96
97 /**
98 * @brief Returns the part number, if supplied
99 *
100 * @return std::optional<std::string>
101 */
102 std::optional<std::string> getPN() const;
103
104 /**
105 * @brief Returns the maintenance procedure, if supplied
106 *
107 * @return std::optional<std::string>
108 */
109 std::optional<std::string> getMaintProc() const;
110
111 /**
112 * @brief Returns the CCIN, if supplied
113 *
114 * @return std::optional<std::string>
115 */
116 std::optional<std::string> getCCIN() const;
117
118 /**
119 * @brief Returns the serial number, if supplied
120 *
121 * @return std::optional<std::string>
122 */
123 std::optional<std::string> getSN() const;
124
125 /**
126 * @brief The type identifier value of this structure.
127 */
128 static const uint16_t substructureType = 0x4944; // "ID"
129
130 private:
131 /**
132 * @brief If the part number is contained in this structure.
133 *
134 * It takes the place of the maintenance procedure ID.
135 *
136 * @return bool
137 */
138 bool hasPN() const
139 {
140 return _flags & pnSupplied;
141 }
142
143 /**
144 * @brief If the CCIN is contained in this structure.
145 *
146 * @return bool
147 */
148 bool hasCCIN() const
149 {
150 return _flags & ccinSupplied;
151 }
152
153 /**
154 * @brief If a maintenance procedure is contained in this structure.
155 *
156 * It takes the place of the part number.
157 *
158 * @return bool
159 */
160 bool hasMP() const
161 {
162 return _flags & maintProcSupplied;
163 }
164
165 /**
166 * @brief If the serial number is contained in this structure.
167 *
168 * @return bool
169 */
170 bool hasSN() const
171 {
172 return _flags & snSupplied;
173 }
174
175 /**
176 * @brief The callout substructure type field. Will be "ID".
177 */
178 uint16_t _type;
179
180 /**
181 * @brief The size of this callout structure.
182 *
183 * Always a multiple of 4.
184 */
185 uint8_t _size;
186
187 /**
188 * @brief The flags byte of this substructure.
189 *
190 * See the FailingComponentType and Flags enums
191 */
192 uint8_t _flags;
193
194 /**
195 * @brief The part number OR maintenance procedure ID,
196 * depending on what the flags field specifies.
197 *
198 * A NULL terminated ASCII string.
199 */
200 std::array<char, 8> _pnOrProcedureID;
201
202 /**
203 * @brief The CCIN VPD keyword
204 *
205 * Four ASCII characters, not NULL terminated.
206 */
207 std::array<char, 4> _ccin;
208
209 /**
210 * @brief The serial number
211 *
212 * Twelve ASCII characters, not NULL terminated.
213 */
214 std::array<char, 12> _sn;
215};
216
217} // namespace src
218} // namespace pels
219} // namespace openpower