xref: /openbmc/openpower-proc-control/procedures/common/collect_sbe_hb_data.cpp (revision 915b38feb5e5793d7555f3060581077e266ba3d6)
1a5311abdSJayanth Othayoth /**
2a5311abdSJayanth Othayoth  * Copyright (C) 2017 IBM Corporation
3a5311abdSJayanth Othayoth  *
4a5311abdSJayanth Othayoth  * Licensed under the Apache License, Version 2.0 (the "License");
5a5311abdSJayanth Othayoth  * you may not use this file except in compliance with the License.
6a5311abdSJayanth Othayoth  * You may obtain a copy of the License at
7a5311abdSJayanth Othayoth  *
8a5311abdSJayanth Othayoth  *     http://www.apache.org/licenses/LICENSE-2.0
9a5311abdSJayanth Othayoth  *
10a5311abdSJayanth Othayoth  * Unless required by applicable law or agreed to in writing, software
11a5311abdSJayanth Othayoth  * distributed under the License is distributed on an "AS IS" BASIS,
12a5311abdSJayanth Othayoth  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a5311abdSJayanth Othayoth  * See the License for the specific language governing permissions and
14a5311abdSJayanth Othayoth  * limitations under the License.
15a5311abdSJayanth Othayoth  */
16a5311abdSJayanth Othayoth #include "cfam_access.hpp"
17a5311abdSJayanth Othayoth #include "p9_cfam.hpp"
18a5311abdSJayanth Othayoth #include "registration.hpp"
19a5311abdSJayanth Othayoth #include "targeting.hpp"
20a5311abdSJayanth Othayoth 
21a5311abdSJayanth Othayoth #include <phosphor-logging/log.hpp>
22a5311abdSJayanth Othayoth 
23a5311abdSJayanth Othayoth namespace openpower
24a5311abdSJayanth Othayoth {
25a5311abdSJayanth Othayoth namespace p9
26a5311abdSJayanth Othayoth {
27a5311abdSJayanth Othayoth namespace debug
28a5311abdSJayanth Othayoth {
29a5311abdSJayanth Othayoth // SBE messaging register - cfam 2809
30a5311abdSJayanth Othayoth union sbeMsgReg_t
31a5311abdSJayanth Othayoth {
32a5311abdSJayanth Othayoth     uint32_t data32;
33a5311abdSJayanth Othayoth 
34a5311abdSJayanth Othayoth     struct
35a5311abdSJayanth Othayoth     {
36a5311abdSJayanth Othayoth #if __BYTE_ORDER == __LITTLE_ENDIAN
37a5311abdSJayanth Othayoth         uint32_t reserved2:6;
38a5311abdSJayanth Othayoth         uint32_t minorStep:6;
39a5311abdSJayanth Othayoth         uint32_t majorStep:8;
40a5311abdSJayanth Othayoth         uint32_t currState:4;
41a5311abdSJayanth Othayoth         uint32_t prevState:4;
42a5311abdSJayanth Othayoth         uint32_t reserved1:2;
43a5311abdSJayanth Othayoth         uint32_t asyncFFDC:1;
44a5311abdSJayanth Othayoth         uint32_t sbeBooted:1;
45a5311abdSJayanth Othayoth #else
46a5311abdSJayanth Othayoth         uint32_t sbeBooted:1;
47a5311abdSJayanth Othayoth         uint32_t asyncFFDC:1;
48a5311abdSJayanth Othayoth         uint32_t reserved1:2;
49a5311abdSJayanth Othayoth         uint32_t prevState:4;
50a5311abdSJayanth Othayoth         uint32_t currState:4;
51a5311abdSJayanth Othayoth         uint32_t majorStep:8;
52a5311abdSJayanth Othayoth         uint32_t minorStep:6;
53a5311abdSJayanth Othayoth         uint32_t reserved2:6;
54a5311abdSJayanth Othayoth #endif
5575912e83SLakshminarayana R. Kammath     } PACK;
56a5311abdSJayanth Othayoth };
57a5311abdSJayanth Othayoth 
58a5311abdSJayanth Othayoth // HB mailbox scratch register 5 - cfam 283C
59a5311abdSJayanth Othayoth union MboxScratch5_HB_t
60a5311abdSJayanth Othayoth {
61a5311abdSJayanth Othayoth     uint32_t data32;
62a5311abdSJayanth Othayoth     struct
63a5311abdSJayanth Othayoth     {
64a5311abdSJayanth Othayoth #if __BYTE_ORDER == __LITTLE_ENDIAN
65a5311abdSJayanth Othayoth         uint32_t minorStep:8;    // 24:31
66a5311abdSJayanth Othayoth         uint32_t majorStep:8;    // 16:23
67a5311abdSJayanth Othayoth         uint32_t internalStep:4; // 12:15
68a5311abdSJayanth Othayoth         uint32_t reserved:2;     // 10:11
69a5311abdSJayanth Othayoth         uint32_t stepFinish:1;   // 9
70a5311abdSJayanth Othayoth         uint32_t stepStart:1;    // 8
71a5311abdSJayanth Othayoth         uint32_t magic:8;        // 0:7
72a5311abdSJayanth Othayoth #else
73a5311abdSJayanth Othayoth         uint32_t magic:8;        // 0:7
74a5311abdSJayanth Othayoth         uint32_t stepStart:1;    // 8
75a5311abdSJayanth Othayoth         uint32_t stepFinish:1;   // 9
76a5311abdSJayanth Othayoth         uint32_t reserved:2;     // 10:11
77a5311abdSJayanth Othayoth         uint32_t internalStep:4; // 12:15
78a5311abdSJayanth Othayoth         uint32_t majorStep:8;    // 16:23
79a5311abdSJayanth Othayoth         uint32_t minorStep:8;    // 24:31
80a5311abdSJayanth Othayoth #endif
8175912e83SLakshminarayana R. Kammath     } PACK;
82a5311abdSJayanth Othayoth };
83a5311abdSJayanth Othayoth 
84a5311abdSJayanth Othayoth static constexpr uint8_t HB_MBX5_VALID_FLAG = 0xAA;
85a5311abdSJayanth Othayoth 
86a5311abdSJayanth Othayoth /**
87a5311abdSJayanth Othayoth  * @brief Capture SBE and HB istep information on watchdog timeout
88a5311abdSJayanth Othayoth  * @return void
89a5311abdSJayanth Othayoth  */
collectSBEHBData()90a5311abdSJayanth Othayoth void collectSBEHBData()
91a5311abdSJayanth Othayoth {
92a5311abdSJayanth Othayoth     using namespace openpower::targeting;
93a5311abdSJayanth Othayoth     using namespace openpower::cfam::p9;
94a5311abdSJayanth Othayoth     using namespace openpower::cfam::access;
95a5311abdSJayanth Othayoth     using namespace phosphor::logging;
96a5311abdSJayanth Othayoth 
97a5311abdSJayanth Othayoth     Targeting targets;
98a5311abdSJayanth Othayoth 
99a5311abdSJayanth Othayoth     for (const auto& proc : targets)
100a5311abdSJayanth Othayoth     {
101a5311abdSJayanth Othayoth         // Read and parse SBE messaging register
102a5311abdSJayanth Othayoth         try
103a5311abdSJayanth Othayoth         {
104a5311abdSJayanth Othayoth             auto readData = readReg(proc, P9_SBE_MSG_REGISTER);
105a5311abdSJayanth Othayoth             auto msg = reinterpret_cast<const sbeMsgReg_t*>(&readData);
106a5311abdSJayanth Othayoth             log<level::INFO>("SBE status register",
107a5311abdSJayanth Othayoth                              entry("PROC=%d", proc->getPos()),
10875912e83SLakshminarayana R. Kammath                              entry("SBE_MAJOR_ISTEP=%d", msg->PACK.majorStep),
10975912e83SLakshminarayana R. Kammath                              entry("SBE_MINOR_ISTEP=%d", msg->PACK.minorStep),
110a5311abdSJayanth Othayoth                              entry("REG_VAL=0x%08X", msg->data32));
111a5311abdSJayanth Othayoth         }
112a5311abdSJayanth Othayoth         catch (const std::exception& e)
113a5311abdSJayanth Othayoth         {
114a5311abdSJayanth Othayoth             log<level::ERR>(e.what());
115a5311abdSJayanth Othayoth             // We want to continue - capturing as much info as possible
116a5311abdSJayanth Othayoth         }
117a5311abdSJayanth Othayoth     }
118a5311abdSJayanth Othayoth 
119a5311abdSJayanth Othayoth     const auto& master = *(targets.begin());
120a5311abdSJayanth Othayoth     // Read and parse HB messaging register
121a5311abdSJayanth Othayoth     try
122a5311abdSJayanth Othayoth     {
123a5311abdSJayanth Othayoth         auto readData = readReg(master, P9_HB_MBX5_REG);
124a5311abdSJayanth Othayoth         auto msg = reinterpret_cast<const MboxScratch5_HB_t*>(&readData);
12575912e83SLakshminarayana R. Kammath         if (HB_MBX5_VALID_FLAG == msg->PACK.magic)
126a5311abdSJayanth Othayoth         {
127a5311abdSJayanth Othayoth             log<level::INFO>("HB MBOX 5 register",
12875912e83SLakshminarayana R. Kammath                              entry("HB_MAJOR_ISTEP=%d", msg->PACK.majorStep),
12975912e83SLakshminarayana R. Kammath                              entry("HB_MINOR_ISTEP=%d", msg->PACK.minorStep),
130a5311abdSJayanth Othayoth                              entry("REG_VAL=0x%08X", msg->data32));
131a5311abdSJayanth Othayoth         }
132a5311abdSJayanth Othayoth     }
133a5311abdSJayanth Othayoth     catch (const std::exception& e)
134a5311abdSJayanth Othayoth     {
135a5311abdSJayanth Othayoth         log<level::ERR>(e.what());
136a5311abdSJayanth Othayoth         // We want to continue - capturing as much info as possible
137a5311abdSJayanth Othayoth     }
138a5311abdSJayanth Othayoth }
139a5311abdSJayanth Othayoth 
140*63508a73SBrad Bishop REGISTER_PROCEDURE("collectSBEHBData", collectSBEHBData)
141a5311abdSJayanth Othayoth 
142a5311abdSJayanth Othayoth } // namespace debug
143a5311abdSJayanth Othayoth } // namespace p9
144a5311abdSJayanth Othayoth } // namespace openpower
145