summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/errludlogregister.C
blob: a1941c8e4b5fb4680ece3d3ebcbdef6812c2042c (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
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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/errludlogregister.C $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* 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 errludlogregister.C
 *
 *  @brief Implementation of ErrlUserDetailsLogRegister
 */
#include <errl/errludlogregister.H>
#include <errl/errlreasoncodes.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/util.H>
#include <targeting/common/trace.H>

#include <devicefw/driverif.H>

namespace ERRORLOG
{

using namespace TARGETING;

extern TARG_TD_t g_trac_errl;

// internal function:
void ErrlUserDetailsLogRegister::setStateLogHUID()
{
    // Set up ErrlUserDetails instance variables
    iv_CompId = ERRL_COMP_ID;
    iv_Version = 1;
    iv_SubSection = ERRL_UDT_LOGREGISTER;

    // override the default of false.
    iv_merge = true;

    // write the HUID of the target into the error log buffer
    uint32_t attrHuid = get_huid(iv_pTarget);
    uint8_t *pBuf = reinterpret_cast<uint8_t *>
            (reallocUsrBuf(sizeof(uint32_t) + sizeof(uint8_t)));
    memcpy(pBuf, &attrHuid, sizeof(uint32_t));
    iv_dataSize += sizeof(uint32_t);

    // add space for the count and initialize to 0
#define REGISTER_COUNT_OFFSET (sizeof(uint32_t))
    *(pBuf + REGISTER_COUNT_OFFSET) = 0;
    iv_dataSize += sizeof(uint8_t);

} // setStateLogHUID

// internal function:
void ErrlUserDetailsLogRegister::writeRegisterData(
    void *i_dataBuf, size_t i_dataSize,
    int32_t i_numAddressArgs,
    uint8_t i_accessType, va_list i_args)
{

    uint64_t regParam[i_numAddressArgs];
    for (int32_t i = 0;i < i_numAddressArgs;i++)
    {
        regParam[i] = va_arg(i_args, uint64_t);
    } // for

    // write the data into the buffer; format is:
    // i_accessType, regParam[i], uint8_t(i_dataSize), i_dataBuf
    uint32_t newSize = sizeof(i_accessType) +
                        sizeof(regParam) +
                        sizeof(uint8_t) +
                        i_dataSize;

    uint8_t *pBuf;
    pBuf = reinterpret_cast<uint8_t *>(reallocUsrBuf(iv_dataSize + newSize));
    memcpy(pBuf + iv_dataSize, &i_accessType, sizeof(i_accessType) );
    iv_dataSize += sizeof(i_accessType);
    for (int32_t i = 0;i < i_numAddressArgs;i++)
    {
        memcpy(pBuf + iv_dataSize, &regParam[i], sizeof(regParam[i]) );
        iv_dataSize += sizeof(regParam[i]);
    } // for
    uint8_t regSize = (uint8_t)i_dataSize;
    memcpy(pBuf + iv_dataSize, &regSize, sizeof(regSize) );
    iv_dataSize += sizeof(regSize);
    if (i_dataSize > 0)
    {
        memcpy(pBuf + iv_dataSize, i_dataBuf, i_dataSize);
        iv_dataSize += i_dataSize;
    }

    // increment the count
    *(pBuf + REGISTER_COUNT_OFFSET) += 1;

} // writeRegisterData

// internal function:
void ErrlUserDetailsLogRegister::readRegister(
    uint8_t i_accessType, va_list i_args)
{
    // we allow 0 in case there is some future type that has no parameter.
    //  (DeviceFW::PRESENT is an example, but we chose not to log that type)
    int32_t numAddressArgs = -1;

    // do we do the deviceOpValist or not, and how many
    //  parameters are there to be logged
    switch (i_accessType)
    {
        // one parameter
        case DeviceFW::SCOM:        // userif.H
        case DeviceFW::FSI:         // userif.H
        case DeviceFW::SPD:         // userif.H
        case DeviceFW::XSCOM:       // driverif.H
        case DeviceFW::FSISCOM:     // driverif.H
        case DeviceFW::IBSCOM:     // driverif.H
        {
            numAddressArgs = 1;
            break;
        }
        // two parameters
        case DeviceFW::MVPD:        // userif.H
        case DeviceFW::EEPROM:      // driverif.H
        {
            numAddressArgs = 2;
            break;
        }
        // three parameters
        case DeviceFW::I2C:         // driverif.H
        {
            numAddressArgs = 3;
            break;
        }
        // not logged!
        case DeviceFW::PRESENT:     // userif.H
        case DeviceFW::PNOR:        // userif.H
        case DeviceFW::MAILBOX:     // userif.H
        default:
        {   // no action - not logged
            TRACFCOMP(g_trac_errl, "LogRegister: AccessType %x not logged",
                i_accessType);
            break;
        } // default
    } // switch i_accessType

    if (numAddressArgs != -1)
    {
        // place for register data to go, and (max) size we expect.
        uint64_t reg_data = 0;
        size_t reg_size = sizeof(reg_data);

        TRACDCOMP(g_trac_errl, "LogRegister: deviceOpValist()");
        errlHndl_t errl;
        errl = DeviceFW::deviceOpValist(DeviceFW::READ,
                    const_cast<TARGETING::Target *>(iv_pTarget),
                    &reg_data, reg_size,
                    (DeviceFW::AccessType) i_accessType, i_args);

        if (unlikely(errl != NULL))
        {   // error!
            TRACFCOMP(g_trac_errl, "LogRegister: deviceOpValist type %d"
                        " threw errl! deleting errl.",
                        i_accessType);
            delete errl; // eat the error - just delete it

            // nothing gets written out
        }
        else
        {
            // internal worker function to put reg data into the log
            writeRegisterData(&reg_data, reg_size, numAddressArgs,
                    i_accessType, i_args);
            TRACDCOMP(g_trac_errl, "LogRegister: iv_dataSize %d", iv_dataSize);
        }
    }
    // else: nothing gets written out
} // readRegister

// internal function:
void ErrlUserDetailsLogRegister::copyRegisterData(
    void *i_dataBuf, size_t i_dataSize,
    uint8_t i_accessType, va_list i_args)
{
    // we allow 0 in case there is some future type that has no parameter.
    //  (DeviceFW::PRESENT is an example, but we chose not to log that type)
    int32_t numAddressArgs = -1;

    // do we do the deviceOpValist or not, and how many
    //  parameters are there to be logged
    switch (i_accessType)
    {
        // one parameter
        case DeviceFW::SCOM:        // userif.H
        case DeviceFW::FSI:         // userif.H
        case DeviceFW::SPD:         // userif.H
        case DeviceFW::XSCOM:       // driverif.H
        case DeviceFW::FSISCOM:     // driverif.H
        case DeviceFW::IBSCOM:     // driverif.H
        {
            numAddressArgs = 1;
            break;
        }
        // two parameters
        case DeviceFW::MVPD:        // userif.H
        case DeviceFW::EEPROM:      // driverif.H
        {
            numAddressArgs = 2;
            break;
        }
        // three parameters
        case DeviceFW::I2C:         // driverif.H
        {
            numAddressArgs = 3;
            break;
        }
        // not logged!
        case DeviceFW::PRESENT:     // userif.H
        case DeviceFW::PNOR:        // userif.H
        case DeviceFW::MAILBOX:     // userif.H
        default:
        {   // no action - not logged
            TRACFCOMP(g_trac_errl, "LogRegister: AccessType %x not logged",
                i_accessType);
            break;
        } // default
    } // switch i_accessType

    if (numAddressArgs != -1)
    {
        // internal worker function to put reg data into the log
        writeRegisterData(i_dataBuf, i_dataSize, numAddressArgs,
                i_accessType, i_args);
        TRACDCOMP(g_trac_errl, "LogRegister: iv_dataSize %d", iv_dataSize);
    }
    // else: nothing gets written out
} // copyRegisterData

//------------------------------------------------------------------------------
/*
 * The public addData() function are templates allowing i_accesstype to change:
 *  either the DeviceFW::AccessType values in devicefw/userif.H
 *  OR the DeviceFW::AccessType_DriverOnly values in devicefw/driverif.H
 *  We don't want to include driverif.H in the errludlogregister.H file, so
 *  we do the template.
 *
 *  We don't want/need to include a different separate addData() for each of
 *  those instances tho, so we create one __addData() function, and then use
 *  this alias to have both public template functions point to this function.
 *
 *  This function will call the readRegister() function to log and do the read.
 */
template <>
void ErrlUserDetailsLogRegister::addData<>(
    DeviceFW::AccessType i_accessType, ...)
__attribute__((alias("_ZN8ERRORLOG26ErrlUserDetailsLogRegister9__addDataEhz")));
template <>
void ErrlUserDetailsLogRegister::addData<>(
    DeviceFW::AccessType_DriverOnly i_accessType, ...)
__attribute__((alias("_ZN8ERRORLOG26ErrlUserDetailsLogRegister9__addDataEhz")));

void ErrlUserDetailsLogRegister::__addData(
    uint8_t i_accessType, ...)
{
    TRACDCOMP(g_trac_errl, "LogRegister::addData: type %x",
        i_accessType);

    // get the data - do the read
    va_list args;
    va_start(args, i_accessType);
    readRegister(i_accessType, args);
    va_end(args);

} // __addData

/*
 * Same as above with regards to templates and alias.
 *
 * This function will just store the passed-in data, unless it's NULL.
 */
template <>
void ErrlUserDetailsLogRegister::addDataBuffer<>(
    void *i_dataBuf, size_t i_dataSize,
    DeviceFW::AccessType i_accessType, ...)
__attribute__((alias("_ZN8ERRORLOG26ErrlUserDetailsLogRegister15__addDataBufferEPvmhz")));
template <>
void ErrlUserDetailsLogRegister::addDataBuffer<>(
    void *i_dataBuf, size_t i_dataSize,
    DeviceFW::AccessType_DriverOnly i_accessType, ...)
__attribute__((alias("_ZN8ERRORLOG26ErrlUserDetailsLogRegister15__addDataBufferEPvmhz")));

void ErrlUserDetailsLogRegister::__addDataBuffer(
    void *i_dataBuf, size_t i_dataSize,
    uint8_t i_accessType, ...)
{
    TRACDCOMP(g_trac_errl, "LogRegister::addDataBuffer: type %x from %p size %d",
        i_accessType, i_dataBuf, i_dataSize);

    // if there's data, just copy it thru.
    if (i_dataBuf != NULL)
    {
        // get the data - do the copy
        va_list args;
        va_start(args, i_accessType);
        copyRegisterData(i_dataBuf, i_dataSize, i_accessType, args);
        va_end(args);
    }
    else
    {   // user didn't give us any data -
        // get the data ourselves - do the read
        va_list args;
        va_start(args, i_accessType);
        readRegister(i_accessType, args);
        va_end(args);
    }
} // __addDataBuffer


//------------------------------------------------------------------------------
ErrlUserDetailsLogRegister::ErrlUserDetailsLogRegister(
    const TARGETING::Target * i_pTarget)
    : iv_pTarget(i_pTarget), iv_dataSize(0)
{
    TRACDCOMP(g_trac_errl, "LogRegister: target %p",
        i_pTarget);

    setStateLogHUID();

    // done - user will have to do addData() or addDataBuffer() calls.
} // ctor with target only

//------------------------------------------------------------------------------
ErrlUserDetailsLogRegister::ErrlUserDetailsLogRegister(
    const TARGETING::Target * i_pTarget,
    DeviceFW::AccessType i_accessType, ...)
    : iv_pTarget(i_pTarget), iv_dataSize(0)
{
    TRACDCOMP(g_trac_errl, "LogRegister: target %p type %x",
        i_pTarget, i_accessType);

    setStateLogHUID();

    // get the data - do the read
    va_list args;
    va_start(args, i_accessType);
    readRegister(i_accessType, args);
    va_end(args);

} // ctor with target and register type/address

//------------------------------------------------------------------------------
ErrlUserDetailsLogRegister::ErrlUserDetailsLogRegister(
    const TARGETING::Target * i_pTarget,
    void *i_dataBuf,
    size_t i_dataSize,
    DeviceFW::AccessType i_accessType, ...)
    : iv_pTarget(i_pTarget), iv_dataSize(0)
{
    TRACDCOMP(g_trac_errl, "LogRegister: target %p type %x dataBuf %p size %d",
        i_pTarget, i_accessType,
        i_dataBuf, i_dataSize
        );

    setStateLogHUID();

    // if there's data, just copy it thru.
    if (i_dataBuf != NULL)
    {
        // get the data - do the copy
        va_list args;
        va_start(args, i_accessType);
        copyRegisterData(i_dataBuf, i_dataSize, i_accessType, args);
        va_end(args);
    }
    else
    {   // user didn't give us any data -
        // get the data ourselves - do the read
        va_list args;
        va_start(args, i_accessType);
        readRegister(i_accessType, args);
        va_end(args);
    }
} // ctor with target, register type/address and already-read data

}
OpenPOWER on IntegriCloud