summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/dimmBadDqBitmapFuncs.C
blob: e9d413adc01ec970d55f7c59b6fb5ac514540ac1 (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwpf/hwp/dimmBadDqBitmapFuncs.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2012
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/**
 *  @file dimmBadDqBitmapFuncs.C
 *
 *  @brief FW Team Utility functions that accesses the Bad DQ Bitmap.
 */

/*
 * Change Log ******************************************************************
 * Flag     Defect/Feature  User        Date        Description
 * ------   --------------  ----------  ----------- ----------------------------
 *                          mjjones     02/17/2012  Created.
 */

#include <dimmBadDqBitmapFuncs.H>
#include <string.h>

extern "C"
{

// TODO
// For the dimmGetBadDqBitmap and dimmSetBadDqBitmap funcs, the original plan to
// get/set the bitmap was to get/set a HWPF attribute called ATTR_BAD_DQ_BITMAP.
// This would automatically call the dimmBadDqBitmapAccessHwp HWP which would
// access the ATTR_SPD_BAD_DQ_DATA HWPF attribute and decode the data. However,
// automatically bridging an attribute request to a HWP turns out to be
// difficult due to the fact that the FAPI_ATTR_GET macro returns a ReturnCode
// and the FAPI_EXEC_HWP macro takes a ReturnCode as parameter. For now call the
// HWP directly and revisit later


//------------------------------------------------------------------------------
// Utility function to check parameters and find a DIMM target
//------------------------------------------------------------------------------
fapi::ReturnCode dimmBadDqCheckParamFindDimm(const fapi::Target & i_mba,
                                             const uint8_t i_port,
                                             const uint8_t i_dimm,
                                             const uint8_t i_rank,
                                             fapi::Target & o_dimm)
{
    fapi::ReturnCode l_rc;

    if ((i_port >= DIMM_DQ_MAX_MBA_PORTS) ||
        (i_dimm >= DIMM_DQ_MAX_MBAPORT_DIMMS) ||
        (i_rank >= DIMM_DQ_MAX_DIMM_RANKS))
    {
        FAPI_ERR("dimmBadDqCheckParams: Bad parameter. %d:%d:%d", i_port,
                 i_dimm, i_rank);
        const uint8_t & FFDC_PORT = i_port;
        const uint8_t & FFDC_DIMM = i_dimm;
        const uint8_t & FFDC_RANK = i_rank;
        FAPI_SET_HWP_ERROR(l_rc, RC_BAD_DQ_DIMM_BAD_PARAM);
    }
    else
    {
        std::vector<fapi::Target> l_dimms;

        // Get the functional DIMMs associated with the MBA chiplet
        l_rc = fapiGetAssociatedDimms(i_mba, l_dimms);

        if (l_rc)
        {
            FAPI_ERR("dimmBadDqFindDimm: Error from fapiGetAssociatedDimms");
        }
        else
        {
            // Find the DIMM with the correct MBA port/dimm
            uint8_t i = 0;
            uint8_t l_port = 0;
            uint8_t l_dimm = 0;

            for (; i < l_dimms.size(); i++)
            {
                l_rc = FAPI_ATTR_GET(ATTR_MBA_PORT, &(l_dimms[i]), l_port);

                if (l_rc)
                {
                    FAPI_ERR("dimmBadDqFindDimm: Error getting ATTR_MBA_PORT for dimm");
                    break;
                }
                else if (l_port == i_port)
                {
                    l_rc = FAPI_ATTR_GET(ATTR_MBA_DIMM, &(l_dimms[i]), l_dimm);

                    if (l_rc)
                    {
                        FAPI_ERR("dimmBadDqFindDimm: Error getting ATTR_MBA_DIMM for dimm");
                        break;
                    }
                    else if (l_dimm == i_dimm)
                    {
                        o_dimm = l_dimms[i];
                        break;
                    }
                }            
            }

            if (!l_rc)
            {
                if (i == l_dimms.size())
                {
                    FAPI_ERR("dimmBadDqFindDimm: Did not find DIMM for %s:%d:%d",
                             i_mba.toEcmdString(), i_port, i_dimm);
                    const fapi::Target & FFDC_MBA_TARGET = i_mba;
                    const uint8_t & FFDC_PORT = i_port;
                    const uint8_t & FFDC_DIMM = i_dimm;
                    FAPI_SET_HWP_ERROR(l_rc, RC_BAD_DQ_DIMM_NOT_FOUND);
                }
            }
        }
    }

    return l_rc;
}

//------------------------------------------------------------------------------
fapi::ReturnCode dimmGetBadDqBitmap(const fapi::Target & i_mba,
                                    const uint8_t i_port,
                                    const uint8_t i_dimm,
                                    const uint8_t i_rank,
                                    uint8_t (&o_data)[DIMM_DQ_RANK_BITMAP_SIZE])
{
    FAPI_INF(">>dimmGetBadDqBitmap. %s:%d:%d:%d", i_mba.toEcmdString(), i_port,
             i_dimm, i_rank);

    fapi::ReturnCode l_rc;

    // Check parameters and find the DIMM Target
    fapi::Target l_dimm;
    l_rc = dimmBadDqCheckParamFindDimm(i_mba, i_port, i_dimm, i_rank, l_dimm);

    if (!l_rc)
    {
        // Get the Bad DQ bitmap by calling the dimmBadDqBitmapAccessHwp HWP.
        // Use a heap based array to avoid large stack alloc
        uint8_t (&l_dqBitmap)[DIMM_DQ_MAX_DIMM_RANKS][DIMM_DQ_RANK_BITMAP_SIZE] =
            *(reinterpret_cast<uint8_t(*)[DIMM_DQ_MAX_DIMM_RANKS][DIMM_DQ_RANK_BITMAP_SIZE]>
                (new uint8_t[DIMM_DQ_MAX_DIMM_RANKS*DIMM_DQ_RANK_BITMAP_SIZE]));
       
        FAPI_EXEC_HWP(l_rc, dimmBadDqBitmapAccessHwp, l_dimm, l_dqBitmap, true);

        if (l_rc)
        {
            FAPI_ERR("dimmGetBadDqBitmap: Error from dimmBadDqBitmapAccessHwp");
        }
        else
        {
            memcpy(o_data, l_dqBitmap[i_rank], DIMM_DQ_RANK_BITMAP_SIZE);
        }

        delete [] &l_dqBitmap;
    }

    FAPI_INF("<<dimmGetBadDqBitmap");
    return l_rc;
}

//------------------------------------------------------------------------------
fapi::ReturnCode dimmSetBadDqBitmap(
    const fapi::Target & i_mba,
    const uint8_t i_port,
    const uint8_t i_dimm,
    const uint8_t i_rank,
    const uint8_t (&i_data)[DIMM_DQ_RANK_BITMAP_SIZE])
{
    FAPI_INF(">>dimmSetBadDqBitmap. %s:%d:%d:%d", i_mba.toEcmdString(), i_port, i_dimm, i_rank);

    fapi::ReturnCode l_rc;

    // Check parameters and find the DIMM Target
    fapi::Target l_dimm;
    l_rc = dimmBadDqCheckParamFindDimm(i_mba, i_port, i_dimm, i_rank, l_dimm);

    if (!l_rc)
    {
        // Get the Bad DQ bitmap by calling the dimmBadDqBitmapAccessHwp HWP.
        // Use a heap based array to avoid large stack alloc
        uint8_t (&l_dqBitmap)[DIMM_DQ_MAX_DIMM_RANKS][DIMM_DQ_RANK_BITMAP_SIZE] =
            *(reinterpret_cast<uint8_t(*)[DIMM_DQ_MAX_DIMM_RANKS][DIMM_DQ_RANK_BITMAP_SIZE]>
                (new uint8_t[DIMM_DQ_MAX_DIMM_RANKS*DIMM_DQ_RANK_BITMAP_SIZE]));

        FAPI_EXEC_HWP(l_rc, dimmBadDqBitmapAccessHwp, l_dimm, l_dqBitmap, true);

        if (l_rc)
        {
            FAPI_ERR("dimmSetBadDqBitmap: Error from dimmBadDqBitmapAccessHwp (get)");
        }
        else
        {
            // Add the rank bitmap to the DIMM bitmap and write the bitmap
            memcpy(l_dqBitmap[i_rank], i_data, DIMM_DQ_RANK_BITMAP_SIZE);

            FAPI_EXEC_HWP(l_rc, dimmBadDqBitmapAccessHwp, l_dimm, l_dqBitmap, false);

            if (l_rc)
            {
                FAPI_ERR("dimmSetBadDqBitmap: Error from dimmBadDqBitmapAccessHwp (set)");
            }
        }

        delete [] &l_dqBitmap;
    }


    FAPI_INF("<<dimmSetBadDqBitmap");
    return l_rc;
}

} // extern "C"
OpenPOWER on IntegriCloud