summaryrefslogtreecommitdiffstats
path: root/sbe/sbefw/sbecmdscomaccess.C
blob: 5b946ffa3d2f363bed93a17250ea08fd7f565947 (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
/*
 * @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"

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

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;

    do
    {
        uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = g_sbeCmdRespHdr.sec_status ;

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

        // @TODO via RTC : 130575
        //       Optimize both the RC handling and
        //       FIFO operation infrastructure.
        uint8_t  l_len2dequeue  = 3;
        uint32_t l_scomAddr[3] = {0};
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, &l_scomAddr[0]);

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

        // If we didn't receive EOT yet
        if ( (l_rc != SBE_FIFO_RC_EOT_ACKED)  &&
             (l_rc != SBE_FIFO_RC_EOT_ACK_FAILED) )
        {
            // We must have received unexpected data
            // on the upstream FIFO.

            // Flush upstream FIFO until EOT;
            l_len2dequeue = 1;
            l_rc = sbeUpFifoDeq_mult ( l_len2dequeue, NULL, true );

            // We will break out here to force
            // command processor routine to handle the RC.
            // If the RC indicates the receipt of EOT,
            // It would send the appropriate response
            // back into the down stream FIFO.
            // For all other failures, it would force
            // timeout the chipOp operation
            break;
        }

        // If EOT arrived prematurely
        if ( ((l_rc == SBE_FIFO_RC_EOT_ACKED)  ||
              (l_rc == SBE_FIFO_RC_EOT_ACK_FAILED))
              && (l_len2dequeue < 2) )
        {
            // We will break out here to force
            // command processor routine to respond
            // into the downstream FIFO with
            // primary response code as SBE_PRI_INVALID_DATA
            break;
        }

        uint32_t l_sbeDownFifoRespBuf[6] = {0};
        uint32_t l_pcbpibStatus = SBE_PCB_PIB_ERROR_NONE;
        uint8_t  l_len2enqueue  = 0;
        uint8_t  l_index = 0;
        // successfully dequeued two entries for
        // scom address followed by the EOT entry
        if ( ((l_rc == SBE_FIFO_RC_EOT_ACKED)  ||
              (l_rc == SBE_FIFO_RC_EOT_ACK_FAILED))
              && (l_len2dequeue == 2) )
        {
            // @TODO via RTC : 126140
            //       Support Indirect SCOM
            // Data entry 1 : Scom Register Address (0..31)
            // Data entry 2 : Register Address (32..63)
            // For Direct SCOM, will ignore entry 1

            uint64_t l_scomData = 0;
            SBE_TRACE(SBE_FUNC"scomAddr1[0x%08X]", l_scomAddr[1]);
            l_rc = getscom (0, l_scomAddr[1], &l_scomData);

            if (l_rc) // scom failed
            {
                SBE_ERROR(SBE_FUNC"getscom failed, l_rc[0x%08X]", l_rc);
                l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
                l_secStatus  = SBE_SEC_GENERIC_FAILURE_IN_EXECUTION;
                l_pcbpibStatus = l_rc;
            }

            if (!l_rc) // successful scom
            {
                SBE_TRACE(SBE_FUNC"getscom succeeds, l_scomData[0x%X]",
                                   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;
                }
                l_index = 2;
            } // end successful scom
        } // end successful dequeue

        // Build the response header packet

        uint8_t l_curIndex = l_index ;
        sbeBuildMinRespHdr(&l_sbeDownFifoRespBuf[0],
                            l_curIndex,
                            l_primStatus,
                            l_secStatus,
                            l_pcbpibStatus,
                            l_index);

        // Now enqueue into the downstream FIFO
        l_len2enqueue = ++l_curIndex - l_index;
        l_rc = sbeDownFifoEnq_mult (l_len2enqueue,
                               &l_sbeDownFifoRespBuf[l_index]);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }

    } while(false);

    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;

    do
    {
        uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status;
        uint16_t l_secStatus  = g_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

        // @TODO via RTC : 130575
        //       Optimize both the RC handling and
        //       FIFO operation infrastructure.
        uint8_t  l_len2dequeue  = 5;
        uint32_t l_scomAddr_Data[5] = {0};
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, &l_scomAddr_Data[0]);

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

        // If we didn't receive EOT yet
        if ( (l_rc != SBE_FIFO_RC_EOT_ACKED)  &&
             (l_rc != SBE_FIFO_RC_EOT_ACK_FAILED) )
        {
            // We must have received unexpected data
            // on the upstream FIFO.

            // Flush upstream FIFO until EOT;
            l_len2dequeue = 1;
            l_rc = sbeUpFifoDeq_mult ( l_len2dequeue, NULL, true );

            // We will break out here to force
            // command processor routine to handle the RC.
            // If the RC indicates the receipt of EOT,
            // It would send the appropriate response
            // back into the down stream FIFO.
            // For all other failures, it would force
            // timeout the chipOp operation
            break;
        }

        // If EOT arrived prematurely
        if ( ((l_rc == SBE_FIFO_RC_EOT_ACKED)  ||
              (l_rc == SBE_FIFO_RC_EOT_ACK_FAILED))
              && (l_len2dequeue < 4) )
        {
            // We will break out here to force
            // command processor routine to respond
            // into the downstream FIFO with
            // primary response code as SBE_PRI_INVALID_DATA
            break;
        }

        uint64_t l_scomData = 0;
        uint32_t l_sbeDownFifoRespBuf[4] = {0};
        uint32_t l_pcbpibStatus = SBE_PCB_PIB_ERROR_NONE;
        uint8_t  l_len2enqueue  = 0;
        // successfully dequeued two entries for
        // scom address followed by the EOT entry
        if ( ((l_rc == SBE_FIFO_RC_EOT_ACKED)  ||
              (l_rc == SBE_FIFO_RC_EOT_ACK_FAILED))
              && (l_len2dequeue == 4) )
        {
            // @TODO via RTC : 126140
            //       Support Indirect SCOM
            // Data entry 1 : Scom Register Address (0..31)
            // Data entry 2 : Scom Register Address (32..63)
            // Data entry 3 : Scom Register Data (0..31)
            // Data entry 4 : Scom Register Data (32..63)
            // For Direct SCOM, will ignore entry 1
            l_scomData = ((uint64_t)(l_scomAddr_Data[2])<<32)
                           | (l_scomAddr_Data[3]);

            SBE_DEBUG(SBE_FUNC"scomAddr0[0x%X]"
                              "scomAddr1[0x%X]"
                              "scomData0[0x%X]"
                              "scomData1[0x%X]",
                  l_scomAddr_Data[0], l_scomAddr_Data[1],
                  l_scomAddr_Data[2], l_scomAddr_Data[3]);

            l_rc = putscom (0, l_scomAddr_Data[1], l_scomData);

            if (l_rc) // scom failed
            {
                SBE_ERROR(SBE_FUNC"putscom failed, l_rc[0x%08X]", l_rc);
                l_primStatus = SBE_PRI_GENERIC_EXECUTION_FAILURE;
                l_secStatus  = SBE_SEC_GENERIC_FAILURE_IN_EXECUTION;
                l_pcbpibStatus = l_rc;
            }
        } // end successful dequeue

        // Build the response header packet

        uint8_t  l_curIndex = 0;
        sbeBuildMinRespHdr(&l_sbeDownFifoRespBuf[0],
                            l_curIndex,
                            l_primStatus,
                            l_secStatus,
                            l_pcbpibStatus);

        // Now enqueue into the downstream FIFO
        l_len2enqueue = ++l_curIndex;
        l_rc = sbeDownFifoEnq_mult (l_len2enqueue, &l_sbeDownFifoRespBuf[0]);
        if (l_rc)
        {
           // will let command processor routine
           // handle the failure
           break;
        }

    } while(false);

    return l_rc;
    #undef SBE_FUNC
}
OpenPOWER on IntegriCloud