blob: 1bfe9c815b23f629d7dfb0961cce41ee877a97d6 [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
9namespace openpower
10{
11namespace pels
12{
13namespace src
14{
15
16/**
17 * @class Callout
18 *
19 * Represents a single FRU callout in the SRC's FRU callout
20 * subsection.
21 *
22 * The 'Callouts' class holds a list of these objects.
23 *
24 * The callout priority and location code are in this structure.
25 *
26 * There can also be up to one each of three types of substructures
27 * in a single callout:
28 * * FRU Identity (must be first if present)
29 * * Power Controlling Enclosure (PCE)
30 * * Manufacturing Replaceable Unit (MRU)
31 *
32 * These substructures have their own objects managed by unique_ptrs
33 * which will only be allocated if those substructures exist.
34 */
35class Callout
36{
37 public:
Matt Spinler0a5d10c2020-03-13 12:54:02 -050038 /**
39 * @brief Which callout substructures are included.
40 */
41 enum calloutFlags
42 {
43 calloutType = 0b0010'0000,
44 fruIdentIncluded = 0b0000'1000,
45 mruIncluded = 0b0000'0100
46
47 // Leaving out the various PCE identity ones since
48 // we don't use them.
49 };
50
Matt Spinler6c9662c2019-10-09 11:27:20 -050051 Callout() = delete;
52 ~Callout() = default;
53 Callout(const Callout&) = delete;
54 Callout& operator=(const Callout&) = delete;
55 Callout(Callout&&) = delete;
56 Callout& operator=(Callout&&) = delete;
57
58 /**
59 * @brief Constructor
60 *
61 * Fills in this class's data fields from the stream.
62 *
63 * @param[in] pel - the PEL data stream
64 */
65 explicit Callout(Stream& pel);
66
67 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -050068 * @brief Constructor
69 *
70 * Creates the objects with a FRUIdentity substructure that calls
71 * out a normal hardware FRU.
72 *
73 * @param[in] priority - The priority of the callout
74 * @param[in] locationCode - The location code of the callout
75 * @param[in] partNumber - The part number of the callout
76 * @param[in] ccin - The CCIN of the callout
77 * @param[in] serialNumber - The serial number of the callout
78 */
79 Callout(CalloutPriority priority, const std::string& locationCode,
80 const std::string& partNumber, const std::string& ccin,
81 const std::string& serialNumber);
82
83 /**
84 * @brief Constructor
85 *
86 * Creates the objects with a FRUIdentity substructure that calls
Matt Spinlera86ec992020-04-09 12:42:07 -050087 * out a maintenance procedure.
Matt Spinler0a5d10c2020-03-13 12:54:02 -050088 *
89 * @param[in] priority - The priority of the callout
Matt Spinler468aab52020-08-13 11:04:31 -050090 * @param[in] procedure - The maintenance procedure name
91 * @param[in] type - If the procedure is the raw name or the registry name
92 */
93 Callout(CalloutPriority priority, const std::string& procedure,
94 CalloutValueType type);
95
96 /**
97 * @brief Constructor
98 *
99 * Creates the objects with a FRUIdentity substructure that calls
100 * out a maintenance procedure.
101 *
102 * @param[in] priority - The priority of the callout
Matt Spinlera27e2e52020-04-09 11:06:11 -0500103 * @param[in] procedureFromRegistry - The maintenance procedure name
104 * as defined in the message registry.
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500105 */
Matt Spinler468aab52020-08-13 11:04:31 -0500106 Callout(CalloutPriority priority,
107 const std::string& procedureFromRegistry) :
108 Callout(priority, procedureFromRegistry, CalloutValueType::registryName)
109 {
110 }
111
112 /**
113 * @brief Constructor
114 *
115 * Creates the objects with a FRUIdentity substructure that calls
116 * out a symbolic FRU.
117 *
118 * @param[in] priority - The priority of the callout
119 * @param[in] symbolicFRU - The symbolic FRU name
120 * @param[in] type - If the FRU is the raw name or the registry name
121 * @param[in] locationCode - The location code of the callout
122 * @param[in] trustedLocationCode - If the location is trusted
123 */
124 Callout(CalloutPriority priority, const std::string& symbolicFRU,
125 CalloutValueType type, const std::string& locationCode,
126 bool trustedLocationCode);
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500127
128 /**
Matt Spinlera86ec992020-04-09 12:42:07 -0500129 * @brief Constructor
130 *
131 * Creates the objects with a FRUIdentity substructure that calls
132 * out a symbolic FRU.
133 *
134 * @param[in] priority - The priority of the callout
135 * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as
136 * defined in the message registry.
137 * @param[in] locationCode - The location code of the callout
138 * @param[in] trustedLocationCode - If the location is trusted
139 */
140 Callout(CalloutPriority priority,
141 const std::string& symbolicFRUFromRegistry,
Matt Spinler468aab52020-08-13 11:04:31 -0500142 const std::string& locationCode, bool trustedLocationCode) :
143 Callout(priority, symbolicFRUFromRegistry,
144 CalloutValueType::registryName, locationCode,
145 trustedLocationCode)
146 {
147 }
Matt Spinlera86ec992020-04-09 12:42:07 -0500148
149 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500150 * @brief Returns the size of this object when flattened into a PEL
151 *
152 * @return size_t - The size of the section
153 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500154 size_t flattenedSize() const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500155
156 /**
157 * @brief Flatten the object into the stream
158 *
159 * @param[in] stream - The stream to write to
160 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600161 void flatten(Stream& pel) const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500162
163 /**
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800164 * @brief Returns the flags field of a callout
165 *
166 * @return uint8_t - The flags
167 */
168 uint8_t flags() const
169 {
170 return _flags;
171 }
172
173 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500174 * @brief Returns the priority field of a callout
175 *
176 * @return uint8_t - The priority
177 */
178 uint8_t priority() const
179 {
180 return _priority;
181 }
182
183 /**
184 * @brief Returns the location code of the callout
185 *
186 * @return std::string - The location code
187 */
188 std::string locationCode() const
189 {
190 std::string lc;
191 if (!_locationCode.empty())
192 {
193 // NULL terminated
194 lc = static_cast<const char*>(_locationCode.data());
195 }
196 return lc;
197 }
198
199 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500200 * @brief Returns the location code size
201 *
202 * @return size_t - The size, including the terminating null.
203 */
204 size_t locationCodeSize() const
205 {
206 return _locationCodeSize;
207 }
208
209 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500210 * @brief Returns the FRU identity substructure
211 *
212 * @return const std::unique_ptr<FRUIdentity>&
213 */
214 const std::unique_ptr<FRUIdentity>& fruIdentity() const
215 {
216 return _fruIdentity;
217 }
218
219 /**
220 * @brief Returns the PCE identity substructure
221 *
222 * @return const std::unique_ptr<PCEIdentity>&
223 */
224 const std::unique_ptr<PCEIdentity>& pceIdentity() const
225 {
226 return _pceIdentity;
227 }
228
229 /**
230 * @brief Returns the MRU identity substructure
231 *
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500232 * @return const std::unique_ptr<MRU>&
Matt Spinler6c9662c2019-10-09 11:27:20 -0500233 */
234 const std::unique_ptr<MRU>& mru() const
235 {
236 return _mru;
237 }
238
239 private:
240 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500241 * @brief Sets the location code field
242 *
243 * @param[in] locationCode - The location code string
244 */
245 void setLocationCode(const std::string& locationCode);
246
247 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500248 * @brief The size of this structure in the PEL
249 */
250 uint8_t _size;
251
252 /**
253 * @brief The flags byte of this structure
254 */
255 uint8_t _flags;
256
257 /**
258 * @brief The replacement priority
259 */
260 uint8_t _priority;
261
262 /**
263 * @brief The length of the location code field.
264 *
265 * Includes the NULL termination, and must be a
266 * multiple of 4 (padded with zeros)
267 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500268 uint8_t _locationCodeSize = 0;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500269
270 /**
271 * @brief NULL terminated location code
272 *
273 * Includes the NULL termination, and must be a
274 * multiple of 4 (padded with zeros)
275 */
276 std::vector<char> _locationCode;
277
278 /**
279 * @brief FRU (Field Replaceable Unit) Identity substructure
280 */
281 std::unique_ptr<FRUIdentity> _fruIdentity;
282
283 /**
284 * @brief PCE (Power Controlling Enclosure) Identity substructure
285 */
286 std::unique_ptr<PCEIdentity> _pceIdentity;
287
288 /**
289 * @brief MRU (Manufacturing Replaceable Unit) substructure
290 */
291 std::unique_ptr<MRU> _mru;
292};
293
294} // namespace src
295} // namespace pels
296} // namespace openpower