summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/bus_training/gcr_funcs.C
blob: 7c33441c8d50b0cd6b851e7b5f399b70d5ece67f (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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/bus_training/gcr_funcs.C $                   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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: gcr_funcs.C,v 1.12 2014/03/10 16:29:43 varkeykv Exp $
// *!***************************************************************************
// *! (C) Copyright International Business Machines Corp. 1997, 1998
// *!           All Rights Reserved -- Property of IBM
// *!                   *** IBM Confidential ***
// *!***************************************************************************
// *! FILENAME             : gcr_funcs.C
// *! TITLE                : 
// *! DESCRIPTION          : 
// *! CONTEXT              : 
// *!
// *! OWNER  NAME          : Varghese, Varkey         Email: varkeykv@in.ibm.com
// *! BACKUP NAME          : Swaminathan, Janani      Email: jaswamin@in.ibm.com
// *!
// *!***************************************************************************
// CHANGE HISTORY: 
//------------------------------------------------------------------------------
// Version:|Author: | Date:  | Comment:
// --------|--------|--------|--------------------------------------------------
//   1.0   |varkeykv|01/19/12| Initial check in to solve hostboot linker 
//------------------------------------------------------------------------------
#include <gcr_funcs.H>

using namespace fapi;
ReturnCode  GCR_read(const Target& chip_target, io_interface_t interface,GCR_sub_registers target_io_reg, uint32_t group_address,  uint32_t lane_address, ecmdDataBufferBase &databuf_16bit)
{
	ReturnCode rc;
	uint32_t rc_ecmd=0;
	ecmdDataBufferBase set_bits(16), clear_bits(16);
	rc_ecmd|=set_bits.flushTo0();
	rc_ecmd|=clear_bits.flushTo1();
   
	if(rc_ecmd)
	{
      FAPI_ERR("Unexpected error in buffer manipulation\n");
      rc.setEcmdError(rc_ecmd);
	}
	else
	{
		rc=doGCRop(chip_target, interface, gcr_op_read, target_io_reg, group_address, lane_address, set_bits, clear_bits, databuf_16bit);
        if(!rc.ok())
        {
          FAPI_ERR("Unexpected error while performing GCR OP \n");
        }
	}

	return  rc;
}
//------------------------------------------------------------------------------------------------------------------------------------
// GCR SCOM WRITE  - main api for write - do not use doGCRop directly
//------------------------------------------------------------------------------------------------------------------------------------
ReturnCode  GCR_write(const Target& chip_target, io_interface_t interface, GCR_sub_registers target_io_reg, uint32_t group_address,  uint32_t lane_address,  ecmdDataBufferBase set_bits,  ecmdDataBufferBase clear_bits, int skipCheck,int bypass_rmw)
{
	ReturnCode rc;
	uint32_t rc_ecmd=0;
	ecmdDataBufferBase databuf_16bit(16);
	rc_ecmd|=databuf_16bit.flushTo0();
        skipCheck=1; // This is redundant -- forcing to 1 
	if(rc_ecmd)
	{
      FAPI_ERR("Unexpected error in buffer manipulation\n");
      rc.setEcmdError(rc_ecmd);
	}
	else
	{
		rc=doGCRop(chip_target, interface, gcr_op_write, target_io_reg, group_address, lane_address, set_bits, clear_bits, databuf_16bit, skipCheck,bypass_rmw);
        if(!rc.ok())
        {
          FAPI_ERR("Unexpected error while performing GCR OP \n");
        }
	}
	return rc;
}

// UPPER LAYER FUNCTIONS

//------------------------------------------------------------------------------------------------------------------------------------
// generate the 64 bit scom address for the GCR
//------------------------------------------------------------------------------------------------------------------------------------
uint64_t scom_address_64bit(uint32_t gcr_addr, uint64_t gcr_data) 
{
	uint32_t rc_ecmd=0;
	ecmdDataBufferBase reg_scom_address(64), temp(64);
	temp.flushTo0();
	temp.setDoubleWord(0,gcr_data);

	// 64 bit address
	rc_ecmd|= reg_scom_address.setWord(0,temp.getWord(0));
	rc_ecmd |= reg_scom_address.setWord(1,gcr_addr);
	rc_ecmd |= reg_scom_address.setBit(0);

	if(rc_ecmd)
	{
		FAPI_ERR("io_run_training: Unexpected failure in scom_address_64bit helper func");
	}
	return(reg_scom_address.getDoubleWord(0));
}


// use GCR_read and GCR_write for reg access - not this function!!!!
/*************************************************************************************************************************/
/* gcr2 is pgp mailbox format                                                                                            */
/* gcr2        0         0         64      # total length                                                                */
/* gcr2        wr        0         1       # gcr register read/write bit (read=1, write=0, opposite of gcr0)             */
/* gcr2        reg_addr  12        9       # gcr ring (register) address (ext_addr)                                      */
/* gcr2        rxtx      21        1       # =1 for a tx group                                                           */
/* gcr2        group     22        5       # does NOT include tx/rx as leading bit                                       */
/* gcr2        lane      27        5       # lane address                                                                */
/* gcr2        data      48        16      # data                                                                        */
/* gcr2        readvalid 39        1       # read data valid bit                                                         */
/*************************************************************************************************************************/

ReturnCode  doGCRop(const Target& chip_target, 
					io_interface_t interface, 
					gcr_op read_or_write, 
					GCR_sub_registers target_io_reg, 
					uint32_t group_address,  
					uint32_t lane_address,  
					ecmdDataBufferBase set_bits,  
					ecmdDataBufferBase clear_bits, 
					ecmdDataBufferBase &databuf_16bit, 
					int skipCheck,
					int bypass_rmw) 
{
    ReturnCode rc;
    uint32_t rc_ecmd=0;
    uint64_t  scom_address64=0;
    ecmdDataBufferBase getscom_data64(64), putscom_data64(64), local_data16(16);

	do
	{
		rc_ecmd |=getscom_data64.flushTo0();
		rc_ecmd |=putscom_data64.flushTo0();
		rc_ecmd |=local_data16.flushTo0();
    
		// Generate the  gcr2_register_data  putscom data
		/* gcr2        reg_addr  12        9       # gcr ring (register) address (ext_addr)                                      */
		// align the extended address to bit (12:20)
		rc_ecmd |= getscom_data64.insert( GCR_sub_reg_ext_addr[target_io_reg], 12, 9, 23 );
		FAPI_DBG("Register Extended address = %x\n",GCR_sub_reg_ext_addr[target_io_reg]);
  
		const char *temp;
		temp=GCR_sub_reg_names[target_io_reg];
		if(temp[0] == 'T' )
		{
			// This is a TX register/field need to set the TX bit
			rc_ecmd |= getscom_data64.setBit( 21 ); // does not include leading TX bit now since we are using only RX
		}
		/* gcr2        group     22        5       # does NOT include tx/rx as leading bit                                       */
		// align the group address to bit (22:26)
		rc_ecmd |= getscom_data64.insert( group_address, 22, 5, 27); // does not include leading TX bit now since we are using only RX
    
		/* gcr2        lane      27        5       # lane address                                                                */
		// align the lane address to bit (27:31)
		rc_ecmd |=  getscom_data64.insert( lane_address, 27, 5, 27 );
		if(rc_ecmd)
		{
			FAPI_ERR("IO gcr_funcs: DataBuffer operation error occurred\n");
			rc.setEcmdError(rc_ecmd);
			break;
		}

        FAPI_DBG("ei_reg_addr_GCR_scom[interface]=%x\n",ei_reg_addr_GCR_scom[interface]);
        scom_address64 =scom_address_64bit(ei_reg_addr_GCR_scom[interface], getscom_data64.getDoubleWord(0));
        if(!bypass_rmw)
		{
           rc = fapiGetScom( chip_target, scom_address64, getscom_data64 );
        }
        else
		{
			getscom_data64.flushTo0();
        }

        if(!rc.ok())
        {
            FAPI_ERR("IO gcr_funcs:GETSCOM error occurred ********\n");
		    FAPI_ERR( "IO GCR FUNCS \tRead GCR %s, @ = %llX, Data = %08X%08X  Failed  group_address=%d\n",
            GCR_sub_reg_names[target_io_reg], scom_address64, getscom_data64.getWord(0), getscom_data64.getWord(1),group_address);
			break;
        }
		FAPI_DBG( "\tRead GCR2 %s:  GETSCOM 0x%llX %08X%08X \n",
        GCR_sub_reg_names[target_io_reg], scom_address64, getscom_data64.getWord(0), getscom_data64.getWord(1) );
		rc_ecmd|=getscom_data64.extract( local_data16,   48, 16 ); // return data on read ops -- for 54/52 onwards
          
		if(rc_ecmd)
		{
			FAPI_ERR("IO gcr_funcs: DataBuffer operation error occurred\n");
			rc.setEcmdError(rc_ecmd);
			break;
		}
		// register write operation
		if (read_or_write == gcr_op_read) 
		{
			databuf_16bit = local_data16;
			break;
		}
		// write operation
		putscom_data64 = getscom_data64;
            
		// clear the desired bits first
		databuf_16bit = databuf_16bit & clear_bits;
                
		// now set desired bits
		databuf_16bit = databuf_16bit | set_bits;
              
		// data is now 64 bits and only last 16 bits are used  48:63 = 16bits  # data  
		rc_ecmd|=putscom_data64.insert( databuf_16bit, 48, 16); //-- for model 54/52 onwards
           
		if(rc_ecmd)
		{
			FAPI_ERR("IO gcr_funcs: DataBuffer operation error occurred");
			rc.setEcmdError(rc_ecmd);
			break;
		}
		FAPI_DBG( "\tWrite GCR2 %s: PUTSCOM 0x%llX  0x%08X%08X",
		GCR_sub_reg_names[target_io_reg], scom_address64, putscom_data64.getWord(0), putscom_data64.getWord(1) );
		rc = fapiPutScom( chip_target, scom_address64, putscom_data64);
		if(!rc.ok())
		{
			FAPI_ERR("IO gcr_funcs: PUTSCOM error occurred\n");
			break;
		}
		// check the write
		if(!skipCheck)
		{
			rc = fapiGetScom( chip_target, scom_address64, getscom_data64 );
		}
		if(!rc.ok())
		{
			FAPI_ERR("IO gcr_funcs: GETSCOM error occurred\n");
			break;
		}
		rc_ecmd=local_data16.insert(getscom_data64,0,16,48);  //-- for 54/52 onwards
		if(rc_ecmd)
		{
			FAPI_ERR("IO gcr_funcs: DataBuffer operation error occurred\n");
			rc.setEcmdError(rc_ecmd);
			break;
		}
		if ( !skipCheck )
		{ 
			//add skipCheck for tx_err_inj since self resetting -- djd 2/11/11
			if ( local_data16 != databuf_16bit )
			{
				FAPI_ERR( "\t %s VALIDATE write failed: read=0x%04X  write=%04X\n",
				GCR_sub_reg_names[target_io_reg], local_data16.getHalfWord(0), databuf_16bit.getHalfWord(0) );
				ecmdDataBufferBase &READ_BUF=local_data16;
				ecmdDataBufferBase &WRITE_BUF=databuf_16bit;
				FAPI_SET_HWP_ERROR(rc, IO_GCR_WRITE_MISMATCH_RC);
			}
		}
                           
	}while(0); 
    return(rc);
}

OpenPOWER on IntegriCloud