summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/slave_sbe/proc_cen_ref_clk_enable/proc_cen_ref_clk_enable.C
blob: 7efe0c5f7a1bdde431db6d0ca2c202b366f17c62 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/slave_sbe/proc_cen_ref_clk_enable/proc_cen_ref_clk_enable.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,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                                                     */
// $Id: proc_cen_ref_clk_enable.C,v 1.4 2014/04/14 18:57:01 jmcgill Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/ipl/fapi/proc_cen_ref_clk_enable.C,v $
//------------------------------------------------------------------------------
// *|
// *! (C) Copyright International Business Machines Corp. 2012
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
// *|
// *! TITLE       : proc_cen_ref_clk_enable.C
// *! DESCRIPTION : Enable Centaur reference clocks (FAPI)
// *!
// *! OWNER  NAME  : Benedikt Geukes         Email: benedikt.geukes@de.ibm.com
// *! BACKUP NAME  : Ralph Koester           Email: rkoester@de.ibm.com
// *!
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "proc_check_master_sbe_seeprom.H"
#include "proc_cen_ref_clk_enable.H"

//------------------------------------------------------------------------------
// Function definitions
//------------------------------------------------------------------------------

extern "C"
{


//------------------------------------------------------------------------------
// Hardware Procedure
//------------------------------------------------------------------------------
// parameters: i_target            => chip target
//             i_attached_centaurs => bitmask representing attached Centaur
//                                    positions
// returns:    FAPI_RC_SUCCESS if operation was successful, else error
//------------------------------------------------------------------------------
fapi::ReturnCode proc_cen_ref_clk_enable(const fapi::Target & i_target,
                                         const uint8_t i_attached_centaurs)
{

    ecmdDataBufferBase reg_data(32);
    uint32_t           rc_ecmd = 0;
    fapi::ReturnCode   rc;
    bool               is_master = false;
    uint8_t            configured_centaurs = 0x00;
    std::vector<fapi::Target> mcs_targets;


    do
    {
        // determine chip status (master/slave) to differentiate access path to FSI GP8 register
        //   master: SCOM
        //   slave:  CFAM
        rc = proc_check_master_sbe_seeprom(i_target, is_master);
        if (!rc.ok())
        {
            FAPI_ERR("proc_cen_ref_clk_enable: Error from proc_check_master_sbe_seeprom");
            break;
        }

        FAPI_INF("proc_cen_ref_clk_enable: Target %s is %s, attached Centaurs: 0x%02X",
                 i_target.toEcmdString(), (is_master)?("master"):("slave"), i_attached_centaurs);

        // obtain set of functional MCS chiplets
        rc = fapiGetChildChiplets(i_target,
                                  fapi::TARGET_TYPE_MCS_CHIPLET,
                                  mcs_targets,
                                  fapi::TARGET_STATE_FUNCTIONAL);
        if (!rc.ok())
        {
            FAPI_ERR("proc_cen_ref_clk_enable: Error from fapiGetChildChiplets");
            break;
        }

        // loop through MCS chiplets, match with attached Centaurs
        for (std::vector<fapi::Target>::iterator i = mcs_targets.begin();
             (i != mcs_targets.end()) && !rc && !rc_ecmd;
             i++)
        {
            uint8_t mcs_unit_id = 0x00;
            uint8_t refclock_bit = 0x00;

            rc = FAPI_ATTR_GET(ATTR_CHIP_UNIT_POS,
                               &(*i),
                               mcs_unit_id);
            if (rc)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: Error querying ATTR_CHIP_UNIT_POS");
                break;
            }

            // continue to next iteration if this MCS is not connected to a Centaur
            if (!(i_attached_centaurs & (1 << ((NUM_CENTAUR_POS-1)-mcs_unit_id))))
            {
                FAPI_DBG("proc_cen_ref_clk_enable: MCS %d is not connected to a Centaur, skipping...\n", mcs_unit_id);
            }
            else
            {
                // mark that we have configured this MCS/Centaur pair
                configured_centaurs |= (1 << ((NUM_CENTAUR_POS-1)-mcs_unit_id));
                FAPI_DBG("proc_cen_ref_clk_enable: MCS %d is connected to a Centaur, configured_centaurs: %02X\n", mcs_unit_id,configured_centaurs);

                // query attribute which defines reflock bit associated with this Centaur
                rc = FAPI_ATTR_GET(ATTR_DMI_REFCLOCK_SWIZZLE,
                                   &(*i),
                                   refclock_bit);
                if (rc)
                {
                    FAPI_ERR("proc_cen_ref_clk_enable: Error querying ATTR_DMI_REFCLOCK_SWIZZLE");
                    break;
                }
                FAPI_DBG("proc_cen_ref_clk_enable: refclock_bit: %02X\n", refclock_bit);

                if ((FSI_GP8_CENTAUR_REFCLOCK_START_BIT + refclock_bit) > FSI_GP8_CENTAUR_REFCLOCK_END_BIT)
                {
                    // bit offset exceeds field range
                    FAPI_ERR("proc_cen_ref_clk_enable: Translated Centaur refclock enable bit position is out of range!");
                    const fapi::Target& PROC_TARGET = i_target;
                    const uint8_t& CENTAUR_POSITION = mcs_unit_id;
                    const uint8_t& REFCLOCK_BIT = refclock_bit;
                    FAPI_SET_HWP_ERROR(rc,
                                       RC_PROC_CEN_REF_CLK_ENABLE_SWIZZLE_ERR);
                    break;
                }

                rc_ecmd |= reg_data.setBit(FSI_GP8_CENTAUR_REFCLOCK_START_BIT+
                                           refclock_bit);
            }
        }
        if (rc)
        {
            break;
        }
        if (rc_ecmd)
        {
            FAPI_ERR("proc_cen_ref_clk_enable: Error (0x%x) setting up refclock enable OR data buffer",
                     rc_ecmd);
            rc.setEcmdError(rc_ecmd);
            break;
        }

        if (configured_centaurs != i_attached_centaurs)
        {
            FAPI_ERR("proc_cen_ref_clk_enable: Not all Centaurs marked as attached were configured");
            const fapi::Target& PROC_TARGET = i_target;
            const uint8_t& CONFIGURED_CENTAUR_POSITIONS = configured_centaurs;
            const uint8_t& ATTACHED_CENTAUR_POSITIONS = i_attached_centaurs;
            FAPI_SET_HWP_ERROR(rc,
                               RC_PROC_CEN_REF_CLK_ENABLE_CONFIG_ERR);
            break;
        }

        FAPI_INF("proc_cen_ref_clk_enable: Enable refclk for functional Centaur chips...");
        if (is_master)
        {
            ecmdDataBufferBase scom_data(64);
            rc = fapiGetScom(i_target, MBOX_FSIGP8_0x00050017, scom_data);
            if (rc)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: fapiGetScom error (MBOX_FSIGP8_0x00050017)");
                break;
            }
            
            rc_ecmd |= scom_data.setOr(reg_data.getWord(0), 0, 32);
            if (rc_ecmd)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: Error (0x%x) setting up FSI GP8 write data buffer (SCOM)",
                         rc_ecmd);
                rc.setEcmdError(rc_ecmd);
                break;
            }

            rc = fapiPutScom(i_target, MBOX_FSIGP8_0x00050017, scom_data);
            if (rc)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: fapiPutScom error (MBOX_FSIGP8_0x00050017)");
                break;
            }
        }
        else
        {
            ecmdDataBufferBase cfam_data(32);
            rc = fapiGetCfamRegister(i_target, CFAM_FSI_GP8_0x00002817, cfam_data);
            if (rc)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: fapiGetCfamRegister error (CFAM_FSI_GP8_0x00001017)");
                break;
            }
            
            rc_ecmd |= cfam_data.setOr(reg_data.getWord(0), 0, 32);
            if (rc_ecmd)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: Error (0x%x) setting up FSI GP8 write data buffer (CFAM)",
                         rc_ecmd);
                rc.setEcmdError(rc_ecmd);
                break;
            }

            rc = fapiPutCfamRegister(i_target, CFAM_FSI_GP8_0x00002817, cfam_data);
            if (rc)
            {
                FAPI_ERR("proc_cen_ref_clk_enable: fapiPutCfamRegister error (CFAM_FSI_GP8_0x00001017)");
                break;
            }
        }
    } while(0);  // end do

    // mark function exit
    FAPI_INF("proc_cen_ref_clk_enable: Exit");
    return rc;
}  // end FAPI procedure proc_cen_ref_clk_enable


} // extern "C"
OpenPOWER on IntegriCloud