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