summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/nest/p9_fab_iovalid.C
blob: e99fe06bf6e1e622f2f6006ebf0cd74eede2aac5 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/nest/p9_fab_iovalid.C $               */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_fab_iovalid.C
/// @brief Manage fabric link iovalid controls (FAPI2)
///
/// @author Joe McGill <jmcgill@us.ibm.com>
///

//
// *HWP HWP Owner: Joe McGill <jmcgill@us.ibm.com>
// *HWP FW Owner: Thi Tran <thi@us.ibm.com>
// *HWP Team: Nest
// *HWP Level: 2
// *HWP Consumed by: HB,FSP
//

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <p9_fab_iovalid.H>
#include <p9_fbc_utils.H>


//------------------------------------------------------------------------------
// Constant definitions
//------------------------------------------------------------------------------
const uint8_t IOVALID_FIELD_NUM_BITS = 2;


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

///
/// @brief Manipulate iovalid/FIR settings for a single fabric link
///
/// @param[in] i_target Reference to processor chip target
/// @param[in] i_ctl Reference to link control structure
/// @param[op] i_set_not_clear Define iovalid operation (true=set, false=clear)
/// @return fapi::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
fapi2::ReturnCode
p9_fab_iovalid_update_link(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target,
                           const p9_fbc_link_ctl_t& i_ctl,
                           const bool i_set_not_clear)
{
    FAPI_DBG("Start");

    // form data buffers for iovalid/RAS FIR mask updates
    fapi2::buffer<uint64_t> l_iovalid_mask;
    fapi2::buffer<uint64_t> l_ras_fir_mask;

    if (i_set_not_clear)
    {
        // set iovalid
        l_iovalid_mask.flush<0>();
        FAPI_TRY(l_iovalid_mask.setBit(i_ctl.iovalid_field_start_bit,
                                       IOVALID_FIELD_NUM_BITS));
        // clear RAS FIR mask
        l_ras_fir_mask.flush<1>();
        FAPI_TRY(l_ras_fir_mask.clearBit(i_ctl.ras_fir_field_bit));
    }
    else
    {
        // clear iovalid
        l_iovalid_mask.flush<1>();
        FAPI_TRY(l_iovalid_mask.clearBit(i_ctl.iovalid_field_start_bit,
                                         IOVALID_FIELD_NUM_BITS));
        // set RAS FIR mask
        l_ras_fir_mask.flush<0>();
        FAPI_TRY(l_ras_fir_mask.setBit(i_ctl.ras_fir_field_bit));
    }

    // use AND/OR mask registers to atomically update link specific fields
    // in iovalid/RAS FIR mask registers
    FAPI_TRY(fapi2::putScom(i_target,
                            (i_set_not_clear) ? (i_ctl.iovalid_or_addr) : (i_ctl.iovalid_clear_addr),
                            l_iovalid_mask),
             "Error writing iovalid control register!");

    FAPI_TRY(fapi2::putScom(i_target,
                            (i_set_not_clear) ? (PU_PB_CENT_SM1_EXTFIR_MASK_REG_AND) : (PU_PB_CENT_SM1_EXTFIR_MASK_REG_OR),
                            l_ras_fir_mask),
             "Error writing RAS FIR mask register!");

fapi_try_exit:
    FAPI_DBG("End");
    return fapi2::current_err;
}



fapi2::ReturnCode
p9_fab_iovalid(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target,
               const bool i_set_not_clear)
{
    FAPI_INF("Start");

    uint8_t l_x_en_attr[P9_FBC_UTILS_MAX_X_LINKS];
    uint8_t l_a_en_attr[P9_FBC_UTILS_MAX_A_LINKS];
    std::vector<std::pair<p9_fbc_link_t, uint8_t>> l_valid_links;
    std::vector<p9_fbc_link_ctl_t> l_link_ctls(P9_FBC_LINK_CTL_ARR,
            P9_FBC_LINK_CTL_ARR + (sizeof(P9_FBC_LINK_CTL_ARR) / sizeof(P9_FBC_LINK_CTL_ARR[0])));
    bool l_ctl_match_found = false;


    // read X/A link enable attributes, extract set of valid links
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_X_ATTACHED_CHIP_CNFG,
                           i_target,
                           l_x_en_attr),
             "Error from FAPI_ATTR_GET (ATTR_PROC_FABRIC_X_ATTACHED_CHIP_CNFG");

    for (uint8_t x = 0; x < P9_FBC_UTILS_MAX_X_LINKS; x++)
    {
        if (l_x_en_attr[x])
        {
            FAPI_DBG("Adding link X%d", x);
            l_valid_links.push_back(std::make_pair(XBUS, x));
        }
        else
        {
            FAPI_DBG("Skipping link X%d", x);
        }
    }

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_A_ATTACHED_CHIP_CNFG,
                           i_target,
                           l_a_en_attr),
             "Error from FAPI_ATTR_GET (ATTR_PROC_FABRIC_A_ATTACHED_CHIP_CNFG");

    for (uint8_t a = 0; a < P9_FBC_UTILS_MAX_A_LINKS; a++)
    {
        if (l_a_en_attr[a])
        {
            FAPI_DBG("Adding link A%d", a);
            l_valid_links.push_back(std::make_pair(ABUS, a));
        }
        else
        {
            FAPI_DBG("Skipping link A%d", a);
        }
    }

    // for each valid link, search vector table & call link update routine
    for (auto l_link_iter = l_valid_links.begin(); l_link_iter != l_valid_links.end(); l_link_iter++)
    {
        FAPI_DBG("Processing %s%d (action = %s)",
                 (l_link_iter->first == XBUS) ? ("X") : ("A)"),
                 l_link_iter->second,
                 (i_set_not_clear) ? ("set") : ("clear"));

        l_ctl_match_found = false;

        for (auto l_link_ctl_iter = l_link_ctls.begin();
             (l_link_ctl_iter != l_link_ctls.end()) && (!l_ctl_match_found);
             l_link_ctl_iter++)
        {
            if ((l_link_ctl_iter->link_type == l_link_iter->first) &&
                (l_link_ctl_iter->link_id == l_link_iter->second))
            {
                l_ctl_match_found = true;
                FAPI_TRY(p9_fab_iovalid_update_link(i_target,
                                                    *l_link_ctl_iter,
                                                    i_set_not_clear),
                         "Error from p9_fab_iovalid_update_link");
            }
        }

        FAPI_ASSERT(l_ctl_match_found,
                    fapi2::P9_FAB_IOVALID_TABLE_ERR().set_TARGET(i_target).
                    set_LINK(l_link_iter->first).
                    set_LINK_ID(l_link_iter->second),
                    "No match found for link");
    }

fapi_try_exit:
    FAPI_INF("End");
    return fapi2::current_err;
}
OpenPOWER on IntegriCloud