summaryrefslogtreecommitdiffstats
path: root/src/occ_405/cmdh/cmdh_thread.c
blob: f2814a8fb2f810d344e6fbb6b0b62b041d18b954 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/cmdh/cmdh_thread.c $                              */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,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 "ssx.h"
#include "ssx_io.h"
#include "simics_stdio.h"
#include "errl.h"
#include "trac.h"
#include <thread.h>
#include <threadSch.h>
#include "state.h"
#include <cmdh_fsp.h>

eCmdhWakeupThreadMask G_cmdh_thread_wakeup_mask;

extern uint8_t G_occ_interrupt_type;

// Function Specification
//
// Name: Cmd_Hndl_thread_routine
//
// Description: This needs to be moved to separate file after we add cmd handler
//              thread support
//
// End Function Specification
void Cmd_Hndl_thread_routine(void *arg)
{
#define OCC_RESP_READY_ALERT_TIMEOUT_ATTEMPTS 5
    int l_rc = 0;
    errlHndl_t l_errlHndl = NULL;

    CHECKPOINT(CMDH_THREAD_STARTED);
    CMDH_TRAC_INFO("Command Handler Thread Started ... " );

    // ------------------------------------------------
    // Initialize HW for FSP Comm
    // ------------------------------------------------
    l_errlHndl = cmdh_fsp_init();
    if(l_errlHndl)
    {
        // Mark Errl as committed, so FSP knows right away we are having
        // problems with Attention, if that is the cause of the error.
        commitErrl(&l_errlHndl);
    }

    CHECKPOINT(FSP_COMM_INITIALIZED);

    // Only send this first attention if FSP is present
    if(G_occ_interrupt_type == FSP_SUPPORTED_OCC)
    {
        // ------------------------------------------------
        // Send 'Service' Attention to signal that we are
        // ready to accept commands from FSP.
        // ------------------------------------------------
        cmdh_fsp_attention( OCC_ALERT_FSP_SERVICE_REQD );

        CHECKPOINT(FIRST_FSP_ATTN_SENT);
    }

    // ------------------------------------------------
    // Loop forever, handling FSP commands
    // ------------------------------------------------
    while(1)
    {
        // ------------------------------------------------
        // Block, Waiting on sem for a doorbell from FSP
        // ------------------------------------------------
        l_rc = cmdh_thread_wait_for_wakeup(); // Blocking Call

        // ------------------------------------------------
        // Handle the command
        // ------------------------------------------------
        if(SSX_OK == l_rc)
        {
            if( CMDH_WAKEUP_FSP_COMMAND & G_cmdh_thread_wakeup_mask )
            {
                clearCmdhWakeupCondition(CMDH_WAKEUP_FSP_COMMAND);

                // Handle the command that TMGT just sent to OCC
                l_errlHndl = cmdh_fsp_cmd_hndler();

                // Commit an error if we get one passed back, do it before
                // we tell the FSP we have a response ready
                if(NULL != l_errlHndl)
                {
                    commitErrl(&l_errlHndl);
                }

                // Check is the sender is FSP
                if(G_fsp_msg.doorbell[0] == ATTN_SENDER_ID_FSP)
                {
                    // Tell the FSP we have a response ready for them.
                    // Try to send this for 500ms before giving up
                    cmdh_fsp_attention_withRetry(OCC_ALERT_FSP_RESP_READY, 500);
                }
            }

            if (CMDH_WAKEUP_FSP_ATTENTION_ALERT & G_cmdh_thread_wakeup_mask)
            {
                clearCmdhWakeupCondition(CMDH_WAKEUP_FSP_ATTENTION_ALERT);

                // Tell the FSP we have something they need to come check on.
                // Try to send this for 500ms, before giving up
                cmdh_fsp_attention_withRetry(OCC_ALERT_FSP_SERVICE_REQD, 500);
            }

            if (CMDH_WAKEUP_FSP_CHECKSTOP_ALERT & G_cmdh_thread_wakeup_mask)
            {
                clearCmdhWakeupCondition(CMDH_WAKEUP_FSP_CHECKSTOP_ALERT);

                // Tell the FSP we have something they need to come check on.
                // Try to send this for 500ms, before giving up
                cmdh_fsp_attention_withRetry(OCC_ALERT_SYS_CHECKSTOP, 500);
            }

        }
    }

}
OpenPOWER on IntegriCloud