xref: /openbmc/phosphor-logging/extensions/openpower-pels/callout.hpp (revision 8a09b982ddeb0c1e13190d9cd196e06a778d6140)
1 #pragma once
2 
3 #include "fru_identity.hpp"
4 #include "mru.hpp"
5 #include "pce_identity.hpp"
6 #include "pel_types.hpp"
7 #include "stream.hpp"
8 
9 #include <memory>
10 
11 namespace openpower
12 {
13 namespace pels
14 {
15 namespace src
16 {
17 
18 /**
19  * @class Callout
20  *
21  * Represents a single FRU callout in the SRC's FRU callout
22  * subsection.
23  *
24  * The 'Callouts' class holds a list of these objects.
25  *
26  * The callout priority and location code are in this structure.
27  *
28  * There can also be up to one each of three types of substructures
29  * in a single callout:
30  *  * FRU Identity  (must be first if present)
31  *  * Power Controlling Enclosure (PCE)
32  *  * Manufacturing Replaceable Unit (MRU)
33  *
34  * These substructures have their own objects managed by unique_ptrs
35  * which will only be allocated if those substructures exist.
36  */
37 class Callout
38 {
39   public:
40     /**
41      * @brief Which callout substructures are included.
42      */
43     enum calloutFlags
44     {
45         calloutType = 0b0010'0000,
46         fruIdentIncluded = 0b0000'1000,
47         mruIncluded = 0b0000'0100
48 
49         // Leaving out the various PCE identity ones since
50         // we don't use them.
51     };
52 
53     Callout() = delete;
54     ~Callout() = default;
55     Callout(const Callout&) = delete;
56     Callout& operator=(const Callout&) = delete;
57     Callout(Callout&&) = delete;
58     Callout& operator=(Callout&&) = delete;
59 
60     /**
61      * @brief Constructor
62      *
63      * Fills in this class's data fields from the stream.
64      *
65      * @param[in] pel - the PEL data stream
66      */
67     explicit Callout(Stream& pel);
68 
69     /**
70      * @brief Constructor
71      *
72      * Creates the objects with a FRUIdentity substructure that calls
73      * out a normal hardware FRU.
74      *
75      * @param[in] priority - The priority of the callout
76      * @param[in] locationCode - The location code of the callout
77      * @param[in] partNumber - The part number of the callout
78      * @param[in] ccin - The CCIN of the callout
79      * @param[in] serialNumber - The serial number of the callout
80      */
81     Callout(CalloutPriority priority, const std::string& locationCode,
82             const std::string& partNumber, const std::string& ccin,
83             const std::string& serialNumber);
84 
85     /**
86      * @brief Constructor
87      *
88      * Creates the objects with a FRUIdentity substructure that calls
89      * out a normal hardware FRU, and takes a list of MRUs that will
90      * be added to the callout.
91      *
92      * @param[in] priority - The priority of the callout
93      * @param[in] locationCode - The location code of the callout
94      * @param[in] partNumber - The part number of the callout
95      * @param[in] ccin - The CCIN of the callout
96      * @param[in] serialNumber - The serial number of the callout
97      * @param[in] mrus - The MRUs, if any, to add to the callout
98      */
99     Callout(CalloutPriority priority, const std::string& locationCode,
100             const std::string& partNumber, const std::string& ccin,
101             const std::string& serialNumber,
102             const std::vector<MRU::MRUCallout>& mrus);
103 
104     /**
105      * @brief Constructor
106      *
107      * Creates the objects with a FRUIdentity substructure that calls
108      * out a maintenance procedure.
109      *
110      * @param[in] priority - The priority of the callout
111      * @param[in] procedure - The maintenance procedure name
112      * @param[in] type - If the procedure is the raw name or the registry name
113      */
114     Callout(CalloutPriority priority, const std::string& procedure,
115             CalloutValueType type);
116 
117     /**
118      * @brief Constructor
119      *
120      * Creates the objects with a FRUIdentity substructure that calls
121      * out a maintenance procedure.
122      *
123      * @param[in] priority - The priority of the callout
124      * @param[in] procedureFromRegistry - The maintenance procedure name
125      *                                    as defined in the message registry.
126      */
Callout(CalloutPriority priority,const std::string & procedureFromRegistry)127     Callout(CalloutPriority priority,
128             const std::string& procedureFromRegistry) :
129         Callout(priority, procedureFromRegistry, CalloutValueType::registryName)
130     {}
131 
132     /**
133      * @brief Constructor
134      *
135      * Creates the objects with a FRUIdentity substructure that calls
136      * out a symbolic FRU.
137      *
138      * @param[in] priority - The priority of the callout
139      * @param[in] symbolicFRU - The symbolic FRU name
140      * @param[in] type - If the FRU is the raw name or the registry name
141      * @param[in] locationCode - The location code of the callout
142      * @param[in] trustedLocationCode - If the location is trusted
143      */
144     Callout(CalloutPriority priority, const std::string& symbolicFRU,
145             CalloutValueType type, const std::string& locationCode,
146             bool trustedLocationCode);
147 
148     /**
149      * @brief Constructor
150      *
151      * Creates the objects with a FRUIdentity substructure that calls
152      * out a symbolic FRU.
153      *
154      * @param[in] priority - The priority of the callout
155      * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as
156      *                                      defined in the message registry.
157      * @param[in] locationCode - The location code of the callout
158      * @param[in] trustedLocationCode - If the location is trusted
159      */
Callout(CalloutPriority priority,const std::string & symbolicFRUFromRegistry,const std::string & locationCode,bool trustedLocationCode)160     Callout(CalloutPriority priority,
161             const std::string& symbolicFRUFromRegistry,
162             const std::string& locationCode, bool trustedLocationCode) :
163         Callout(priority, symbolicFRUFromRegistry,
164                 CalloutValueType::registryName, locationCode,
165                 trustedLocationCode)
166     {}
167 
168     /**
169      * @brief Returns the size of this object when flattened into a PEL
170      *
171      * @return size_t - The size of the section
172      */
173     size_t flattenedSize() const;
174 
175     /**
176      * @brief Flatten the object into the stream
177      *
178      * @param[in] stream - The stream to write to
179      */
180     void flatten(Stream& pel) const;
181 
182     /**
183      * @brief Returns the flags field of a callout
184      *
185      * @return uint8_t - The flags
186      */
flags() const187     uint8_t flags() const
188     {
189         return _flags;
190     }
191 
192     /**
193      * @brief Returns the priority field of a callout
194      *
195      * @return uint8_t - The priority
196      */
priority() const197     uint8_t priority() const
198     {
199         return _priority;
200     }
201 
202     /**
203      * @brief Set the priority of the callout
204      *
205      * @param[in] priority - The priority value
206      */
setPriority(uint8_t priority)207     void setPriority(uint8_t priority)
208     {
209         _priority = priority;
210     }
211 
212     /**
213      * @brief Returns the location code of the callout
214      *
215      * @return std::string - The location code
216      */
locationCode() const217     std::string locationCode() const
218     {
219         std::string lc;
220         if (!_locationCode.empty())
221         {
222             // NULL terminated
223             lc = static_cast<const char*>(_locationCode.data());
224         }
225         return lc;
226     }
227 
228     /**
229      * @brief Returns the location code size
230      *
231      * @return size_t - The size, including the terminating null.
232      */
locationCodeSize() const233     size_t locationCodeSize() const
234     {
235         return _locationCodeSize;
236     }
237 
238     /**
239      * @brief Returns the FRU identity substructure
240      *
241      * @return const std::unique_ptr<FRUIdentity>&
242      */
fruIdentity() const243     const std::unique_ptr<FRUIdentity>& fruIdentity() const
244     {
245         return _fruIdentity;
246     }
247 
248     /**
249      * @brief Returns the PCE identity substructure
250      *
251      * @return const std::unique_ptr<PCEIdentity>&
252      */
pceIdentity() const253     const std::unique_ptr<PCEIdentity>& pceIdentity() const
254     {
255         return _pceIdentity;
256     }
257 
258     /**
259      * @brief Returns the MRU identity substructure
260      *
261      * @return const std::unique_ptr<MRU>&
262      */
mru() const263     const std::unique_ptr<MRU>& mru() const
264     {
265         return _mru;
266     }
267 
268     /**
269      * @brief Operator == used for finding duplicate callouts
270      *
271      * Checks if the location codes then maintenance procedure
272      * value, then symbolic FRU value match.
273      *
274      * @param[in] right - The callout to compare to
275      * @return bool - true if they are the same
276      */
277     bool operator==(const Callout& right) const;
278 
279     /**
280      * @brief Operator > used for sorting callouts by priority
281      *
282      * @param[in] right - The callout to compare to
283      * @return bool - true if callout has higher priority than other
284      */
285     bool operator>(const Callout& right) const;
286 
287   private:
288     /**
289      * @brief Sets the location code field
290      *
291      * @param[in] locationCode - The location code string
292      */
293     void setLocationCode(const std::string& locationCode);
294 
295     /**
296      * @brief The size of this structure in the PEL
297      */
298     uint8_t _size;
299 
300     /**
301      * @brief The flags byte of this structure
302      */
303     uint8_t _flags;
304 
305     /**
306      * @brief The replacement priority
307      */
308     uint8_t _priority;
309 
310     /**
311      * @brief The length of the location code field.
312      *
313      * Includes the NULL termination, and must be a
314      * multiple of 4 (padded with zeros)
315      */
316     uint8_t _locationCodeSize = 0;
317 
318     /**
319      * @brief NULL terminated location code
320      *
321      * Includes the NULL termination, and must be a
322      * multiple of 4 (padded with zeros)
323      */
324     std::vector<char> _locationCode;
325 
326     /**
327      * @brief FRU (Field Replaceable Unit) Identity substructure
328      */
329     std::unique_ptr<FRUIdentity> _fruIdentity;
330 
331     /**
332      * @brief PCE (Power Controlling Enclosure) Identity substructure
333      */
334     std::unique_ptr<PCEIdentity> _pceIdentity;
335 
336     /**
337      * @brief MRU (Manufacturing Replaceable Unit) substructure
338      */
339     std::unique_ptr<MRU> _mru;
340 };
341 
342 } // namespace src
343 } // namespace pels
344 } // namespace openpower
345