summaryrefslogtreecommitdiffstats
path: root/src/usr/expaccess/expscom_utils.C
blob: c4818379ca08ed9aae7c2e62db0bfdddefef51aa (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/expaccess/expscom_utils.C $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2018,2019                        */
/* [+] 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                                                     */
/**
 *  @file expscom_utls.C
 *
 *  @brief Provides the common utility functions for i2c and mmio
 *         Explorer OCMB scom drivers
 */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <errl/errlmanager.H>        // errlCommit
#include <errl/errludtarget.H>       // ErrlUserDetailsTarget
#include <devicefw/driverif.H>       // OperationType
#include <expscom/expscom_reasoncodes.H> // ReasonCodes/ModuleIds
#include "expscom_trace.H" //g_trac_expscom
#include "expscom_utils.H" //validateInputs

namespace EXPSCOM
{

constexpr uint64_t FIRST_4_BYTES = 0xFFFFFFFF00000000;

///////////////////////////////////////////////////////////////////////////////
// See header file for doxygen documentation
///////////////////////////////////////////////////////////////////////////////
errlHndl_t validateInputs(DeviceFW::OperationType i_opType,
                          const TARGETING::Target* i_target,
                          size_t i_buflen,
                          uint64_t i_scomAddr)
{
    errlHndl_t l_err = nullptr;
    uint32_t l_commonPlid = 0;  // If there are multiple issues found link logs with first

    // Verify that the target is of type OCMB_CHIP
    TARGETING::ATTR_TYPE_type l_targetType =
                    i_target->getAttr<TARGETING::ATTR_TYPE>();

    // Only target we can perform ocmb scoms on are OCMB chip targets
    if( l_targetType != TARGETING::TYPE_OCMB_CHIP )
    {
        TRACFCOMP( g_trac_expscom, ERR_MRK "validateInputs> Invalid target type : l_targetType=0x%X", l_targetType );
        /*@
          * @errortype
          * @moduleid     EXPSCOM::MOD_OCMB_UTILS
          * @reasoncode   EXPSCOM::RC_INVALID_MODEL_TYPE
          * @userdata1    SCOM Address
          * @userdata2    Model Type
          * @devdesc      validateInputs> Invalid target type (!= OCMB_CHIP)
          * @custdesc     A problem occurred during the IPL of the system:
          *               Invalid target type for a SCOM operation.
          */
        l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                        EXPSCOM::MOD_OCMB_UTILS,
                                        EXPSCOM::RC_INVALID_MODEL_TYPE,
                                        i_scomAddr,
                                        l_targetType,
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

        l_err->collectTrace(EXPSCOM_COMP_NAME);
        ERRORLOG::ErrlUserDetailsTarget(i_target,"SCOM Target").
          addToLog(l_err);
        l_commonPlid = l_err->plid();
    }

    // The address passed to the OCMB scom functions is really only 32 bits
    //  just to be safe make sure that first 4 bytes are 0s
    if( i_scomAddr & FIRST_4_BYTES )
    {
        TRACFCOMP( g_trac_expscom,
                    ERR_MRK "validateInputs> Invalid address : i_scomAddr=0x%lx , first 32 bits should be 0's",
                    i_scomAddr );

        // If there is already an error from prev checks, then commit it
        if(l_err)
        {
            errlCommit(l_err, EXPSCOM_COMP_ID);
        }

        /*@
          * @errortype
          * @moduleid     EXPSCOM::MOD_OCMB_UTILS
          * @reasoncode   EXPSCOM::RC_INVALID_ADDRESS
          * @userdata1    SCOM Address
          * @userdata2    Target HUID
          * @devdesc      validateInputs> Invalid scom address, first 4
          *               bytes should be 0's
          * @custdesc     A problem occurred during the IPL of the system:
          *               Invalid address for a SCOM operation.
          */
        l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                        EXPSCOM::MOD_OCMB_UTILS,
                                        EXPSCOM::RC_INVALID_ADDRESS,
                                        i_scomAddr,
                                        TARGETING::get_huid(i_target),
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

        l_err->collectTrace(EXPSCOM_COMP_NAME);
        ERRORLOG::ErrlUserDetailsTarget(i_target,"SCOM Target").
          addToLog(l_err);

        if(l_commonPlid == 0)
        {
            l_commonPlid = l_err->plid();
        }
        else
        {
            l_err->plid(l_commonPlid);
        }
    }

    // The buffer passed into validateInputs should ALWAYS be 8 bytes.
    // If it is an IBM scom then all 8 bytes are used. If its microchip scom
    // then only the last 4 bytes are used.
    if (i_buflen != sizeof(uint64_t))
    {
        TRACFCOMP( g_trac_expscom, ERR_MRK "validateInputs> Invalid data length : io_buflen=%d ,"
                    " expected sizeof(uint64_t)", i_buflen );

        // If there is already an error from prev checks, then commit it
        if(l_err)
        {
            errlCommit(l_err, EXPSCOM_COMP_ID);
        }

        /*@
          * @errortype
          * @moduleid     EXPSCOM::MOD_OCMB_UTILS
          * @reasoncode   EXPSCOM::RC_INVALID_LENGTH
          * @userdata1    SCOM Address
          * @userdata2    Data Length
          * @devdesc      validateInputs> Invalid data length (!= 8 bytes)
          * @custdesc     A problem occurred during the IPL of the system:
          *               Invalid data length for a SCOM operation.
          */
        l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                        EXPSCOM::MOD_OCMB_UTILS,
                                        EXPSCOM::RC_INVALID_LENGTH,
                                        i_scomAddr,
                                        TO_UINT64(i_buflen),
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

        l_err->collectTrace(EXPSCOM_COMP_NAME);
        ERRORLOG::ErrlUserDetailsTarget(i_target,"SCOM Target").
          addToLog(l_err);

        if(l_commonPlid == 0)
        {
            l_commonPlid = l_err->plid();
        }
        else
        {
            l_err->plid(l_commonPlid);
        }
    }

    // The only valid operations are READ and WRITE if anything else comes in we need to error out
    if (i_opType != DeviceFW::READ && i_opType != DeviceFW::WRITE )
    {
        TRACFCOMP( g_trac_expscom, ERR_MRK "validateInputs> Invalid operation type : i_opType=%d", i_opType );

        if(l_err)
        {
            errlCommit(l_err, EXPSCOM_COMP_ID);
        }

        /*@
          * @errortype
          * @moduleid     EXPSCOM::MOD_OCMB_UTILS
          * @reasoncode   EXPSCOM::RC_INVALID_OPTYPE
          * @userdata1    SCOM Address
          * @userdata2    Access Type
          * @devdesc      validateInputs> Invalid OP type (!= READ or WRITE)
          * @custdesc     A problem occurred during the IPL of the system:
          *               Invalid operation type for a SCOM operation.
          */
        l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                        EXPSCOM::MOD_OCMB_UTILS,
                                        EXPSCOM::RC_INVALID_OPTYPE,
                                        i_scomAddr,
                                        i_opType,
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

        l_err->collectTrace(EXPSCOM_COMP_NAME);
        ERRORLOG::ErrlUserDetailsTarget(i_target,"SCOM Target").
          addToLog(l_err);

        if(l_commonPlid == 0)
        {
            l_commonPlid = l_err->plid();
        }
        else
        {
            l_err->plid(l_commonPlid);
        }
    }

    return l_err;
}

} // End namespace EXPSCOM
OpenPOWER on IntegriCloud