Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | ba0ee00 | 2020-03-13 11:24:14 -0500 | [diff] [blame] | 3 | #include "pel_types.hpp" |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 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 | /** |
Matt Spinler | ba0ee00 | 2020-03-13 11:24:14 -0500 | [diff] [blame] | 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] procedure - The procedure to use |
| 93 | */ |
| 94 | FRUIdentity(MaintProcedure procedure); |
| 95 | |
| 96 | /** |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 97 | * @brief Flatten the object into the stream |
| 98 | * |
| 99 | * @param[in] stream - The stream to write to |
| 100 | */ |
Matt Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 101 | void flatten(Stream& pel) const; |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * @brief Returns the size of this structure when flattened into a PEL |
| 105 | * |
| 106 | * @return size_t - The size of the section |
| 107 | */ |
Matt Spinler | a09354b | 2020-03-13 10:24:52 -0500 | [diff] [blame] | 108 | size_t flattenedSize() const; |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 109 | |
| 110 | /** |
Matt Spinler | ba0ee00 | 2020-03-13 11:24:14 -0500 | [diff] [blame] | 111 | * @brief Returns the type field |
| 112 | * |
| 113 | * @return uint16_t - The type, always 0x4944 "ID". |
| 114 | */ |
| 115 | uint16_t type() const |
| 116 | { |
| 117 | return _type; |
| 118 | } |
| 119 | /** |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 120 | * @brief The failing component type for this FRU callout. |
| 121 | * |
| 122 | * @return FailingComponentType |
| 123 | */ |
| 124 | FailingComponentType failingComponentType() const |
| 125 | { |
| 126 | return static_cast<FailingComponentType>(_flags & 0xF0); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @brief Returns the part number, if supplied |
| 131 | * |
| 132 | * @return std::optional<std::string> |
| 133 | */ |
| 134 | std::optional<std::string> getPN() const; |
| 135 | |
| 136 | /** |
| 137 | * @brief Returns the maintenance procedure, if supplied |
| 138 | * |
| 139 | * @return std::optional<std::string> |
| 140 | */ |
| 141 | std::optional<std::string> getMaintProc() const; |
| 142 | |
| 143 | /** |
| 144 | * @brief Returns the CCIN, if supplied |
| 145 | * |
| 146 | * @return std::optional<std::string> |
| 147 | */ |
| 148 | std::optional<std::string> getCCIN() const; |
| 149 | |
| 150 | /** |
| 151 | * @brief Returns the serial number, if supplied |
| 152 | * |
| 153 | * @return std::optional<std::string> |
| 154 | */ |
| 155 | std::optional<std::string> getSN() const; |
| 156 | |
| 157 | /** |
| 158 | * @brief The type identifier value of this structure. |
| 159 | */ |
| 160 | static const uint16_t substructureType = 0x4944; // "ID" |
| 161 | |
| 162 | private: |
| 163 | /** |
| 164 | * @brief If the part number is contained in this structure. |
| 165 | * |
| 166 | * It takes the place of the maintenance procedure ID. |
| 167 | * |
| 168 | * @return bool |
| 169 | */ |
| 170 | bool hasPN() const |
| 171 | { |
| 172 | return _flags & pnSupplied; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @brief If the CCIN is contained in this structure. |
| 177 | * |
| 178 | * @return bool |
| 179 | */ |
| 180 | bool hasCCIN() const |
| 181 | { |
| 182 | return _flags & ccinSupplied; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @brief If a maintenance procedure is contained in this structure. |
| 187 | * |
| 188 | * It takes the place of the part number. |
| 189 | * |
| 190 | * @return bool |
| 191 | */ |
| 192 | bool hasMP() const |
| 193 | { |
| 194 | return _flags & maintProcSupplied; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @brief If the serial number is contained in this structure. |
| 199 | * |
| 200 | * @return bool |
| 201 | */ |
| 202 | bool hasSN() const |
| 203 | { |
| 204 | return _flags & snSupplied; |
| 205 | } |
| 206 | |
| 207 | /** |
Matt Spinler | ba0ee00 | 2020-03-13 11:24:14 -0500 | [diff] [blame] | 208 | * @brief Sets the 8 character null terminated part |
| 209 | * number field to the string passed in. |
| 210 | * |
| 211 | * @param[in] partNumber - The part number string. |
| 212 | */ |
| 213 | void setPartNumber(const std::string& partNumber); |
| 214 | |
| 215 | /** |
| 216 | * @brief Sets the 4 character CCIN field. |
| 217 | * |
| 218 | * @param[in] ccin - The CCIN string |
| 219 | */ |
| 220 | void setCCIN(const std::string& ccin); |
| 221 | |
| 222 | /** |
| 223 | * @brief Sets the 12 character serial number field. |
| 224 | * |
| 225 | * @param[in] serialNumber - The serial number string |
| 226 | */ |
| 227 | void setSerialNumber(const std::string& serialNumber); |
| 228 | |
| 229 | /** |
| 230 | * @brief Sets the 8 character null terminated procedure |
| 231 | * field. This is in the same field as the part |
| 232 | * number since they are mutually exclusive. |
| 233 | */ |
| 234 | void setMaintenanceProcedure(MaintProcedure procedure); |
| 235 | |
| 236 | /** |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 237 | * @brief The callout substructure type field. Will be "ID". |
| 238 | */ |
| 239 | uint16_t _type; |
| 240 | |
| 241 | /** |
| 242 | * @brief The size of this callout structure. |
| 243 | * |
| 244 | * Always a multiple of 4. |
| 245 | */ |
| 246 | uint8_t _size; |
| 247 | |
| 248 | /** |
| 249 | * @brief The flags byte of this substructure. |
| 250 | * |
| 251 | * See the FailingComponentType and Flags enums |
| 252 | */ |
| 253 | uint8_t _flags; |
| 254 | |
| 255 | /** |
| 256 | * @brief The part number OR maintenance procedure ID, |
| 257 | * depending on what the flags field specifies. |
| 258 | * |
| 259 | * A NULL terminated ASCII string. |
| 260 | */ |
| 261 | std::array<char, 8> _pnOrProcedureID; |
| 262 | |
| 263 | /** |
| 264 | * @brief The CCIN VPD keyword |
| 265 | * |
| 266 | * Four ASCII characters, not NULL terminated. |
| 267 | */ |
| 268 | std::array<char, 4> _ccin; |
| 269 | |
| 270 | /** |
| 271 | * @brief The serial number |
| 272 | * |
| 273 | * Twelve ASCII characters, not NULL terminated. |
| 274 | */ |
| 275 | std::array<char, 12> _sn; |
| 276 | }; |
| 277 | |
| 278 | } // namespace src |
| 279 | } // namespace pels |
| 280 | } // namespace openpower |