blob: c8bb0a312278060c31a55303072d8292bbd15463 [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
87 * out maintenance procedure.
88 *
89 * @param[in] priority - The priority of the callout
90 * @param[in] procedure - The maintenance procedure
91 */
92 Callout(CalloutPriority priority, MaintProcedure procedure);
93
94 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -050095 * @brief Returns the size of this object when flattened into a PEL
96 *
97 * @return size_t - The size of the section
98 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -050099 size_t flattenedSize() const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500100
101 /**
102 * @brief Flatten the object into the stream
103 *
104 * @param[in] stream - The stream to write to
105 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600106 void flatten(Stream& pel) const;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500107
108 /**
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800109 * @brief Returns the flags field of a callout
110 *
111 * @return uint8_t - The flags
112 */
113 uint8_t flags() const
114 {
115 return _flags;
116 }
117
118 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500119 * @brief Returns the priority field of a callout
120 *
121 * @return uint8_t - The priority
122 */
123 uint8_t priority() const
124 {
125 return _priority;
126 }
127
128 /**
129 * @brief Returns the location code of the callout
130 *
131 * @return std::string - The location code
132 */
133 std::string locationCode() const
134 {
135 std::string lc;
136 if (!_locationCode.empty())
137 {
138 // NULL terminated
139 lc = static_cast<const char*>(_locationCode.data());
140 }
141 return lc;
142 }
143
144 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500145 * @brief Returns the location code size
146 *
147 * @return size_t - The size, including the terminating null.
148 */
149 size_t locationCodeSize() const
150 {
151 return _locationCodeSize;
152 }
153
154 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500155 * @brief Returns the FRU identity substructure
156 *
157 * @return const std::unique_ptr<FRUIdentity>&
158 */
159 const std::unique_ptr<FRUIdentity>& fruIdentity() const
160 {
161 return _fruIdentity;
162 }
163
164 /**
165 * @brief Returns the PCE identity substructure
166 *
167 * @return const std::unique_ptr<PCEIdentity>&
168 */
169 const std::unique_ptr<PCEIdentity>& pceIdentity() const
170 {
171 return _pceIdentity;
172 }
173
174 /**
175 * @brief Returns the MRU identity substructure
176 *
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500177 * @return const std::unique_ptr<MRU>&
Matt Spinler6c9662c2019-10-09 11:27:20 -0500178 */
179 const std::unique_ptr<MRU>& mru() const
180 {
181 return _mru;
182 }
183
184 private:
185 /**
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500186 * @brief Sets the location code field
187 *
188 * @param[in] locationCode - The location code string
189 */
190 void setLocationCode(const std::string& locationCode);
191
192 /**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500193 * @brief The size of this structure in the PEL
194 */
195 uint8_t _size;
196
197 /**
198 * @brief The flags byte of this structure
199 */
200 uint8_t _flags;
201
202 /**
203 * @brief The replacement priority
204 */
205 uint8_t _priority;
206
207 /**
208 * @brief The length of the location code field.
209 *
210 * Includes the NULL termination, and must be a
211 * multiple of 4 (padded with zeros)
212 */
Matt Spinler0a5d10c2020-03-13 12:54:02 -0500213 uint8_t _locationCodeSize = 0;
Matt Spinler6c9662c2019-10-09 11:27:20 -0500214
215 /**
216 * @brief NULL terminated location code
217 *
218 * Includes the NULL termination, and must be a
219 * multiple of 4 (padded with zeros)
220 */
221 std::vector<char> _locationCode;
222
223 /**
224 * @brief FRU (Field Replaceable Unit) Identity substructure
225 */
226 std::unique_ptr<FRUIdentity> _fruIdentity;
227
228 /**
229 * @brief PCE (Power Controlling Enclosure) Identity substructure
230 */
231 std::unique_ptr<PCEIdentity> _pceIdentity;
232
233 /**
234 * @brief MRU (Manufacturing Replaceable Unit) substructure
235 */
236 std::unique_ptr<MRU> _mru;
237};
238
239} // namespace src
240} // namespace pels
241} // namespace openpower