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