summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/errlmanager_common.C
blob: 38b8b3f3db0cb67926f0486a8fbb26750e2ae02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/errlmanager_common.C $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include <errl/errlmanager.H>
#include <config.h>
#include <hwas/common/hwasCallout.H>
#include <errl/errlreasoncodes.H>
#include <ipmi/ipmisel.H>
#include <ipmi/ipmisensor.H>

namespace ERRORLOG
{

extern trace_desc_t* g_trac_errl;

#ifdef CONFIG_BMC_IPMI
void ErrlManager::sendErrLogToBmc(errlHndl_t &io_err)
{
    TRACFCOMP(g_trac_errl, ENTER_MRK
                "sendErrLogToBmc errlogId 0x%.8x", io_err->eid());

    do {

        // Decide whether we want to skip the error log
        if( io_err->getSkipShowingLog() )
        {
            TRACDCOMP( g_trac_errl, INFO_MRK
                    "sendErrLogToBmc: %.8X is INFORMATIONAL/RECOVERED; skipping",
                    io_err->eid());
            break;
        }

        // look thru the errlog for any Callout UserDetail sections
        //  to determine the sensor information for the SEL
        std::vector<uint8_t> l_sensorNumbers;
        std::vector<uint8_t> l_sensorTypes;
        HWAS::callOutPriority l_priority = HWAS::SRCI_PRIORITY_NONE;
        for(std::vector<ErrlUD*>::const_iterator
                it = io_err->iv_SectionVector.begin();
                it != io_err->iv_SectionVector.end();
                it++ )
        {
            HWAS::callout_ud_t *l_ud =
                    reinterpret_cast<HWAS::callout_ud_t*>((*it)->iv_pData);

            // if this is a CALLOUT that will have a target
            if ((ERRL_COMP_ID     == (*it)->iv_header.iv_compId) &&
                (1                == (*it)->iv_header.iv_ver) &&
                (ERRL_UDT_CALLOUT == (*it)->iv_header.iv_sst) &&
                (HWAS::HW_CALLOUT == l_ud->type)
               )
            {
                // if this callout is higher than any previous callout
                if (l_ud->priority > l_priority)
                {
                    // get the sensor number for the target
                    uint8_t * l_uData = (uint8_t *)(l_ud + 1);
                    TARGETING::Target *l_target = NULL;
                    bool l_err = HWAS::retrieveTarget(l_uData,
                            l_target, io_err);
                    if (!l_err)
                    {
                        //remove previous sensor data
                        l_sensorNumbers.clear();

                        // got a target, now get the sensor number
                        l_sensorNumbers.push_back(
                                        SENSOR::getFaultSensorNumber(l_target));

                        // and update the priority
                        l_priority = l_ud->priority;
                    }
                // if this callout is equal to any previous callout
                }else if(l_ud->priority == l_priority)
                {
                    //get the sensor number for the target
                    uint8_t * l_uData = (uint8_t *)(l_ud + 1);
                    TARGETING::Target *l_target = NULL;
                    bool l_err = HWAS::retrieveTarget(l_uData,
                            l_target, io_err);
                    if(!l_err)
                    {
                        //add sensor data to array
                        l_sensorNumbers.push_back(
                                        SENSOR::getFaultSensorNumber(l_target));
                    }
                }
            }
        } // for each SectionVector

        std::vector<uint8_t>::const_iterator l_sensorIter;
        for(l_sensorIter = l_sensorNumbers.begin();
            l_sensorIter != l_sensorNumbers.end();
            l_sensorIter++)
        {
            uint8_t unused = 0;
            uint8_t l_getSensorType;
            errlHndl_t e =
                SENSOR::SensorBase::getSensorType(
                                *l_sensorIter,
                                l_getSensorType,unused);
            l_sensorTypes.push_back(l_getSensorType);
            if( e )
            {
                TRACFCOMP(g_trac_errl,
                          ERR_MRK"Failed to get sensor type for sensor %d",
                          *l_sensorIter);
                // since we are in the commit path, lets just delete this
                // error and move on.
                delete e;
            }

        }

        // flatten into buffer, truncate to max eSEL size
        uint32_t l_pelSize = io_err->flattenedSize();
        if (l_pelSize > (IPMISEL::ESEL_MAX_SIZE - sizeof(IPMISEL::selRecord)))
        {
            TRACFCOMP( g_trac_errl, INFO_MRK
                    "sendErrLogToBmc: msg size %d > %d, truncating.",
                    l_pelSize, IPMISEL::ESEL_MAX_SIZE);
            l_pelSize = IPMISEL::ESEL_MAX_SIZE - sizeof(IPMISEL::selRecord);
        }

        uint8_t *l_pelData = new uint8_t[l_pelSize];
        uint32_t l_errSize = io_err->flatten (l_pelData,
                                    l_pelSize, true /* truncate */);

        if (l_errSize ==0)
        {
            // flatten didn't work
            TRACFCOMP( g_trac_errl, ERR_MRK
                    "sendErrLogToBmc: could not flatten data - not sending");
            delete [] l_pelData;
            break;
        }

        uint8_t l_eventDirType  = IPMISEL::event_transition;
        uint8_t l_eventOffset   = IPMISEL::event_data1_trans_to_non_recoverable;
        switch (io_err->sev())
        {
            case ERRORLOG::ERRL_SEV_INFORMATIONAL:
                l_eventDirType  = IPMISEL::event_transition;
                l_eventOffset   = IPMISEL::event_data1_trans_informational;
                break;
            case ERRL_SEV_RECOVERED:
                l_eventDirType  = IPMISEL::event_transition;
                l_eventOffset   = IPMISEL::event_data1_trans_to_ok;
                break;
            case ERRL_SEV_PREDICTIVE:
                l_eventDirType  = IPMISEL::event_predictive;
                l_eventOffset   = IPMISEL::event_data1_trans_to_noncrit_from_ok;
                break;
            case ERRL_SEV_UNRECOVERABLE:
                l_eventDirType  = IPMISEL::event_transition;
                l_eventOffset   = IPMISEL::event_data1_trans_to_non_recoverable;
                break;
            case ERRL_SEV_CRITICAL_SYS_TERM:
                l_eventDirType  = IPMISEL::event_transition;
                l_eventOffset   = IPMISEL::event_data1_trans_to_crit_from_non_r;
                break;
            case ERRL_SEV_UNKNOWN:
                l_eventDirType  = IPMISEL::event_state;
                l_eventOffset   = IPMISEL::event_data1_asserted;
                break;
        }

        // send it to the BMC over IPMI
        for(uint8_t l_sendIdx=0;l_sendIdx < l_sensorNumbers.size();l_sendIdx++)
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "sendErrLogToBmc: creating ESEL for sensor #%d",l_sendIdx);
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "sendErrLogToBmc: sensor %.2x/%.2x event %x/%x, size %d",
                    l_sensorTypes.at(l_sendIdx), l_sensorNumbers.at(l_sendIdx),
                    l_eventDirType, l_eventOffset,
                    ((l_sendIdx==0)?l_pelSize:0));

            IPMISEL::sendESEL(l_pelData, ((l_sendIdx==0) ? l_pelSize:0),
                                io_err->eid(),
                                l_eventDirType, l_eventOffset,
                                l_sensorTypes.at(l_sendIdx),
                                l_sensorNumbers.at(l_sendIdx));
        }

        // free the buffer
        delete [] l_pelData;

    } while(0);

    TRACFCOMP(g_trac_errl, EXIT_MRK "sendErrLogToBmc");
} // sendErrLogToBmc

#endif

} // end namespace
OpenPOWER on IntegriCloud