xref: /openbmc/openpower-vpd-parser/vpd-manager/include/single_fab.hpp (revision c4fa618189bc05dde54b59d490bf9e83c2513c20)
1 #pragma once
2 
3 #include "constants.hpp"
4 #include "event_logger.hpp"
5 
6 #include <string>
7 
8 namespace vpd
9 {
10 /**
11  * @brief class to implement single fab feature.
12  *
13  * The class hosts functionalities required to support single FAB feature.
14  *
15  */
16 class SingleFab
17 {
18   public:
19     /**
20      * @brief API to support single FAB feature.
21      *
22      * This API updates the IM value to the P11 series or creates PEL in invalid
23      * case based on the IM value read from the cache and planar, considering
24      * the system mode and image.
25      *
26      * System mode can be of field mode or lab mode and system image can be
27      * special or normal image.
28      *
29      * @return 0 on success, -1 in case of failure.
30      */
31     int singleFabImOverride() const noexcept;
32 
33   private:
34     /**
35      * @brief API to get IM value from persisted location.
36      *
37      * @return IM value on success, empty string otherwise.
38      */
39     std::string getImFromPersistedLocation() const noexcept;
40 
41     /**
42      * @brief API to get IM value from system planar EEPROM path.
43      *
44      * @return IM value on success, empty string otherwise.
45      */
46     std::string getImFromPlanar() const noexcept;
47 
48     /**
49      * @brief API to update IM value on system planar EEPROM path.
50      *
51      * @param[in] i_imValue - IM value to be updated.
52      *
53      * @return true if value updated successfully, otherwise false.
54      */
55     bool setImOnPlanar(const std::string& i_imValue) const noexcept;
56 
57     /**
58      * @brief API to update IM value on system planar EEPROM path to P11 series.
59      *
60      * @param[in] i_currentImValuePlanar - current IM value in planar EEPROM.
61      */
62     void updateSystemImValueInVpdToP11Series(
63         std::string i_currentImValuePlanar) const noexcept;
64 
65     /**
66      * @brief API to check if it is a P10 system.
67      *
68      * @param[in] i_imValue - IM value of the system.
69      *
70      * @return true, if P10 system. Otherwise false.
71      */
isP10System(const std::string & i_imValue) const72     inline bool isP10System(const std::string& i_imValue) const noexcept
73     {
74         try
75         {
76             return !(i_imValue.compare(constants::VALUE_0, constants::VALUE_4,
77                                        POWER10_IM_SERIES));
78         }
79         catch (const std::exception& l_ex)
80         {
81             EventLogger::createSyncPel(
82                 types::ErrorType::InternalFailure,
83                 types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
84                 std::string(
85                     "Failed to check if system is of P10 series. Error : ") +
86                     l_ex.what(),
87                 std::nullopt, std::nullopt, std::nullopt, std::nullopt);
88             return false;
89         }
90     }
91 
92     /**
93      * @brief API to check if it is a P11 system.
94      *
95      * @param[in] i_imValue - IM value of the system.
96      *
97      * @return true, if P11 system. Otherwise false.
98      */
isP11System(const std::string & i_imValue) const99     inline bool isP11System(const std::string& i_imValue) const noexcept
100     {
101         try
102         {
103             return !(i_imValue.compare(constants::VALUE_0, constants::VALUE_4,
104                                        POWER11_IM_SERIES));
105         }
106         catch (const std::exception& l_ex)
107         {
108             EventLogger::createSyncPel(
109                 types::ErrorType::InternalFailure,
110                 types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
111                 std::string(
112                     "Failed to check if system is of P11 series. Error : ") +
113                     l_ex.what(),
114                 std::nullopt, std::nullopt, std::nullopt, std::nullopt);
115             return false;
116         }
117     }
118 
119     /**
120      * @brief API to check if it is a valid IM series.
121      *
122      * This API checks if the provided IM value is of either P10 or P11 series.
123      *
124      * @param[in] i_imValue - IM value of the system.
125      *
126      * @return true, if valid IM series. Otherwise false.
127      */
isValidImSeries(const std::string & l_imValue) const128     inline bool isValidImSeries(const std::string& l_imValue) const noexcept
129     {
130         return (isP10System(l_imValue) || isP11System(l_imValue));
131     }
132 
133     // valid IM series.
134     static constexpr auto POWER10_IM_SERIES = "5000";
135     static constexpr auto POWER11_IM_SERIES = "6000";
136 };
137 } // namespace vpd
138