Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 1 | #include <assert.h> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 2 | #include <libpdbg.h> |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 3 | #include <unistd.h> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 4 | |
Zane Shelley | a9b4434 | 2021-08-08 17:15:52 -0500 | [diff] [blame] | 5 | #include <analyzer/ras-data/ras-data-parser.hpp> |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 6 | #include <analyzer/service_data.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 7 | #include <attn/attn_dump.hpp> |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 8 | #include <hei_main.hpp> |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 10 | #include <util/pdbg.hpp> |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 11 | #include <util/trace.hpp> |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 12 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 13 | #include <algorithm> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 14 | #include <fstream> |
| 15 | #include <iostream> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 16 | #include <map> |
| 17 | #include <string> |
| 18 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 19 | namespace analyzer |
| 20 | { |
| 21 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 22 | //------------------------------------------------------------------------------ |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 23 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 24 | // Forward references for externally defined functions. |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 25 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 26 | /** |
| 27 | * @brief Will get the list of active chip and initialize the isolator. |
| 28 | * @param o_chips The returned list of active chips. |
| 29 | */ |
Zane Shelley | 171a2e0 | 2020-11-13 13:56:13 -0600 | [diff] [blame] | 30 | void initializeIsolator(std::vector<libhei::Chip>& o_chips); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 31 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 32 | /** |
| 33 | * @brief Will create and submit a PEL using the given data. |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 34 | * @param i_isoData The data gathered during isolation (for FFDC). |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 35 | * @param i_servData Data regarding service actions gathered during analysis. |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 36 | * @return Tuple of BMC log id, platform log id |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 37 | */ |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 38 | std::tuple<uint32_t, uint32_t> createPel(const libhei::IsolationData& i_isoData, |
| 39 | const ServiceData& i_servData); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 40 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 41 | //------------------------------------------------------------------------------ |
| 42 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 43 | const char* __attn(libhei::AttentionType_t i_attnType) |
| 44 | { |
| 45 | const char* str = ""; |
| 46 | switch (i_attnType) |
| 47 | { |
| 48 | case libhei::ATTN_TYPE_CHECKSTOP: |
| 49 | str = "CHECKSTOP"; |
| 50 | break; |
| 51 | case libhei::ATTN_TYPE_UNIT_CS: |
| 52 | str = "UNIT_CS"; |
| 53 | break; |
| 54 | case libhei::ATTN_TYPE_RECOVERABLE: |
| 55 | str = "RECOVERABLE"; |
| 56 | break; |
| 57 | case libhei::ATTN_TYPE_SP_ATTN: |
| 58 | str = "SP_ATTN"; |
| 59 | break; |
| 60 | case libhei::ATTN_TYPE_HOST_ATTN: |
| 61 | str = "HOST_ATTN"; |
| 62 | break; |
| 63 | default: |
| 64 | trace::err("Unsupported attention type: %u", i_attnType); |
| 65 | assert(0); |
| 66 | } |
| 67 | return str; |
| 68 | } |
| 69 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 70 | //------------------------------------------------------------------------------ |
| 71 | |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 72 | bool __filterRootCause(const libhei::IsolationData& i_isoData, |
| 73 | libhei::Signature& o_signature) |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 74 | { |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 75 | // We'll need to make a copy of the list so that the original list is |
| 76 | // maintained for the log. |
| 77 | std::vector<libhei::Signature> sigList{i_isoData.getSignatureList()}; |
| 78 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 79 | // For debug, trace out the original list of signatures before filtering. |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 80 | for (const auto& sig : sigList) |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 81 | { |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 82 | trace::inf("Signature: %s 0x%0" PRIx32 " %s", |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 83 | util::pdbg::getPath(sig.getChip()), sig.toUint32(), |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 84 | __attn(sig.getAttnType())); |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 85 | } |
| 86 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 87 | // Special and host attentions are not supported by this user application. |
| 88 | auto newEndItr = |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 89 | std::remove_if(sigList.begin(), sigList.end(), [&](const auto& t) { |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 90 | return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() || |
| 91 | libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType()); |
| 92 | }); |
| 93 | |
| 94 | // Shrink the vector, if needed. |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 95 | sigList.resize(std::distance(sigList.begin(), newEndItr)); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 96 | |
| 97 | // START WORKAROUND |
| 98 | // TODO: Filtering should be determined by the RAS Data Files provided by |
| 99 | // the host firmware via the PNOR (similar to the Chip Data Files). |
| 100 | // Until that support is available, use a rudimentary filter that |
| 101 | // first looks for any recoverable attention, then any unit checkstop, |
| 102 | // and then any system checkstop. This is built on the premise that |
| 103 | // recoverable errors could be the root cause of an system checkstop |
| 104 | // attentions. Fortunately, we just need to sort the list by the |
| 105 | // greater attention type value. |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 106 | std::sort(sigList.begin(), sigList.end(), |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 107 | [&](const auto& a, const auto& b) { |
| 108 | return a.getAttnType() > b.getAttnType(); |
| 109 | }); |
| 110 | // END WORKAROUND |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 111 | |
| 112 | // Check if a root cause attention was found. |
| 113 | if (!sigList.empty()) |
| 114 | { |
| 115 | // The entry at the front of the list will be the root cause. |
| 116 | o_signature = sigList.front(); |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | return false; // default, no active attentions found. |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | //------------------------------------------------------------------------------ |
| 124 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 125 | bool analyzeHardware(attn::DumpParameters& o_dumpParameters) |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 126 | { |
| 127 | bool attnFound = false; |
| 128 | |
Zane Shelley | e5411f0 | 2021-08-04 22:41:35 -0500 | [diff] [blame] | 129 | if (!util::pdbg::queryHardwareAnalysisSupported()) |
| 130 | { |
| 131 | trace::err("Hardware error analysis is not supported on this system"); |
| 132 | return attnFound; |
| 133 | } |
| 134 | |
| 135 | trace::inf(">>> enter analyzeHardware()"); |
| 136 | |
| 137 | // Initialize the isolator and get all of the chips to be analyzed. |
| 138 | trace::inf("Initializing the isolator..."); |
| 139 | std::vector<libhei::Chip> chips; |
| 140 | initializeIsolator(chips); |
| 141 | |
| 142 | // Isolate attentions. |
| 143 | trace::inf("Isolating errors: # of chips=%u", chips.size()); |
| 144 | libhei::IsolationData isoData{}; |
| 145 | libhei::isolate(chips, isoData); |
| 146 | |
| 147 | // Filter for root cause attention. |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 148 | libhei::Signature rootCause{}; |
Zane Shelley | e5411f0 | 2021-08-04 22:41:35 -0500 | [diff] [blame] | 149 | attnFound = __filterRootCause(isoData, rootCause); |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 150 | |
| 151 | if (!attnFound) |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 152 | { |
Zane Shelley | e5411f0 | 2021-08-04 22:41:35 -0500 | [diff] [blame] | 153 | // It is possible for TI handling, or manually initiated analysis via |
| 154 | // the command line, that there will not be an active attention. In |
| 155 | // which case, we will do nothing and let the caller of this function |
| 156 | // determine if this is the expected behavior. |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 157 | trace::inf("No active attentions found"); |
| 158 | } |
| 159 | else |
| 160 | { |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 161 | trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s", |
Zane Shelley | cb45738 | 2020-11-02 20:55:06 -0600 | [diff] [blame] | 162 | util::pdbg::getPath(rootCause.getChip()), |
| 163 | rootCause.toUint32(), __attn(rootCause.getAttnType())); |
| 164 | |
Zane Shelley | 9513582 | 2021-08-23 09:00:05 -0500 | [diff] [blame] | 165 | // Resolve any service actions required by the root cause. |
Zane Shelley | a9b4434 | 2021-08-08 17:15:52 -0500 | [diff] [blame] | 166 | RasDataParser rasData{}; |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 167 | ServiceData servData{rootCause, isoData.queryCheckstop()}; |
Zane Shelley | a9b4434 | 2021-08-08 17:15:52 -0500 | [diff] [blame] | 168 | rasData.getResolution(rootCause)->resolve(servData); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 169 | |
| 170 | // Create and commit a PEL. |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 171 | uint32_t logId = std::get<1>(createPel(isoData, servData)); |
| 172 | |
Zane Shelley | 9513582 | 2021-08-23 09:00:05 -0500 | [diff] [blame] | 173 | // Write guard records to persistent storage. |
| 174 | // TODO: The PEL ID will be required, but interface is still unknown. |
| 175 | for (const auto& guard : servData.getGuardList()) |
| 176 | { |
| 177 | guard.apply(); |
| 178 | } |
| 179 | |
| 180 | // Gather/return information needed for dump. |
| 181 | // TODO: Need ID from root cause. At the moment, HUID does not exist in |
| 182 | // devtree. Will need a better ID definition. |
| 183 | // TODO: HW dump is default, but some attentions may require something |
| 184 | // different. Will need to investigate adding that information to |
| 185 | // the RAS data files. |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 186 | o_dumpParameters.logId = logId; |
| 187 | o_dumpParameters.unitId = 0; |
| 188 | o_dumpParameters.dumpType = attn::DumpType::Hardware; |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Zane Shelley | e5411f0 | 2021-08-04 22:41:35 -0500 | [diff] [blame] | 191 | // All done, clean up the isolator. |
| 192 | trace::inf("Uninitializing isolator..."); |
| 193 | libhei::uninitialize(); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 194 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 195 | trace::inf("<<< exit analyzeHardware()"); |
| 196 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 197 | return attnFound; |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 198 | } |
| 199 | |
Ben Tyner | eea4542 | 2021-04-15 10:54:14 -0500 | [diff] [blame] | 200 | //------------------------------------------------------------------------------ |
| 201 | |
| 202 | /** |
| 203 | * @brief Get error isolator build information |
| 204 | * |
| 205 | * @return Pointer to build information |
| 206 | */ |
| 207 | const char* getBuildInfo() |
| 208 | { |
| 209 | return libhei::getBuildInfo(); |
| 210 | } |
| 211 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 212 | } // namespace analyzer |