xref: /openbmc/phosphor-logging/extensions/openpower-pels/fru_identity.hpp (revision 81a91e3ee4bf962111cf555ab9d3c3c51000fa3b)
1 #pragma once
2 
3 #include "pel_types.hpp"
4 #include "stream.hpp"
5 
6 #include <optional>
7 
8 namespace openpower
9 {
10 namespace pels
11 {
12 namespace src
13 {
14 
15 /**
16  * @class FRUIdentity
17  *
18  * This represents the FRU Identity substructure in the
19  * callout subsection of the SRC PEL section.
20  *
21  * It provides information about the FRU being called out,
22  * such as serial number and part number.  A maintenance
23  * procedure name may be used instead of the part number,
24  * and this would be indicated in the flags field.
25  */
26 class FRUIdentity
27 {
28   public:
29     /**
30      * @brief The failing component type
31      *
32      * Upper nibble of the flags byte
33      */
34     enum FailingComponentType
35     {
36         hardwareFRU = 0x10,
37         codeFRU = 0x20,
38         configError = 0x30,
39         maintenanceProc = 0x40,
40         externalFRU = 0x90,
41         externalCodeFRU = 0xA0,
42         toolFRU = 0xB0,
43         symbolicFRU = 0xC0,
44         symbolicFRUTrustedLocCode = 0xE0
45     };
46 
47     /**
48      * @brief The lower nibble of the flags byte
49      */
50     enum Flags
51     {
52         pnSupplied = 0x08,
53         ccinSupplied = 0x04,
54         maintProcSupplied = 0x02,
55         snSupplied = 0x01
56     };
57 
58     FRUIdentity() = delete;
59     ~FRUIdentity() = default;
60     FRUIdentity(const FRUIdentity&) = default;
61     FRUIdentity& operator=(const FRUIdentity&) = default;
62     FRUIdentity(FRUIdentity&&) = default;
63     FRUIdentity& operator=(FRUIdentity&&) = default;
64 
65     /**
66      * @brief Constructor
67      *
68      * Fills in this class's data fields from the stream.
69      *
70      * @param[in] pel - the PEL data stream
71      */
72     explicit FRUIdentity(Stream& pel);
73 
74     /**
75      * Constructor
76      *
77      * Creates the object as a hardware callout with the part number,
78      * CCIN, and serial number fields supplied.
79      *
80      * @param[in] partNumber - The part number of the FRU
81      * @param[in] ccin - The CCIN of the FRU
82      * @param[in] serialNumber - The serial number of the FRU
83      */
84     FRUIdentity(const std::string& partNumber, const std::string& ccin,
85                 const std::string& serialNumber);
86 
87     /**
88      * @brief Constructor
89      *
90      * Creates the object with a maintenance procedure callout.
91      *
92      * @param[in] procedureFromRegistry - The maintenance procedure name
93      *                                    as defined in the message registry.
94      */
95     FRUIdentity(const std::string& procedureFromRegistry);
96 
97     /**
98      * @brief Constructor
99      *
100      * Creates the object with a symbolic FRU callout.
101      *
102      * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as
103      *                                      defined in the message registry.
104      * @param[in] trustedLocationCode - If this FRU callout's location code
105      *                                  can be trusted to be correct.
106      */
107     FRUIdentity(const std::string& symbolicFRUFromRegistry,
108                 bool trustedLocationCode);
109 
110     /**
111      * @brief Flatten the object into the stream
112      *
113      * @param[in] stream - The stream to write to
114      */
115     void flatten(Stream& pel) const;
116 
117     /**
118      * @brief Returns the size of this structure when flattened into a PEL
119      *
120      * @return size_t - The size of the section
121      */
122     size_t flattenedSize() const;
123 
124     /**
125      * @brief Returns the type field
126      *
127      * @return uint16_t - The type, always 0x4944 "ID".
128      */
129     uint16_t type() const
130     {
131         return _type;
132     }
133     /**
134      * @brief The failing component type for this FRU callout.
135      *
136      * @return FailingComponentType
137      */
138     FailingComponentType failingComponentType() const
139     {
140         return static_cast<FailingComponentType>(_flags & 0xF0);
141     }
142 
143     /**
144      * @brief Returns the part number, if supplied
145      *
146      * @return std::optional<std::string>
147      */
148     std::optional<std::string> getPN() const;
149 
150     /**
151      * @brief Returns the maintenance procedure, if supplied
152      *
153      * @return std::optional<std::string>
154      */
155     std::optional<std::string> getMaintProc() const;
156 
157     /**
158      * @brief Returns the CCIN, if supplied
159      *
160      * @return std::optional<std::string>
161      */
162     std::optional<std::string> getCCIN() const;
163 
164     /**
165      * @brief Returns the serial number, if supplied
166      *
167      * @return std::optional<std::string>
168      */
169     std::optional<std::string> getSN() const;
170 
171     /**
172      * @brief The type identifier value of this structure.
173      */
174     static const uint16_t substructureType = 0x4944; // "ID"
175 
176   private:
177     /**
178      * @brief If the part number is contained in this structure.
179      *
180      * It takes the place of the maintenance procedure ID.
181      *
182      * @return bool
183      */
184     bool hasPN() const
185     {
186         return _flags & pnSupplied;
187     }
188 
189     /**
190      * @brief If the CCIN is contained in this structure.
191      *
192      * @return bool
193      */
194     bool hasCCIN() const
195     {
196         return _flags & ccinSupplied;
197     }
198 
199     /**
200      * @brief If a maintenance procedure is contained in this structure.
201      *
202      * It takes the place of the part number.
203      *
204      * @return bool
205      */
206     bool hasMP() const
207     {
208         return _flags & maintProcSupplied;
209     }
210 
211     /**
212      * @brief If the serial number is contained in this structure.
213      *
214      * @return bool
215      */
216     bool hasSN() const
217     {
218         return _flags & snSupplied;
219     }
220 
221     /**
222      * @brief Sets the 8 character null terminated part
223      *        number field to the string passed in.
224      *
225      * @param[in] partNumber - The part number string.
226      */
227     void setPartNumber(const std::string& partNumber);
228 
229     /**
230      * @brief Sets the 4 character CCIN field.
231      *
232      * @param[in] ccin - The CCIN string
233      */
234     void setCCIN(const std::string& ccin);
235 
236     /**
237      * @brief Sets the 12 character serial number field.
238      *
239      * @param[in] serialNumber - The serial number string
240      */
241     void setSerialNumber(const std::string& serialNumber);
242 
243     /**
244      * @brief Sets the 8 character null terminated procedure
245      *        field.  This is in the same field as the part
246      *        number since they are mutually exclusive.
247      *
248      * @param procedureFromRegistry - The procedure name as defined in
249      *                                the PEL message registry.
250      */
251     void setMaintenanceProcedure(const std::string& procedureFromRegistry);
252 
253     /**
254      * @brief Sets the 8 character null terminated symbolic FRU
255      *        field.  This is in the same field as the part
256      *        number since they are mutually exclusive.
257      *
258      * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as
259      *                                      defined in the message registry.
260      */
261     void setSymbolicFRU(const std::string& symbolicFRUFromRegistry);
262 
263     /**
264      * @brief The callout substructure type field. Will be "ID".
265      */
266     uint16_t _type;
267 
268     /**
269      * @brief The size of this callout structure.
270      *
271      * Always a multiple of 4.
272      */
273     uint8_t _size;
274 
275     /**
276      * @brief The flags byte of this substructure.
277      *
278      * See the FailingComponentType and Flags enums
279      */
280     uint8_t _flags;
281 
282     /**
283      * @brief The part number OR maintenance procedure ID,
284      *        depending on what the flags field specifies.
285      *
286      * A NULL terminated ASCII string.
287      */
288     std::array<char, 8> _pnOrProcedureID;
289 
290     /**
291      * @brief The CCIN VPD keyword
292      *
293      * Four ASCII characters, not NULL terminated.
294      */
295     std::array<char, 4> _ccin;
296 
297     /**
298      * @brief The serial number
299      *
300      * Twelve ASCII characters, not NULL terminated.
301      */
302     std::array<char, 12> _sn;
303 };
304 
305 } // namespace src
306 } // namespace pels
307 } // namespace openpower
308