PEL: Let Callout object ctor take a MRU list
A list of MRUs (Manufacturing Replaceable Units) can now be passed into
the Callout object constructor. There is also a new MRU object
constructor that will build that object with a MRU list as well.
This will be used in the future when someone wants to add MRUs to a
callout.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic0e93e081a91ffc47dfd6642a34f02fd9a6edb8e
diff --git a/extensions/openpower-pels/callout.cpp b/extensions/openpower-pels/callout.cpp
index 4ddb897..f54d77e 100644
--- a/extensions/openpower-pels/callout.cpp
+++ b/extensions/openpower-pels/callout.cpp
@@ -80,7 +80,16 @@
Callout::Callout(CalloutPriority priority, const std::string& locationCode,
const std::string& partNumber, const std::string& ccin,
- const std::string& serialNumber)
+ const std::string& serialNumber) :
+ Callout(priority, locationCode, partNumber, ccin, serialNumber,
+ std::vector<MRU::MRUCallout>{})
+{
+}
+
+Callout::Callout(CalloutPriority priority, const std::string& locationCode,
+ const std::string& partNumber, const std::string& ccin,
+ const std::string& serialNumber,
+ const std::vector<MRU::MRUCallout>& mrus)
{
_flags = calloutType | fruIdentIncluded;
@@ -91,6 +100,12 @@
_fruIdentity =
std::make_unique<FRUIdentity>(partNumber, ccin, serialNumber);
+ if (!mrus.empty())
+ {
+ _flags |= mruIncluded;
+ _mru = std::make_unique<MRU>(mrus);
+ }
+
_size = flattenedSize();
}
diff --git a/extensions/openpower-pels/callout.hpp b/extensions/openpower-pels/callout.hpp
index 1bfe9c8..66dcde0 100644
--- a/extensions/openpower-pels/callout.hpp
+++ b/extensions/openpower-pels/callout.hpp
@@ -84,6 +84,25 @@
* @brief Constructor
*
* Creates the objects with a FRUIdentity substructure that calls
+ * out a normal hardware FRU, and takes a list of MRUs that will
+ * be added to the callout.
+ *
+ * @param[in] priority - The priority of the callout
+ * @param[in] locationCode - The location code of the callout
+ * @param[in] partNumber - The part number of the callout
+ * @param[in] ccin - The CCIN of the callout
+ * @param[in] serialNumber - The serial number of the callout
+ * @param[in] mrus - The MRUs, if any, to add to the callout
+ */
+ Callout(CalloutPriority priority, const std::string& locationCode,
+ const std::string& partNumber, const std::string& ccin,
+ const std::string& serialNumber,
+ const std::vector<MRU::MRUCallout>& mrus);
+
+ /**
+ * @brief Constructor
+ *
+ * Creates the objects with a FRUIdentity substructure that calls
* out a maintenance procedure.
*
* @param[in] priority - The priority of the callout
diff --git a/extensions/openpower-pels/mru.cpp b/extensions/openpower-pels/mru.cpp
index a79c026..1a9ce00 100644
--- a/extensions/openpower-pels/mru.cpp
+++ b/extensions/openpower-pels/mru.cpp
@@ -26,6 +26,9 @@
using namespace phosphor::logging;
+// The MRU substructure supports up to 15 MRUs.
+static constexpr size_t maxMRUs = 15;
+
MRU::MRU(Stream& pel)
{
pel >> _type >> _size >> _flags >> _reserved4B;
@@ -53,6 +56,27 @@
}
}
+MRU::MRU(const std::vector<MRUCallout>& mrus)
+{
+ if (mrus.empty())
+ {
+ log<level::ERR>("Trying to create a MRU section with no MRUs");
+ throw std::runtime_error{"Trying to create a MRU section with no MRUs"};
+ }
+
+ _mrus = mrus;
+ if (_mrus.size() > maxMRUs)
+ {
+ _mrus.resize(maxMRUs);
+ }
+
+ _type = substructureType;
+ _size = sizeof(_type) + sizeof(_size) + sizeof(_flags) +
+ sizeof(_reserved4B) + (sizeof(MRUCallout) * _mrus.size());
+ _flags = _mrus.size();
+ _reserved4B = 0;
+}
+
void MRU::flatten(Stream& pel) const
{
pel << _type << _size << _flags << _reserved4B;
diff --git a/extensions/openpower-pels/mru.hpp b/extensions/openpower-pels/mru.hpp
index e2293f1..db66e3b 100644
--- a/extensions/openpower-pels/mru.hpp
+++ b/extensions/openpower-pels/mru.hpp
@@ -57,6 +57,15 @@
explicit MRU(Stream& pel);
/**
+ * @brief Constructor
+ *
+ * Creates the object using the passed in MRUs
+ *
+ * @param[in] mrus - The MRUs
+ */
+ explicit MRU(const std::vector<MRUCallout>& mrus);
+
+ /**
* @brief Flatten the object into the stream
*
* @param[in] stream - The stream to write to
@@ -84,6 +93,26 @@
}
/**
+ * @brief Returns the size field
+ *
+ * @return size_t - The size of the MRU substructure
+ */
+ size_t size() const
+ {
+ return _size;
+ }
+
+ /**
+ * @brief Returns the flags field
+ *
+ * @return uint8_t - The flags
+ */
+ uint8_t flags() const
+ {
+ return _flags;
+ }
+
+ /**
* @brief The type identifier value of this structure.
*/
static const uint16_t substructureType = 0x4D52; // "MR"