Zane Shelley | 979e287 | 2021-09-20 22:46:06 -0500 | [diff] [blame] | 1 | #include <analyzer/service_data.hpp> |
| 2 | |
| 3 | namespace analyzer |
| 4 | { |
| 5 | |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 6 | //------------------------------------------------------------------------------ |
| 7 | |
| 8 | void ServiceData::calloutTarget(pdbg_target* i_target, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 9 | callout::Priority i_priority, bool i_guard) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 10 | { |
| 11 | // Add the target to the callout list. |
| 12 | addTargetCallout(i_target, i_priority, i_guard); |
| 13 | |
| 14 | // Add the callout FFDC. |
| 15 | nlohmann::json ffdc; |
| 16 | ffdc["Callout Type"] = "Hardware Callout"; |
| 17 | ffdc["Target"] = util::pdbg::getPhysDevPath(i_target); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 18 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 19 | ffdc["Guard"] = i_guard; |
| 20 | addCalloutFFDC(ffdc); |
| 21 | } |
| 22 | |
| 23 | //------------------------------------------------------------------------------ |
| 24 | |
| 25 | void ServiceData::calloutConnected(pdbg_target* i_rxTarget, |
| 26 | const callout::BusType& i_busType, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 27 | callout::Priority i_priority, bool i_guard) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 28 | { |
| 29 | // Get the endpoint target for the transfer side of the bus. |
| 30 | auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType); |
| 31 | |
| 32 | // Callout the TX endpoint. |
| 33 | addTargetCallout(txTarget, i_priority, i_guard); |
| 34 | |
| 35 | // Add the callout FFDC. |
| 36 | nlohmann::json ffdc; |
| 37 | ffdc["Callout Type"] = "Connected Callout"; |
| 38 | ffdc["Bus Type"] = i_busType.getString(); |
| 39 | ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget); |
| 40 | ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 41 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 42 | ffdc["Guard"] = i_guard; |
| 43 | addCalloutFFDC(ffdc); |
| 44 | } |
| 45 | |
| 46 | //------------------------------------------------------------------------------ |
| 47 | |
| 48 | void ServiceData::calloutBus(pdbg_target* i_rxTarget, |
| 49 | const callout::BusType& i_busType, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 50 | callout::Priority i_priority, bool i_guard) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 51 | { |
| 52 | // Get the endpoint target for the transfer side of the bus. |
| 53 | auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType); |
| 54 | |
| 55 | // Callout the RX endpoint. |
| 56 | addTargetCallout(i_rxTarget, i_priority, i_guard); |
| 57 | |
| 58 | // Callout the TX endpoint. |
| 59 | addTargetCallout(txTarget, i_priority, i_guard); |
| 60 | |
| 61 | // Callout everything else in between. |
| 62 | // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane. |
| 63 | addBackplaneCallout(i_priority); |
| 64 | |
| 65 | // Add the callout FFDC. |
| 66 | nlohmann::json ffdc; |
| 67 | ffdc["Callout Type"] = "Bus Callout"; |
| 68 | ffdc["Bus Type"] = i_busType.getString(); |
| 69 | ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget); |
| 70 | ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 71 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 72 | ffdc["Guard"] = i_guard; |
| 73 | addCalloutFFDC(ffdc); |
| 74 | } |
| 75 | |
| 76 | //------------------------------------------------------------------------------ |
| 77 | |
| 78 | void ServiceData::calloutClock(const callout::ClockType& i_clockType, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 79 | callout::Priority i_priority, bool) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 80 | { |
| 81 | // Callout the clock target. |
| 82 | // TODO: For P10, the callout is simply the backplane. Also, there are no |
| 83 | // clock targets in the device tree. So at the moment there is no |
| 84 | // guard support for clock targets. |
| 85 | addBackplaneCallout(i_priority); |
| 86 | |
| 87 | // Add the callout FFDC. |
| 88 | // TODO: Add the target and guard type if guard is ever supported. |
| 89 | nlohmann::json ffdc; |
| 90 | ffdc["Callout Type"] = "Clock Callout"; |
| 91 | ffdc["Clock Type"] = i_clockType.getString(); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 92 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 93 | addCalloutFFDC(ffdc); |
| 94 | } |
| 95 | |
| 96 | //------------------------------------------------------------------------------ |
| 97 | |
| 98 | void ServiceData::calloutProcedure(const callout::Procedure& i_procedure, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 99 | callout::Priority i_priority) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 100 | { |
| 101 | // Add the actual callout to the service data. |
| 102 | nlohmann::json callout; |
| 103 | callout["Procedure"] = i_procedure.getString(); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 104 | callout["Priority"] = callout::getString(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 105 | addCallout(callout); |
| 106 | |
| 107 | // Add the callout FFDC. |
| 108 | nlohmann::json ffdc; |
| 109 | ffdc["Callout Type"] = "Procedure Callout"; |
| 110 | ffdc["Procedure"] = i_procedure.getString(); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 111 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 112 | addCalloutFFDC(ffdc); |
| 113 | } |
| 114 | |
| 115 | //------------------------------------------------------------------------------ |
| 116 | |
Zane Shelley | a413477 | 2022-01-10 17:22:44 -0600 | [diff] [blame] | 117 | void ServiceData::calloutPart(const callout::PartType& i_part, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 118 | callout::Priority i_priority) |
Zane Shelley | a413477 | 2022-01-10 17:22:44 -0600 | [diff] [blame] | 119 | { |
| 120 | if (callout::PartType::PNOR == i_part) |
| 121 | { |
| 122 | // The PNOR is on the BMC card. |
| 123 | // TODO: Will need to be modified if we ever support systems with more |
| 124 | // than one BMC. |
| 125 | addTargetCallout(util::pdbg::getTrgt("/bmc0"), i_priority, false); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | throw std::logic_error("Unsupported part type: " + i_part.getString()); |
| 130 | } |
| 131 | |
| 132 | // Add the callout FFDC. |
| 133 | nlohmann::json ffdc; |
| 134 | ffdc["Callout Type"] = "Part Callout"; |
| 135 | ffdc["Part Type"] = i_part.getString(); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 136 | ffdc["Priority"] = callout::getStringFFDC(i_priority); |
Zane Shelley | a413477 | 2022-01-10 17:22:44 -0600 | [diff] [blame] | 137 | addCalloutFFDC(ffdc); |
| 138 | } |
| 139 | |
| 140 | //------------------------------------------------------------------------------ |
| 141 | |
Zane Shelley | 979e287 | 2021-09-20 22:46:06 -0500 | [diff] [blame] | 142 | void ServiceData::addCallout(const nlohmann::json& i_callout) |
| 143 | { |
| 144 | // The new callout is either a hardware callout with a location code or a |
| 145 | // procedure callout. |
| 146 | |
| 147 | std::string type{}; |
| 148 | if (i_callout.contains("LocationCode")) |
| 149 | { |
| 150 | type = "LocationCode"; |
| 151 | } |
| 152 | else if (i_callout.contains("Procedure")) |
| 153 | { |
| 154 | type = "Procedure"; |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | throw std::logic_error("Unsupported callout: " + i_callout.dump()); |
| 159 | } |
| 160 | |
| 161 | // A map to determine the priority order. All of the medium priorities, |
| 162 | // including the medium group priorities, are all the same level. |
| 163 | static const std::map<std::string, unsigned int> m = { |
| 164 | {"H", 3}, {"M", 2}, {"A", 2}, {"B", 2}, {"C", 2}, {"L", 1}, |
| 165 | }; |
| 166 | |
| 167 | bool addCallout = true; |
| 168 | |
| 169 | for (auto& c : iv_calloutList) |
| 170 | { |
| 171 | if (c.contains(type) && (c.at(type) == i_callout.at(type))) |
| 172 | { |
| 173 | // The new callout already exists. Don't add a new callout. |
| 174 | addCallout = false; |
| 175 | |
| 176 | if (m.at(c.at("Priority")) < m.at(i_callout.at("Priority"))) |
| 177 | { |
| 178 | // The new callout has a higher priority, update it. |
| 179 | c["Priority"] = i_callout.at("Priority"); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (addCallout) |
| 185 | { |
| 186 | iv_calloutList.push_back(i_callout); |
| 187 | } |
| 188 | } |
| 189 | |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 190 | //------------------------------------------------------------------------------ |
| 191 | |
| 192 | void ServiceData::addTargetCallout(pdbg_target* i_target, |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 193 | callout::Priority i_priority, bool i_guard) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 194 | { |
| 195 | nlohmann::json callout; |
| 196 | |
| 197 | callout["LocationCode"] = util::pdbg::getLocationCode(i_target); |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 198 | callout["Priority"] = callout::getString(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 199 | callout["Deconfigured"] = false; |
| 200 | callout["Guarded"] = false; // default |
| 201 | |
| 202 | // Check if guard info should be added. |
| 203 | if (i_guard) |
| 204 | { |
| 205 | auto guardType = queryGuardPolicy(); |
| 206 | |
| 207 | if (!(callout::GuardType::NONE == guardType)) |
| 208 | { |
| 209 | callout["Guarded"] = true; |
| 210 | callout["EntityPath"] = util::pdbg::getPhysBinPath(i_target); |
| 211 | callout["GuardType"] = guardType.getString(); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | addCallout(callout); |
| 216 | } |
| 217 | |
| 218 | //------------------------------------------------------------------------------ |
| 219 | |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 220 | void ServiceData::addBackplaneCallout(callout::Priority i_priority) |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 221 | { |
| 222 | // TODO: There isn't a device tree object for this. So will need to hardcode |
| 223 | // the location code for now. In the future, we will need a mechanism |
| 224 | // to make this data driven. |
| 225 | |
| 226 | nlohmann::json callout; |
| 227 | |
| 228 | callout["LocationCode"] = "P0"; |
Zane Shelley | 9980d48 | 2022-01-28 15:21:47 -0600 | [diff] [blame] | 229 | callout["Priority"] = callout::getString(i_priority); |
Zane Shelley | 37acb28 | 2022-01-10 16:05:22 -0600 | [diff] [blame] | 230 | callout["Deconfigured"] = false; |
| 231 | callout["Guarded"] = false; |
| 232 | |
| 233 | addCallout(callout); |
| 234 | } |
| 235 | |
| 236 | //------------------------------------------------------------------------------ |
| 237 | |
Zane Shelley | 979e287 | 2021-09-20 22:46:06 -0500 | [diff] [blame] | 238 | } // namespace analyzer |