blob: 2f5027162f2fd11ab3366ebbd803fefe36198e63 [file] [log] [blame]
Matt Spinler6c9662c2019-10-09 11:27:20 -05001#pragma once
2
3#include "fru_identity.hpp"
4#include "mru.hpp"
5#include "pce_identity.hpp"
Matt Spinler0a5d10c2020-03-13 12:54:02 -05006#include "pel_types.hpp"
Matt Spinler6c9662c2019-10-09 11:27:20 -05007#include "stream.hpp"
8
Matt Spinler8a09b982025-05-09 14:09:10 -05009#include <memory>
10
Matt Spinler6c9662c2019-10-09 11:27:20 -050011namespace openpower
12{
13namespace pels
14{
15namespace 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 */
37class Callout
38{
39 public:
Matt Spinler0a5d10c2020-03-13 12:54:02 -050040 /**
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
Matt Spinler6c9662c2019-10-09 11:27:20 -050053 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 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -050070 * @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
Matt Spinler5ab39972020-08-13 13:02:28 -050089 * 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
Matt Spinlera86ec992020-04-09 12:42:07 -0500108 * out a maintenance procedure.
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500109 *
110 * @param[in] priority - The priority of the callout
Matt Spinler468aab52020-08-13 11:04:31 -0500111 * @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
Matt Spinlera27e2e52020-04-09 11:06:11 -0500124 * @param[in] procedureFromRegistry - The maintenance procedure name
125 * as defined in the message registry.
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500126 */
Matt Spinler468aab52020-08-13 11:04:31 -0500127 Callout(CalloutPriority priority,
128 const std::string& procedureFromRegistry) :
129 Callout(priority, procedureFromRegistry, CalloutValueType::registryName)
Patrick Williams2544b412022-10-04 08:41:06 -0500130 {}
Matt Spinler468aab52020-08-13 11:04:31 -0500131
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);
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500147
148 /**
Matt Spinlera86ec992020-04-09 12:42:07 -0500149 * @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 */
160 Callout(CalloutPriority priority,
161 const std::string& symbolicFRUFromRegistry,
Matt Spinler468aab52020-08-13 11:04:31 -0500162 const std::string& locationCode, bool trustedLocationCode) :
163 Callout(priority, symbolicFRUFromRegistry,
164 CalloutValueType::registryName, locationCode,
165 trustedLocationCode)
Patrick Williams2544b412022-10-04 08:41:06 -0500166 {}
Matt Spinlera86ec992020-04-09 12:42:07 -0500167
168 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500169 * @brief Returns the size of this object when flattened into a PEL
170 *
171 * @return size_t - The size of the section
172 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500173 size_t flattenedSize() const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500174
175 /**
176 * @brief Flatten the object into the stream
177 *
178 * @param[in] stream - The stream to write to
179 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600180 void flatten(Stream& pel) const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500181
182 /**
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800183 * @brief Returns the flags field of a callout
184 *
185 * @return uint8_t - The flags
186 */
187 uint8_t flags() const
188 {
189 return _flags;
190 }
191
192 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500193 * @brief Returns the priority field of a callout
194 *
195 * @return uint8_t - The priority
196 */
197 uint8_t priority() const
198 {
199 return _priority;
200 }
201
202 /**
Matt Spinler4efed0e2024-02-26 11:16:07 -0600203 * @brief Set the priority of the callout
204 *
205 * @param[in] priority - The priority value
206 */
207 void setPriority(uint8_t priority)
208 {
209 _priority = priority;
210 }
211
212 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500213 * @brief Returns the location code of the callout
214 *
215 * @return std::string - The location code
216 */
217 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 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500229 * @brief Returns the location code size
230 *
231 * @return size_t - The size, including the terminating null.
232 */
233 size_t locationCodeSize() const
234 {
235 return _locationCodeSize;
236 }
237
238 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500239 * @brief Returns the FRU identity substructure
240 *
241 * @return const std::unique_ptr<FRUIdentity>&
242 */
243 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 */
253 const std::unique_ptr<PCEIdentity>& pceIdentity() const
254 {
255 return _pceIdentity;
256 }
257
258 /**
259 * @brief Returns the MRU identity substructure
260 *
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500261 * @return const std::unique_ptr<MRU>&
Matt Spinler6c9662c2019-10-09 11:27:20 -0500262 */
263 const std::unique_ptr<MRU>& mru() const
264 {
265 return _mru;
266 }
267
Matt Spinler4efed0e2024-02-26 11:16:07 -0600268 /**
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
Matt Spinler6c9662c2019-10-09 11:27:20 -0500287 private:
288 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500289 * @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 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500296 * @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 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500316 uint8_t _locationCodeSize = 0;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500317
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