blob: 186c8f996852753f7bf2100afb8b85b28c381582 [file] [log] [blame]
Matt Spinlera906c942019-10-08 13:42:05 -05001#pragma once
2
3#include "stream.hpp"
4
Matt Spinler46139b02022-06-03 13:25:41 -05005#include <array>
Matt Spinlera906c942019-10-08 13:42:05 -05006#include <optional>
7
8namespace openpower
9{
10namespace pels
11{
12namespace src
13{
14
15/**
Matt Spinler468aab52020-08-13 11:04:31 -050016 * @brief Specifies if the incoming maintenance procedure or
17 * symbolic FRU is the registry name or the raw name.
18 */
19enum class CalloutValueType
20{
21 raw,
22 registryName
23};
24
25/**
Matt Spinlera906c942019-10-08 13:42:05 -050026 * @class FRUIdentity
27 *
28 * This represents the FRU Identity substructure in the
29 * callout subsection of the SRC PEL section.
30 *
31 * It provides information about the FRU being called out,
32 * such as serial number and part number. A maintenance
33 * procedure name may be used instead of the part number,
34 * and this would be indicated in the flags field.
35 */
36class FRUIdentity
37{
38 public:
39 /**
40 * @brief The failing component type
41 *
42 * Upper nibble of the flags byte
43 */
44 enum FailingComponentType
45 {
46 hardwareFRU = 0x10,
47 codeFRU = 0x20,
48 configError = 0x30,
49 maintenanceProc = 0x40,
50 externalFRU = 0x90,
51 externalCodeFRU = 0xA0,
52 toolFRU = 0xB0,
53 symbolicFRU = 0xC0,
54 symbolicFRUTrustedLocCode = 0xE0
55 };
56
57 /**
58 * @brief The lower nibble of the flags byte
59 */
60 enum Flags
61 {
62 pnSupplied = 0x08,
63 ccinSupplied = 0x04,
64 maintProcSupplied = 0x02,
65 snSupplied = 0x01
66 };
67
68 FRUIdentity() = delete;
69 ~FRUIdentity() = default;
70 FRUIdentity(const FRUIdentity&) = default;
71 FRUIdentity& operator=(const FRUIdentity&) = default;
72 FRUIdentity(FRUIdentity&&) = default;
73 FRUIdentity& operator=(FRUIdentity&&) = default;
74
75 /**
76 * @brief Constructor
77 *
78 * Fills in this class's data fields from the stream.
79 *
80 * @param[in] pel - the PEL data stream
81 */
82 explicit FRUIdentity(Stream& pel);
83
84 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -050085 * Constructor
86 *
87 * Creates the object as a hardware callout with the part number,
88 * CCIN, and serial number fields supplied.
89 *
90 * @param[in] partNumber - The part number of the FRU
91 * @param[in] ccin - The CCIN of the FRU
92 * @param[in] serialNumber - The serial number of the FRU
93 */
94 FRUIdentity(const std::string& partNumber, const std::string& ccin,
95 const std::string& serialNumber);
96
97 /**
98 * @brief Constructor
99 *
100 * Creates the object with a maintenance procedure callout.
101 *
Matt Spinlera27e2e52020-04-09 11:06:11 -0500102 * @param[in] procedureFromRegistry - The maintenance procedure name
103 * as defined in the message registry.
Matt Spinlerba0ee002020-03-13 11:24:14 -0500104 */
Matt Spinler45796e82022-07-01 11:25:27 -0500105 explicit FRUIdentity(const std::string& procedureFromRegistry) :
Matt Spinler468aab52020-08-13 11:04:31 -0500106 FRUIdentity(procedureFromRegistry, CalloutValueType::registryName)
Patrick Williams2544b412022-10-04 08:41:06 -0500107 {}
Matt Spinler468aab52020-08-13 11:04:31 -0500108
109 /**
110 * @brief Constructor
111 *
112 * Creates the object with a maintenance procedure callout.
113 *
114 * @param[in] procedure - The maintenance procedure name.
115 * @param[in] type - If the procedure is the raw name or the registry name.
116 */
117 FRUIdentity(const std::string& procedure, CalloutValueType type);
Matt Spinlerba0ee002020-03-13 11:24:14 -0500118
119 /**
Matt Spinler2b6dfa02020-04-09 11:39:05 -0500120 * @brief Constructor
121 *
122 * Creates the object with a symbolic FRU callout.
123 *
124 * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as
125 * defined in the message registry.
126 * @param[in] trustedLocationCode - If this FRU callout's location code
127 * can be trusted to be correct.
128 */
129 FRUIdentity(const std::string& symbolicFRUFromRegistry,
Matt Spinler468aab52020-08-13 11:04:31 -0500130 bool trustedLocationCode) :
131 FRUIdentity(symbolicFRUFromRegistry, CalloutValueType::registryName,
132 trustedLocationCode)
Patrick Williams2544b412022-10-04 08:41:06 -0500133 {}
Matt Spinler468aab52020-08-13 11:04:31 -0500134
135 /**
136 * @brief Constructor
137 *
138 * Creates the object with a symbolic FRU callout.
139 *
140 * @param[in] fru - The symbolic FRU name.
141 * @param[in] type - If the FRU is the raw name or the registry name.
142 * @param[in] trustedLocationCode - If this FRU callout's location code
143 * can be trusted to be correct.
144 */
145 FRUIdentity(const std::string& fru, CalloutValueType type,
Matt Spinler2b6dfa02020-04-09 11:39:05 -0500146 bool trustedLocationCode);
147
148 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500149 * @brief Flatten the object into the stream
150 *
151 * @param[in] stream - The stream to write to
152 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600153 void flatten(Stream& pel) const;
Matt Spinlera906c942019-10-08 13:42:05 -0500154
155 /**
156 * @brief Returns the size of this structure when flattened into a PEL
157 *
158 * @return size_t - The size of the section
159 */
Matt Spinlera09354b2020-03-13 10:24:52 -0500160 size_t flattenedSize() const;
Matt Spinlera906c942019-10-08 13:42:05 -0500161
162 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500163 * @brief Returns the type field
164 *
165 * @return uint16_t - The type, always 0x4944 "ID".
166 */
167 uint16_t type() const
168 {
169 return _type;
170 }
171 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500172 * @brief The failing component type for this FRU callout.
173 *
174 * @return FailingComponentType
175 */
176 FailingComponentType failingComponentType() const
177 {
178 return static_cast<FailingComponentType>(_flags & 0xF0);
179 }
180
181 /**
182 * @brief Returns the part number, if supplied
183 *
184 * @return std::optional<std::string>
185 */
186 std::optional<std::string> getPN() const;
187
188 /**
189 * @brief Returns the maintenance procedure, if supplied
190 *
191 * @return std::optional<std::string>
192 */
193 std::optional<std::string> getMaintProc() const;
194
195 /**
196 * @brief Returns the CCIN, if supplied
197 *
198 * @return std::optional<std::string>
199 */
200 std::optional<std::string> getCCIN() const;
201
202 /**
203 * @brief Returns the serial number, if supplied
204 *
205 * @return std::optional<std::string>
206 */
207 std::optional<std::string> getSN() const;
208
209 /**
210 * @brief The type identifier value of this structure.
211 */
212 static const uint16_t substructureType = 0x4944; // "ID"
213
214 private:
215 /**
216 * @brief If the part number is contained in this structure.
217 *
218 * It takes the place of the maintenance procedure ID.
219 *
220 * @return bool
221 */
222 bool hasPN() const
223 {
224 return _flags & pnSupplied;
225 }
226
227 /**
228 * @brief If the CCIN is contained in this structure.
229 *
230 * @return bool
231 */
232 bool hasCCIN() const
233 {
234 return _flags & ccinSupplied;
235 }
236
237 /**
238 * @brief If a maintenance procedure is contained in this structure.
239 *
240 * It takes the place of the part number.
241 *
242 * @return bool
243 */
244 bool hasMP() const
245 {
246 return _flags & maintProcSupplied;
247 }
248
249 /**
250 * @brief If the serial number is contained in this structure.
251 *
252 * @return bool
253 */
254 bool hasSN() const
255 {
256 return _flags & snSupplied;
257 }
258
259 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500260 * @brief Sets the 8 character null terminated part
261 * number field to the string passed in.
262 *
263 * @param[in] partNumber - The part number string.
264 */
265 void setPartNumber(const std::string& partNumber);
266
267 /**
268 * @brief Sets the 4 character CCIN field.
269 *
270 * @param[in] ccin - The CCIN string
271 */
272 void setCCIN(const std::string& ccin);
273
274 /**
275 * @brief Sets the 12 character serial number field.
276 *
277 * @param[in] serialNumber - The serial number string
278 */
279 void setSerialNumber(const std::string& serialNumber);
280
281 /**
282 * @brief Sets the 8 character null terminated procedure
283 * field. This is in the same field as the part
284 * number since they are mutually exclusive.
Matt Spinlera27e2e52020-04-09 11:06:11 -0500285 *
Matt Spinler468aab52020-08-13 11:04:31 -0500286 * @param procedure - The procedure name.
287 * @param[in] type - If the procedure is the raw name or
288 * the registry name.
Matt Spinlerba0ee002020-03-13 11:24:14 -0500289 */
Matt Spinler468aab52020-08-13 11:04:31 -0500290 void setMaintenanceProcedure(const std::string& procedure,
291 CalloutValueType type);
Matt Spinlerba0ee002020-03-13 11:24:14 -0500292
293 /**
Matt Spinler2b6dfa02020-04-09 11:39:05 -0500294 * @brief Sets the 8 character null terminated symbolic FRU
295 * field. This is in the same field as the part
296 * number since they are mutually exclusive.
297 *
Matt Spinler468aab52020-08-13 11:04:31 -0500298 * @param[in] symbolicFRU - The symbolic FRU name.
299 * @param[in] type - If the FRU is the raw name or
300 * the registry name.
Matt Spinler2b6dfa02020-04-09 11:39:05 -0500301 */
Matt Spinler468aab52020-08-13 11:04:31 -0500302 void setSymbolicFRU(const std::string& symbolicFRU, CalloutValueType type);
Matt Spinler2b6dfa02020-04-09 11:39:05 -0500303
304 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500305 * @brief The callout substructure type field. Will be "ID".
306 */
307 uint16_t _type;
308
309 /**
310 * @brief The size of this callout structure.
311 *
312 * Always a multiple of 4.
313 */
314 uint8_t _size;
315
316 /**
317 * @brief The flags byte of this substructure.
318 *
319 * See the FailingComponentType and Flags enums
320 */
321 uint8_t _flags;
322
323 /**
324 * @brief The part number OR maintenance procedure ID,
325 * depending on what the flags field specifies.
326 *
327 * A NULL terminated ASCII string.
328 */
329 std::array<char, 8> _pnOrProcedureID;
330
331 /**
332 * @brief The CCIN VPD keyword
333 *
334 * Four ASCII characters, not NULL terminated.
335 */
336 std::array<char, 4> _ccin;
337
338 /**
339 * @brief The serial number
340 *
341 * Twelve ASCII characters, not NULL terminated.
342 */
343 std::array<char, 12> _sn;
344};
345
346} // namespace src
347} // namespace pels
348} // namespace openpower