xref: /openbmc/phosphor-logging/extensions/openpower-pels/device_callouts.hpp (revision 18c42b0f7ff2e570a795e291452383ded7eab3aa)
1*18c42b0fSMatt Spinler #pragma once
2*18c42b0fSMatt Spinler 
3*18c42b0fSMatt Spinler #include "pel_types.hpp"
4*18c42b0fSMatt Spinler 
5*18c42b0fSMatt Spinler #include <filesystem>
6*18c42b0fSMatt Spinler #include <nlohmann/json.hpp>
7*18c42b0fSMatt Spinler #include <string>
8*18c42b0fSMatt Spinler #include <tuple>
9*18c42b0fSMatt Spinler #include <vector>
10*18c42b0fSMatt Spinler 
11*18c42b0fSMatt Spinler /**
12*18c42b0fSMatt Spinler  * @file device_callouts.hpp
13*18c42b0fSMatt Spinler  *
14*18c42b0fSMatt Spinler  * @brief Looks up FRU callouts, which are D-Bus inventory paths,
15*18c42b0fSMatt Spinler  * in JSON for device sysfs paths.
16*18c42b0fSMatt Spinler  *
17*18c42b0fSMatt Spinler  * The code will extract the search keys from the sysfs path to
18*18c42b0fSMatt Spinler  * use to look up the callout list in the JSON.  The callouts will
19*18c42b0fSMatt Spinler  * be sorted by priority as defined in th PEL spec.
20*18c42b0fSMatt Spinler  *
21*18c42b0fSMatt Spinler  * The JSON is normally generated from the MRW, and contains
22*18c42b0fSMatt Spinler  * sections for the following types of callouts:
23*18c42b0fSMatt Spinler  *   * I2C  (also based on bus/addr as well as the path)
24*18c42b0fSMatt Spinler  *   * FSI
25*18c42b0fSMatt Spinler  *   * FSI-I2C
26*18c42b0fSMatt Spinler  *   * FSI-SPI
27*18c42b0fSMatt Spinler  *
28*18c42b0fSMatt Spinler  * The JSON looks like:
29*18c42b0fSMatt Spinler  *
30*18c42b0fSMatt Spinler  * "I2C":
31*18c42b0fSMatt Spinler  *   "<bus>":
32*18c42b0fSMatt Spinler  *     "<address>":
33*18c42b0fSMatt Spinler  *       "Callouts": [
34*18c42b0fSMatt Spinler  *          {
35*18c42b0fSMatt Spinler  *             "LocationCode": "<location code>",
36*18c42b0fSMatt Spinler  *             "Name": "<inventory path>",
37*18c42b0fSMatt Spinler  *             "Priority": "<priority=H/M/L>",
38*18c42b0fSMatt Spinler  *             "MRU": "<optional MRU name>"
39*18c42b0fSMatt Spinler  *          },
40*18c42b0fSMatt Spinler  *          ...
41*18c42b0fSMatt Spinler  *       ],
42*18c42b0fSMatt Spinler  *       "Dest": "<destination MRW target>"
43*18c42b0fSMatt Spinler  *
44*18c42b0fSMatt Spinler  * "FSI":
45*18c42b0fSMatt Spinler  *   "<fsi link>":
46*18c42b0fSMatt Spinler  *     "Callouts": [
47*18c42b0fSMatt Spinler  *            ...
48*18c42b0fSMatt Spinler  *     ],
49*18c42b0fSMatt Spinler  *     "Dest": "<destination MRW target>"
50*18c42b0fSMatt Spinler  *
51*18c42b0fSMatt Spinler  * "FSI-I2C":
52*18c42b0fSMatt Spinler  *    "<fsi link>":
53*18c42b0fSMatt Spinler  *      "<bus>":
54*18c42b0fSMatt Spinler  *        "<address>":
55*18c42b0fSMatt Spinler  *            "Callouts": [
56*18c42b0fSMatt Spinler  *                   ...
57*18c42b0fSMatt Spinler  *             ],
58*18c42b0fSMatt Spinler  *            "Dest": "<destination MRW target>"
59*18c42b0fSMatt Spinler  *
60*18c42b0fSMatt Spinler  * "FSI-SPI":
61*18c42b0fSMatt Spinler  *    "<fsi link>":
62*18c42b0fSMatt Spinler  *      "<bus>":
63*18c42b0fSMatt Spinler  *         "Callouts": [
64*18c42b0fSMatt Spinler  *                ...
65*18c42b0fSMatt Spinler  *         ],
66*18c42b0fSMatt Spinler  *         "Dest": "<destination MRW target>"
67*18c42b0fSMatt Spinler  *
68*18c42b0fSMatt Spinler  */
69*18c42b0fSMatt Spinler 
70*18c42b0fSMatt Spinler namespace openpower::pels::device_callouts
71*18c42b0fSMatt Spinler {
72*18c42b0fSMatt Spinler 
73*18c42b0fSMatt Spinler /**
74*18c42b0fSMatt Spinler  * @brief Represents a callout in the device JSON.
75*18c42b0fSMatt Spinler  *
76*18c42b0fSMatt Spinler  * The debug field will only be filled in for the first
77*18c42b0fSMatt Spinler  * callout in the list of them and contains additional
78*18c42b0fSMatt Spinler  * information about what happened when looking up the
79*18c42b0fSMatt Spinler  * callouts that is meant to aid in debug.
80*18c42b0fSMatt Spinler  */
81*18c42b0fSMatt Spinler struct Callout
82*18c42b0fSMatt Spinler {
83*18c42b0fSMatt Spinler     std::string priority;
84*18c42b0fSMatt Spinler     std::string locationCode;
85*18c42b0fSMatt Spinler     std::string name;
86*18c42b0fSMatt Spinler     std::string mru;
87*18c42b0fSMatt Spinler     std::string debug;
88*18c42b0fSMatt Spinler };
89*18c42b0fSMatt Spinler 
90*18c42b0fSMatt Spinler /**
91*18c42b0fSMatt Spinler  * @brief Looks up the callouts in a JSON File to add to a PEL
92*18c42b0fSMatt Spinler  *        for when the path between the BMC and the device specified
93*18c42b0fSMatt Spinler  *        by the passed in device path needs to be called out.
94*18c42b0fSMatt Spinler  *
95*18c42b0fSMatt Spinler  * The path is the path used to access the device in sysfs.  It
96*18c42b0fSMatt Spinler  * can be either a directory path or a file path.
97*18c42b0fSMatt Spinler  *
98*18c42b0fSMatt Spinler  * @param[in] devPath - The device path
99*18c42b0fSMatt Spinler  * @param[in] compatibleList - The list of compatible names for this
100*18c42b0fSMatt Spinler  *                             system.
101*18c42b0fSMatt Spinler  * @return std::vector<Callout> - The list of callouts
102*18c42b0fSMatt Spinler  */
103*18c42b0fSMatt Spinler std::vector<Callout>
104*18c42b0fSMatt Spinler     getCallouts(const std::string& devPath,
105*18c42b0fSMatt Spinler                 const std::vector<std::string>& compatibleList);
106*18c42b0fSMatt Spinler 
107*18c42b0fSMatt Spinler /**
108*18c42b0fSMatt Spinler  * @brief Looks up the callouts to add to a PEL for when the path
109*18c42b0fSMatt Spinler  *        between the BMC and the device specified by the passed in
110*18c42b0fSMatt Spinler  *        I2C bus and address needs to be called out.
111*18c42b0fSMatt Spinler  *
112*18c42b0fSMatt Spinler  * @param[in] i2cBus - The I2C bus
113*18c42b0fSMatt Spinler  * @param[in] i2cAddress - The I2C address
114*18c42b0fSMatt Spinler  * @param[in] compatibleList - The list of compatible names for this
115*18c42b0fSMatt Spinler  *                             system.
116*18c42b0fSMatt Spinler  * @return std::vector<Callout> - The list of callouts
117*18c42b0fSMatt Spinler  */
118*18c42b0fSMatt Spinler std::vector<Callout>
119*18c42b0fSMatt Spinler     getI2CCallouts(size_t i2cBus, uint8_t i2cAddress,
120*18c42b0fSMatt Spinler                    const std::vector<std::string>& compatibleList);
121*18c42b0fSMatt Spinler 
122*18c42b0fSMatt Spinler namespace util
123*18c42b0fSMatt Spinler {
124*18c42b0fSMatt Spinler 
125*18c42b0fSMatt Spinler /**
126*18c42b0fSMatt Spinler  * @brief Returns the path to the JSON file to look up callouts in.
127*18c42b0fSMatt Spinler  *
128*18c42b0fSMatt Spinler  * @param[in] compatibleList - The list of compatible names for this
129*18c42b0fSMatt Spinler  *                             system.
130*18c42b0fSMatt Spinler  *
131*18c42b0fSMatt Spinler  * @return path - The path to the file.
132*18c42b0fSMatt Spinler  */
133*18c42b0fSMatt Spinler std::filesystem::path
134*18c42b0fSMatt Spinler     getJSONFilename(const std::vector<std::string>& compatibleList);
135*18c42b0fSMatt Spinler 
136*18c42b0fSMatt Spinler /**
137*18c42b0fSMatt Spinler  * @brief Looks up the callouts in the JSON using the I2C keys.
138*18c42b0fSMatt Spinler  *
139*18c42b0fSMatt Spinler  * @param[in] i2cBus - The I2C bus
140*18c42b0fSMatt Spinler  * @param[in] i2cAddress - The I2C address
141*18c42b0fSMatt Spinler  * @param[in] calloutJSON - The JSON containing the callouts
142*18c42b0fSMatt Spinler  *
143*18c42b0fSMatt Spinler  * @return std::vector<Callout> - The callouts
144*18c42b0fSMatt Spinler  */
145*18c42b0fSMatt Spinler std::vector<device_callouts::Callout>
146*18c42b0fSMatt Spinler     calloutI2C(size_t i2CBus, uint8_t i2cAddress,
147*18c42b0fSMatt Spinler                const nlohmann::json& calloutJSON);
148*18c42b0fSMatt Spinler } // namespace util
149*18c42b0fSMatt Spinler } // namespace openpower::pels::device_callouts
150