summaryrefslogtreecommitdiffstats
path: root/src/sbefw/sbecmdscomaccess.C
blob: c74ed1334191b02be656090d7df5d7f10a2ea4f3 (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
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/sbecmdscomaccess.C $                                */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2017                        */
/* [+] 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: ppe/sbe/sbefw/sbecmdscomaccess.C
 *
 * @brief This file contains the SBE SCOM Access chipOps
 *
 */

#include "sbecmdscomaccess.H"
#include "sbefifo.H"
#include "sbe_sp_intf.H"
#include "sbetrace.H"
#include "sbescom.H"
#include "sbeutil.H"
#include "sbeFifoMsgUtils.H"
#include "plat_hw_access.H"
#include "sbeglobals.H"


//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
uint32_t sbeGetScom (uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeGetScom "
    SBE_ENTER(SBE_FUNC);

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    sbeGetScomReqMsg_t l_getScomReqMsg;

    do
    {
        uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = SBE_GLOBAL->sbeCmdRespHdr.sec_status ;

        // Will attempt to dequeue two entries for
        // the scom addresses plus the expected
        // EOT entry at the end

        uint32_t l_len2dequeue  = sizeof(l_getScomReqMsg)/sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, (uint32_t *)&l_getScomReqMsg);

        // If FIFO access failure
        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
        {
            // Let command processor routine to handle the RC.
            break;
        }

        sbeRespGenHdr_t l_hdr;
        l_hdr.init();
        sbeResponseFfdc_t l_ffdc;
        uint32_t l_len2enqueue  = 0;
        uint32_t l_sbeDownFifoRespBuf[2] = {0};

        uint64_t l_addr = ( (uint64_t)l_getScomReqMsg.hiAddr << 32) |
                                      l_getScomReqMsg.lowAddr;
        uint64_t l_scomData = 0;
        SBE_DEBUG(SBE_FUNC"scomAddr[0x%08X%08X]",
                            l_getScomReqMsg.hiAddr, l_getScomReqMsg.lowAddr);
        l_rc = checkIndirectAndDoScom(true, l_addr,
                                      l_scomData,
                                      &l_ffdc);

        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL) // scom failed
        {
            SBE_ERROR(SBE_FUNC"getscom failed, "
                "scomAddr[0x%08X%08X]",
                l_getScomReqMsg.hiAddr, l_getScomReqMsg.lowAddr);
            l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
            l_secStatus  = l_rc;
        }
        else // successful scom
        {
            SBE_DEBUG(SBE_FUNC"getscom succeeds, l_scomData[0x%016X]",
                                   l_scomData);

            l_sbeDownFifoRespBuf[0] = (uint32_t)(l_scomData>>32);
            l_sbeDownFifoRespBuf[1] = (uint32_t)(l_scomData);

            // Push the data into downstream FIFO
            l_len2enqueue = 2;
            l_rc = sbeDownFifoEnq_mult (l_len2enqueue,
                                      &l_sbeDownFifoRespBuf[0]);
            if (l_rc)
            {
                // will let command processor routine
                // handle the failure
                break;
            }
        } // end successful scom

        // Build the response header packet

        l_hdr.setStatus(l_primStatus, l_secStatus);
        l_rc = sbeDsSendRespHdr(l_hdr, &l_ffdc);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }

    } while(false);

    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}

/////////////////////////////////////////////////////
//////////////////////////////////////////////////////
uint32_t sbePutScom (uint8_t *i_pArg)
{
    #define SBE_FUNC " sbePutScom "
    SBE_ENTER(SBE_FUNC);

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    sbePutScomReqMsg_t l_putScomReqMsg;

    do
    {
        uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = SBE_GLOBAL->sbeCmdRespHdr.sec_status ;

        // Will attempt to dequeue four entries for
        // the scom address (two entries) and the
        // corresponding data (two entries) plus
        // the expected EOT entry at the end

        uint32_t  l_len2dequeue  = sizeof(l_putScomReqMsg)/sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, (uint32_t *)&l_putScomReqMsg);

        // If FIFO access failure
        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
        {
            // Let command processor routine to handle the RC.
            break;
        }

        uint64_t l_scomData = 0;
        sbeRespGenHdr_t l_hdr;
        l_hdr.init();
        sbeResponseFfdc_t l_ffdc;
        // successfully dequeued two entries for
        // scom address followed by the EOT entry

        // Data entry 0 : Scom Register Address (0..31)
        // Data entry 1 : Scom Register Address (32..63)
        // Data entry 2 : Scom Register Data (0..31)
        // Data entry 3 : Scom Register Data (32..63)
        // For Direct SCOM, will ignore entry 0

        l_scomData = l_putScomReqMsg.getScomData();

        uint64_t l_addr = ( (uint64_t)  l_putScomReqMsg.hiAddr << 32) |
                                        l_putScomReqMsg.lowAddr;
        SBE_DEBUG(SBE_FUNC"scomAddr[0x%08X%08X]",
                            l_putScomReqMsg.hiAddr, l_putScomReqMsg.lowAddr);
        l_rc = checkIndirectAndDoScom(false, l_addr,
                                      l_scomData, &l_ffdc);

        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL) // scom failed
        {
            SBE_ERROR(SBE_FUNC"putscom failure data, "
                          "scomAddr[0x%08X%08X], "
                          "scomData[0x%08X%08X]",
                          l_putScomReqMsg.hiAddr,
                          l_putScomReqMsg.lowAddr,
                          SBE::higher32BWord(l_scomData),
                          SBE::lower32BWord(l_scomData));
            l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
            l_secStatus  = l_rc;
        }

        // Build the response header packet

        l_hdr.setStatus(l_primStatus, l_secStatus);
        l_rc = sbeDsSendRespHdr(l_hdr, &l_ffdc);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }

    } while(false);

    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}


//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
uint32_t sbeModifyScom (uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeModifyScom "
    SBE_ENTER(SBE_FUNC);

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;

    sbeModifyScomReqMsg_t l_modifyScomMsg;

    do
    {
        uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = SBE_GLOBAL->sbeCmdRespHdr.sec_status ;

        // Will attempt to dequeue the following entries:
        // Entry 1 : Operation Mode
        // Entry 2 : Scom Register Address (0..31)
        // Entry 3 : Scom Register Address (32..63)
        // Entry 4 : Modifying Data (0..31)
        // Entry 5 : Modifying Data (32..63)
        // Entry 6 : EOT entry at the end

        uint32_t  l_len2dequeue  = sizeof(l_modifyScomMsg)/sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, (uint32_t *)&l_modifyScomMsg);

        // If FIFO access failure
        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
        {
            // Let command processor routine to handle the RC.
            break;
        }

        sbeRespGenHdr_t l_hdr;
        l_hdr.init();
        sbeResponseFfdc_t l_ffdc;

        // Modifying Data
        uint64_t l_modifyingData = l_modifyScomMsg.getModifyingData();

        SBE_DEBUG(SBE_FUNC"OpMode[0x%02X], modifyingData[0x%016X]",
                    l_modifyScomMsg.opMode,
                    SBE::higher32BWord(l_modifyingData),
                    SBE::lower32BWord(l_modifyingData));

        // The following steps need to be done as part of this command :
        //    1. Read Register Data (getscom)
        //    2. 'AND' the Mask with the data read from register
        //    3. 'OR' the modifying data with the result of step 2
        //    4. Write the result of step 3 into the register (putscom)
        do
        {
                // Check for a valid OpMode
                if ( (l_modifyScomMsg.opMode != SBE_MODIFY_MODE_OR)   &&
                     (l_modifyScomMsg.opMode != SBE_MODIFY_MODE_AND)  &&
                     (l_modifyScomMsg.opMode != SBE_MODIFY_MODE_XOR) )
                {
                    // Invalid Data passed
                    SBE_ERROR(SBE_FUNC"Invalid OpMode");
                    l_primStatus = SBE_PRI_INVALID_DATA;
                    l_secStatus  = SBE_SEC_GENERIC_FAILURE_IN_EXECUTION;
                    break;
                }

                uint64_t l_addr = ( (uint64_t) l_modifyScomMsg.hiAddr << 32) |
                                               l_modifyScomMsg.lowAddr;
                uint64_t l_scomData = 0;
                SBE_DEBUG(SBE_FUNC"scomAddr[0x%08X%08X]",
                              l_modifyScomMsg.hiAddr, l_modifyScomMsg.lowAddr);
                l_rc = checkIndirectAndDoScom(true, l_addr,
                                      l_scomData, &l_ffdc);

                if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL) // scom failed
                {
                    SBE_ERROR(SBE_FUNC"getscom failed,"
                        " ScomAddress[0x%08X %08X]",
                        l_modifyScomMsg.hiAddr, l_modifyScomMsg.lowAddr);
                    l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
                    l_secStatus  = l_rc;
                    break;
                }

                if (l_modifyScomMsg.opMode == SBE_MODIFY_MODE_OR)
                {
                    l_modifyingData |= l_scomData;
                }
                else if (l_modifyScomMsg.opMode == SBE_MODIFY_MODE_AND)
                {
                    l_modifyingData &= l_scomData;
                }
                else
                {
                    l_modifyingData ^= l_scomData;
                }

                // Write the modified data
                l_rc = checkIndirectAndDoScom(false, l_addr,
                                      l_modifyingData, &l_ffdc);

                if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL) // scom failed
                {
                    SBE_ERROR(SBE_FUNC"putscom failed,"
                        " ScomAddress[0x%08X%08X]",
                        l_modifyScomMsg.hiAddr, l_modifyScomMsg.lowAddr);
                    SBE_ERROR(SBE_FUNC"modifyingData[0x%08X%08X]",
                              SBE::higher32BWord(l_modifyingData),
                              SBE::lower32BWord(l_modifyingData));
                    l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
                    l_secStatus  = l_rc;
                    break;
                }
        } while (false);

        // Build the response header packet

        l_hdr.setStatus(l_primStatus, l_secStatus);
        l_rc = sbeDsSendRespHdr(l_hdr, &l_ffdc);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }

    } while(false);

    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}

/////////////////////////////////////////////////////
//////////////////////////////////////////////////////
uint32_t sbePutScomUnderMask (uint8_t *i_pArg)
{
    #define SBE_FUNC " sbePutScomUnderMask "
    SBE_ENTER(SBE_FUNC);

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    sbePutScomUnderMaskReqMsg_t l_putScomUmaskMsg;

    do
    {
        uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = SBE_GLOBAL->sbeCmdRespHdr.sec_status ;

        // Will attempt to dequeue the following entries:
        // Entry 1 : Scom Register Address (0..31)
        // Entry 2 : Scom Register Address (32..63)
        // Entry 3 : Modifying Data (0..31)
        // Entry 4 : Modifying Data (32..63)
        // Entry 5 : Mask Data (0..31)
        // Entry 6 : Mask Data (32..63)
        // Entry 7 : EOT entry at the end

        uint32_t  l_len2dequeue  = sizeof(l_putScomUmaskMsg)/sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue,
                                  (uint32_t *)&l_putScomUmaskMsg);

        // If FIFO access failure
        if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
        {
            // Let command processor routine to handle the RC.
            break;
        }

        sbeRespGenHdr_t l_hdr;
        l_hdr.init();
        sbeResponseFfdc_t l_ffdc;

        SBE_DEBUG(SBE_FUNC"scomAddr[0x%08X%08X],"
                     "modifyingData[0x%08X%08X]",
                      l_putScomUmaskMsg.hiAddr,
                      l_putScomUmaskMsg.lowAddr,
                      l_putScomUmaskMsg.hiInputData,
                      l_putScomUmaskMsg.lowInputData);
        SBE_INFO(SBE_FUNC"maskData[0x%08X%08X]",
                      l_putScomUmaskMsg.hiMaskData,
                      l_putScomUmaskMsg.lowMaskData);

        // PutScomUnderMask formula:
        // dest_reg = (dest_reg & ~input_mask) | (input_data & input_mask)

        do
        {
            uint64_t l_scomData = 0;

            uint64_t l_addr = ( (uint64_t) l_putScomUmaskMsg.hiAddr << 32) |
                                           l_putScomUmaskMsg.lowAddr;
            l_rc = checkIndirectAndDoScom(true, l_addr,
                                          l_scomData, &l_ffdc);

            if (l_rc == SBE_SEC_OPERATION_SUCCESSFUL) // scom success
            {
                l_putScomUmaskMsg.getScomData(l_scomData);

                // Write the modified data
                l_rc = checkIndirectAndDoScom(false, l_addr,
                                          l_scomData, &l_ffdc);
            }

            if (l_rc != SBE_SEC_OPERATION_SUCCESSFUL) // scom failed
            {
                SBE_ERROR(SBE_FUNC"scom failed, "
                    "ScomAddress[0x%08X%08X]",
                    l_putScomUmaskMsg.hiAddr,
                    l_putScomUmaskMsg.lowAddr);
                SBE_ERROR(SBE_FUNC"modifyingData[0x%08X%08X]"
                    "maskData[0x%08X%08X]",
                    l_putScomUmaskMsg.hiInputData,
                    l_putScomUmaskMsg.lowInputData,
                    l_putScomUmaskMsg.hiMaskData,
                    l_putScomUmaskMsg.lowMaskData);

                l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
                l_secStatus  = l_rc;
                break;
            }
        } while (false);

        // Build the response header packet
        l_hdr.setStatus(l_primStatus, l_secStatus);
        l_rc = sbeDsSendRespHdr(l_hdr, &l_ffdc);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }
    } while(false);

    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}

/////////////////////////////////////////////////////
//////////////////////////////////////////////////////
uint32_t sbeMultiScom (uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeMultiScom "
    return 0;
    #undef SBE_FUNC
}

OpenPOWER on IntegriCloud