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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/ipmi/ipmisel.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2014,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 */
/**
* @file ipmisel.C
* @brief IPMI system error log transport definition
*/
#include <algorithm>
#include <sys/time.h>
#include <ipmi/ipmisel.H>
#include "ipmiconfig.H"
#include <ipmi/ipmi_reasoncodes.H>
#include <sys/task.h>
#include <initservice/taskargs.H>
#include <initservice/initserviceif.H>
#include <errl/errlmanager.H>
//Defined in ipmidd.C
extern trace_desc_t * g_trac_ipmi;
#define IPMI_TRAC(printf_string,args...) \
TRACFCOMP(g_trac_ipmi,"sel: "printf_string,##args)
// local functions
/*
* @brief Store either Record/Reserve ID from given data
*/
void storeReserveRecord(uint8_t* o_RData, uint8_t* i_data)
{
o_RData[0] = i_data[0];
o_RData[1] = i_data[1];
return;
}
/*
* @brief Create Partial Add eSEL Header from inputs
*/
void createPartialAddHeader(uint8_t* i_reserveID, uint8_t* i_recordID,
uint16_t i_offset, uint8_t i_isLastEntry,
uint8_t* o_header)
{
o_header[0] = i_reserveID[0];
o_header[1] = i_reserveID[1];
o_header[2] = i_recordID[0];
o_header[3] = i_recordID[1];
o_header[4] = (uint8_t)(i_offset & 0x00FF);
o_header[5] = (uint8_t)((i_offset & 0xFF00) >> 8);
o_header[6] = i_isLastEntry;
return;
}
enum esel_retry
{
MAX_SEND_COUNT = 4,
SLEEP_BASE = 2 * NS_PER_MSEC,
};
namespace IPMISEL
{
void sendESEL(uint8_t* i_eselData, uint32_t i_dataSize,
uint32_t i_eid, uint8_t i_eventDirType,
uint8_t i_sensorType, uint8_t i_sensorNumber)
{
IPMI_TRAC(ENTER_MRK "sendESEL()");
#ifdef __HOSTBOOT_RUNTIME
// HBRT doesn't send a msg, but use the msg structure to pass the data
msg_t l_msg;
msg_t *msg = &l_msg;
memset(msg, 0, sizeof(msg_t));
#else
msg_t *msg = msg_allocate();
#endif
msg->type = MSG_SEND_ESEL;
msg->data[0] = i_eid;
// create the sel record of information
IPMISEL::selRecord l_sel;
l_sel.record_type = IPMISEL::record_type_ami_esel;
l_sel.generator_id = IPMISEL::generator_id_ami;
l_sel.evm_format_version = IPMISEL::format_ipmi_version_2_0;
l_sel.sensor_type = i_sensorType;
l_sel.sensor_number = i_sensorNumber;
l_sel.event_dir_type = i_eventDirType;
l_sel.event_data1 = IPMISEL::event_data1_ami;
eselInitData *eselData =
new eselInitData(&l_sel, i_eselData, i_dataSize);
msg->extra_data = eselData;
#ifdef __HOSTBOOT_RUNTIME
process_esel(msg);
#else
// one message queue to the SEL thread
static msg_q_t mq = Singleton<IpmiSEL>::instance().msgQueue();
//Send the msg to the sel thread
int rc = msg_send(mq,msg);
if(rc)
{
IPMI_TRAC(ERR_MRK "Failed (rc=%d) to send message",rc);
delete eselData;
}
#endif
IPMI_TRAC(EXIT_MRK "sendESEL");
return;
} // sendESEL
/*
* @brief process esel msg
*/
void process_esel(msg_t *i_msg)
{
errlHndl_t l_err = NULL;
IPMI::completion_code l_cc = IPMI::CC_UNKBAD;
const uint32_t l_eid = i_msg->data[0];
IPMISEL::eselInitData * l_data =
(IPMISEL::eselInitData*)(i_msg->extra_data);
IPMI_TRAC(ENTER_MRK "process_esel");
uint32_t l_send_count = MAX_SEND_COUNT;
while (l_send_count > 0)
{
// try to send the eles to the bmc
IPMISEL::send_esel(l_data, l_err, l_cc);
// if no error but last completion code was:
if ((l_err == NULL) &&
((l_cc == IPMI::CC_BADRESV) || // lost reservation
(l_cc == IPMI::CC_TIMEOUT))) // timeout
{
// update our count and pause
l_send_count--;
if (l_send_count)
{
IPMI_TRAC("process_esel: sleeping; retry_count %d",
l_send_count);
// sleep 3 times - 2ms, 32ms, 512ms. if we can't get this
// through by then, the system must really be busy...
nanosleep(0,
SLEEP_BASE << (4 * (MAX_SEND_COUNT - l_send_count - 1)));
continue;
}
}
// else it did get sent down OR it didn't because of a bad error
break;
} // while
if(l_err)
{
#ifdef __HOSTBOOT_RUNTIME
// HBRT can't commit an error, since this could already be in the
// errlCommit path since HBRT is single threaded
IPMI_TRAC(ERR_MRK "DELETING l_err 0x%.8X", l_err->eid());
delete l_err;
l_err = NULL;
// TODO RTC: 123419 investigate adding a 'iv_isIpmiEnabled' flag and setting
// that to false somehow, so that we can commit error logs in this path
// and future calls wont try to send them down.
#else
l_err->collectTrace(IPMI_COMP_NAME);
errlCommit(l_err, IPMI_COMP_ID);
#endif
}
else if((l_cc == IPMI::CC_OK) && // no error
(l_eid != 0)) // and it's an errorlog
{
#ifdef __HOSTBOOT_RUNTIME
// TODO RTC: 123419 story to add storing errlog to PNOR in HBRT if IPMI
#else
// eSEL successfully sent to the BMC - send an ack to the errlmanager
IPMI_TRAC(INFO_MRK "Sending ack for eid 0x%.8X", l_eid);
ERRORLOG::ErrlManager::errlAckErrorlog(l_eid);
#endif
}
delete l_data;
IPMI_TRAC(EXIT_MRK "process_esel");
return;
} // process_esel
/*
* @brief Send esel data to bmc
*/
void send_esel(IPMISEL::eselInitData * i_data,
errlHndl_t &o_err, IPMI::completion_code &o_cc)
{
IPMI_TRAC(ENTER_MRK "send_esel");
uint8_t* data = NULL;
const size_t l_eSELlen = i_data->dataSize;
size_t len = 0;
uint8_t reserveID[2] = {0,0};
uint8_t esel_recordID[2] = {0,0};
do{
// we need to send down the extended sel data (eSEL), which is
// longer than the protocol buffer, so we need to do a reservation and
// call the AMI partial_add_esel command multiple times
// put a reservation on the SEL Device since we're doing a partial_add
len = 0;
delete [] data;
data = NULL;
o_cc = IPMI::CC_UNKBAD;
o_err = IPMI::sendrecv(IPMI::reserve_sel(),o_cc,len,data);
if(o_err)
{
IPMI_TRAC(ERR_MRK "error from reserve_sel");
break;
}
if(o_cc != IPMI::CC_OK)
{
IPMI_TRAC(ERR_MRK "Failed to reserve_sel, o_cc %02x",o_cc);
break;
}
storeReserveRecord(reserveID,data);
// first send down the SEL Event Record data
size_t eSELindex = 0;
uint8_t l_lastEntry = 0;
len = IPMISEL::PARTIAL_ADD_ESEL_REQ + sizeof(IPMISEL::selRecord);
delete [] data;
data = new uint8_t[len];
// fill in the partial_add_esel request (command) data
createPartialAddHeader(reserveID,esel_recordID,eSELindex,l_lastEntry,data);
// copy in the SEL event record data
memcpy(&data[IPMISEL::PARTIAL_ADD_ESEL_REQ], i_data->eSel,
sizeof(IPMISEL::selRecord));
o_cc = IPMI::CC_UNKBAD;
TRACFBIN( g_trac_ipmi, INFO_MRK"1st partial_add_esel:", data, len);
o_err = IPMI::sendrecv(IPMI::partial_add_esel(),o_cc,len,data);
if(o_err)
{
IPMI_TRAC(ERR_MRK "error from first partial_add_esel");
break;
}
// as long as we continue to get CC_OK, the reserve sel is good.
// if the reservation is lost (ie, because something else tried to
// create a SEL) then the BMC just discards all this data. the
// errorlog will still be in PNOR and won't get ACKed, so it'll get
// resent on the next IPL.
if (o_cc != IPMI::CC_OK)
{
IPMI_TRAC(ERR_MRK "failed first partial_add_esel, o_cc %02x, eSELindex %02x",
o_cc, eSELindex);
break;
}
// BMC returns the recordID, it's always the same (unless
// there's a major BMC bug...)
storeReserveRecord(esel_recordID,data);
// now send down the eSEL data in chunks.
const size_t l_maxBuffer = IPMI::max_buffer();
while(eSELindex<l_eSELlen)
{
//if the index + the maximum buffer is less than what we still
//have left in the eSEL, this is not the last entry (data[6] = 0)
//otherwise, it is and data[6] = 1
if(eSELindex + (l_maxBuffer - IPMISEL::PARTIAL_ADD_ESEL_REQ)
< l_eSELlen)
{
len = l_maxBuffer;
l_lastEntry = 0x00;
}
else
{
len = l_eSELlen - eSELindex + IPMISEL::PARTIAL_ADD_ESEL_REQ;
l_lastEntry = 0x01;
}
delete [] data;
data = new uint8_t[len];
// fill in the partial_add_esel request (command) data
createPartialAddHeader(reserveID, esel_recordID,
eSELindex + sizeof(IPMISEL::selRecord),
l_lastEntry, data);
uint8_t dataCpyLen = len - IPMISEL::PARTIAL_ADD_ESEL_REQ;
memcpy(&data[IPMISEL::PARTIAL_ADD_ESEL_REQ],
&i_data->eSelExtra[eSELindex],
dataCpyLen);
// update the offset into the data
eSELindex = eSELindex + dataCpyLen;
o_cc = IPMI::CC_UNKBAD;
TRACFBIN( g_trac_ipmi, INFO_MRK"partial_add_esel:", data, len);
o_err = IPMI::sendrecv(IPMI::partial_add_esel(),o_cc,len,data);
if(o_err)
{
IPMI_TRAC(ERR_MRK "error from partial_add_esel");
break;
}
// as long as we continue to get CC_OK, the reserve sel is good.
// if the reservation is lost (ie, because something else tried to
// create a SEL) then the BMC just discards all this data. the
// errorlog will still be in PNOR and won't get ACKed, so it'll get
// resent on the next IPL.
if (o_cc != IPMI::CC_OK)
{
IPMI_TRAC(ERR_MRK "failed partial_add_esel, o_cc %02x, eSELindex %02x",
o_cc, eSELindex);
break;
}
// BMC returns the recordID, it's always the same (unless
// there's a major BMC bug...)
storeReserveRecord(esel_recordID,data);
}
if(o_err || (o_cc != IPMI::CC_OK))
{
break;
}
}while(0);
delete[] data;
IPMI_TRAC(EXIT_MRK "send_esel (o_err %.8X, o_cc x%.2x, recID=x%x%x)",
o_err ? o_err->plid() : NULL, o_cc, esel_recordID[1], esel_recordID[0]);
return;
} // send_esel
} // IPMISEL
#ifndef __HOSTBOOT_RUNTIME
/**
* @brief Constructor
*/
IpmiSEL::IpmiSEL(void)
:iv_msgQ(msg_q_create())
{
IPMI_TRAC(ENTER_MRK "IpmiSEL ctor");
task_create(&IpmiSEL::start,NULL);
}
/**
* @brief Destructor
*/
IpmiSEL::~IpmiSEL(void)
{
msg_q_destroy(iv_msgQ);
}
void* IpmiSEL::start(void* unused)
{
Singleton<IpmiSEL>::instance().execute();
return NULL;
}
/**
* @brief Entry point of the sel ipmi thread
*/
//@todo: RTC 119832
void IpmiSEL::execute(void)
{
//Mark as an independent daemon so if it crashes we terminate.
task_detach();
// Register shutdown events with init service.
// Done at the "end" of shutdown processesing.
// This will flush out any IPMI messages which were sent as
// part of the shutdown processing. We chose MBOX priority
// as we don't want to accidentally get this message after
// interrupt processing has stopped in case we need intr to
// finish flushing the pipe.
INITSERVICE::registerShutdownEvent(iv_msgQ, IPMISEL::MSG_STATE_SHUTDOWN,
INITSERVICE::MBOX_PRIORITY);
while(true)
{
msg_t* msg = msg_wait(iv_msgQ);
const IPMISEL::msg_type msg_type =
static_cast<IPMISEL::msg_type>(msg->type);
// Invert the "default" by checking here. This allows the compiler
// to warn us if the enum has an unhadled case but still catch
// runtime errors where msg_type is set out of bounds.
assert(msg_type <= IPMISEL::MSG_LAST_TYPE,
"msg_type %d not handled", msg_type);
switch(msg_type)
{
case IPMISEL::MSG_SEND_ESEL:
IPMISEL::process_esel(msg);
//done with msg
msg_free(msg);
break;
case IPMISEL::MSG_STATE_SHUTDOWN:
IPMI_TRAC(INFO_MRK "ipmisel shutdown event");
//Respond that we are done shutting down.
msg_respond(iv_msgQ, msg);
break;
}
} // while(1)
IPMI_TRAC(EXIT_MRK "message loop");
return;
} // execute
#endif
|