summaryrefslogtreecommitdiffstats
path: root/src/usr/fapi2/test/fapi2SpdTestCxx.H
blob: d033401e82fb00c903bd4bccbfe9ef3c4c1b1878 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/fapi2/test/fapi2SpdTestCxx.H $                        */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */
#ifndef __SPDTEST_H
#define __SPDTEST_H

/**
 *  @file spdtest.H
 *
 *  @brief Test cases for SPD code
 */
#include <sys/time.h>

#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/driverif.H>
#include <fapi2_spd_access.H>
#include <vpd/spdenums.H>

using namespace TARGETING;

void getDIMMTargets ( TargetHandleList & o_dimmList )
{
    // Get Dimm list.
    getAllLogicalCards( o_dimmList,
                        TARGETING::TYPE_DIMM );
    return;
}

class SPDTest: public CxxTest::TestSuite
{
    public:

      /**
       * @brief Test SPD get Interface DIMMs.
       */
      void testGetSPD ( void )
      {
          fapi2::ReturnCode l_rc;
          size_t l_spdSize = 0;
          uint8_t * l_blobData = NULL;

          FAPI_INF( "testGetSPD - Enter" );

          // Get DIMM Targets
          TargetHandleList dimmList;
          getDIMMTargets( dimmList );

          // Should get atleast one
          if( ( 0 == dimmList.size() ) ||
              ( NULL == dimmList[0] ) )
          {
              TS_FAIL( "testGetSPD- No DIMMs found!");
          }

          for( auto l_tDimm : dimmList )
          {

              // convert to fapi2 target
              fapi2::Target<fapi2::TARGET_TYPE_DIMM> l_fDimm(l_tDimm);

              // SPD interface call with NULL blob to get size data
              l_rc = fapi2::getSPD(l_fDimm, NULL, l_spdSize);

              // Expect to return the size or non failure
              if( !l_spdSize || (l_rc != fapi2::FAPI2_RC_SUCCESS) )
              {
                  TS_FAIL("testGetSPD: Failed getting the size of the mem buffer - Dimm %.8X", TARGETING::get_huid(l_tDimm));
                  continue;
              }

              //  allocate the blob data of mem size length to hold data
              l_blobData = reinterpret_cast<uint8_t *>(malloc(l_spdSize));
              memset(l_blobData,0,l_spdSize);

              l_rc = fapi2::getSPD(l_fDimm,l_blobData, l_spdSize);
              if ( l_rc != fapi2::FAPI2_RC_SUCCESS )
              {
                  TS_FAIL( "testGetSPD- Failed to read data from DIMM with HUID= 0x%x",
                           TARGETING::get_huid(l_tDimm));
                  continue;
              }

              uint8_t l_memModule = 0x0;
              size_t l_memSize = sizeof(uint8_t);

              auto l_errl = deviceRead(l_tDimm,
                                       (void *)&l_memModule,
                                       l_memSize,
                                       DEVICE_SPD_ADDRESS(SPD::MODULE_TYPE));

              if ( l_errl )
              {
                  TS_FAIL( "testGetSPD- Failed to deviceRead with HUID= 0x%x",
                           TARGETING::get_huid(l_tDimm));
                  continue;
              }

              uint8_t l_memGen = 0x0;
              l_errl = deviceRead(l_tDimm,
                                  (void *)&l_memGen,
                                  l_memSize,
                                  DEVICE_SPD_ADDRESS(SPD::BASIC_MEMORY_TYPE));

              if ( l_errl )
              {
                  TS_FAIL( "testGetSPD- Failed to deviceRead with HUID= 0x%x",
                           TARGETING::get_huid(l_tDimm));
                  continue;
              }

              // figure out the expected size based on the memory type
              size_t l_compareSize = 0;
              if( (l_memModule == SPD::MEM_DDIMM) && (l_memGen == SPD::MEM_DDR4) )
              {
                  l_compareSize = SPD::OCMB_SPD_EFD_COMBINED_SIZE;
              }
              else if( (l_memModule != SPD::MEM_DDIMM) && (l_memGen == SPD::MEM_DDR4) )
              {
                  l_compareSize = SPD::DDR4_SPD_SIZE;
              }
              else if( l_memGen == SPD::MEM_DDR3 )
              {
                  l_compareSize = SPD::DDR3_SPD_SIZE;
              }
              else
              {
                  TS_FAIL( "testGetSPD - Unknown memory type for %.8X : module=0x%X, gen=0x%X",
                           TARGETING::get_huid(l_tDimm), l_memModule, l_memGen );
                  continue;
              }

              if( l_compareSize != l_spdSize )
              {
                  TS_FAIL( "testGetSPD - Wrong SPD size for %.8X : module=0x%X, gen=0x%X, exp=%d, act=%d",
                           TARGETING::get_huid(l_tDimm), l_memModule, l_memGen,
                           l_compareSize, l_spdSize);
                  continue;
              }

              FAPI_DBG("getSPD: SPD data for DIMM with HUID=0x%.8X Size %d Blob %d",
                       TARGETING::get_huid(l_tDimm),
                       l_spdSize,
                       l_blobData);
          }

          if( NULL != l_blobData )
          {
              free( l_blobData );
              l_blobData = NULL;
          }

          FAPI_INF( "testGetSPD - Exit" );
      }

};

#endif
OpenPOWER on IntegriCloud