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