summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/bus_training/io_cleanup.C
blob: 34713ad90ac226e344e8eb8b50c2821ae853edd9 (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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/bus_training/io_cleanup.C $                  */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,2014              */
/*                                                                        */
/* 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 otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
// $Id: io_cleanup.C,v 1.13 2014/05/16 18:23:37 dcrowell Exp $
// *!***************************************************************************
// *! (C) Copyright International Business Machines Corp. 1997, 1998
// *!           All Rights Reserved -- Property of IBM
// *!                   *** IBM Confidential ***
// *!***************************************************************************
// *! FILENAME             : io_cleanup.C
// *! TITLE                :
// *! DESCRIPTION          : Cleanup procedure for re-init loop
// *! CONTEXT              :
// *!
// *! OWNER  NAME          : Varghese, Varkey         Email: varkey.kv@in.ibm.com
// *! BACKUP NAME          : Janani Swaminathan      Email:  jaswamin@in.ibm.com
// *!
// *!***************************************************************************
// CHANGE HISTORY:
//------------------------------------------------------------------------------
// Version:|Author: | Date:  | Comment:
// --------|--------|--------|--------------------------------------------------
//   1.0   |varkeykv|07/30/11|Initial check in .
//------------------------------------------------------------------------------
#include <fapi.H>
#include "io_cleanup.H"
#include "gcr_funcs.H"



extern "C" {
     using namespace fapi;
// For clearing the FIR mask , used by io run training
// As per Irving , it should be ok to clear all FIRs here since we will scom init , also we dont touch mask values
ReturnCode clear_fir_reg(const Target &i_target,fir_io_interface_t i_chip_interface){
    ReturnCode rc;
    ecmdDataBufferBase data(64);
    FAPI_INF("io_cleanup:In the Clear FIR RW register function ");

     // use FIR AND mask register to un-mask selected bits
     rc = fapiPutScom(i_target, fir_rw_reg_addr[i_chip_interface], data);
     if (!rc.ok())
     {
         FAPI_ERR("Error writing FIR mask register (=%08X)!",
                  fir_rw_reg_addr[i_chip_interface]);
     }
    return(rc);
}

/*
 from Megan's ipl1.sh

 istep -s0..11
## forcing channel fail
getscom pu  02011C4A -pall -call -vs1
        getscom cen 0201080A -pall -call -vs1
        putscom pu 02011C4A 8000000480400000 -pall -call
        putscom cen 0201080A 8000000000000000 -pall -call
        getscom pu  02011C4A -pall -call -vs1
        getscom cen 0201080A -pall -call -vs1
## masking fir bit
putscom pu.mcs 2011843 FFFFFFFFFFFFFFFF -all
### IO reset
iotk put rx_fence=1 -t=p8:bmcs
iotk put rx_fence=1 -t=cn
iotk put ioreset_hard_bus0=111111 -t=p8:bmcs
iotk put ioreset_hard_bus0=111111 -t=cn

#exit
##clear_fir
./clear_fir.pl
### Reload
istep proc_dmi_scominit
istep dmi_scominit
##checking Zcal
iotk get tx_zcal_p_4x -t=p8:bmcs
iotk get tx_zcal_p_4x -t=cn
iotk get  tx_zcal_sm_min_val -t=p8:bmcs
iotk get tx_zcal_sm_min_val -t=cn
iotk get  tx_zcal_sm_max_val -t=p8:bmcs
iotk get tx_zcal_sm_max_val -t=cn
### Loading Zcal
iotk put tx_zcal_p_4x=00100
iotk put tx_zcal_sm_min_val=0010101
iotk put tx_zcal_sm_max_val=1000110
## Runing Zcal
istep dmi_io_dccal
## forcing channel fail
        getscom pu  02011C4A -pall -call -vs1
        getscom cen 0201080A -pall -call -vs1
        putscom pu 02011C4A 8000000480400000 -pall -call
        putscom cen 0201080A 8000000000000000 -pall -call
        getscom pu  02011C4A -pall -call -vs1
        getscom cen 0201080A -pall -call -vs1
*/

ReturnCode do_cleanup(const Target &master_target,io_interface_t master_interface,uint32_t master_group,const Target &slave_target,io_interface_t slave_interface,uint32_t slave_group)
{
     ReturnCode rc;
     uint32_t rc_ecmd = 0;
     uint8_t chip_unit = 0;
     ecmdDataBufferBase data(64);
     ecmdDataBufferBase reg_data(16),set_bits(16),clear_bits(16),temp_bits(16);

     //iotk put rx_fence=1 -t=p8:bmcs
     // No other field in this reg , so no need for RMW
     rc_ecmd = temp_bits.setBit(0);
     if(rc_ecmd)
     {
        rc.setEcmdError(rc_ecmd);
        return(rc);
     }
     rc=GCR_write(master_target, master_interface,  rx_fence_pg, master_group,0,   temp_bits, temp_bits,1,1);
     if(rc) return rc;

     //iotk put rx_fence=1 -t=cn
     rc=GCR_write(slave_target, slave_interface, rx_fence_pg, slave_group,0,   temp_bits, temp_bits,1,1);
     if(rc) return rc;

     rc = FAPI_ATTR_GET(ATTR_CHIP_UNIT_POS,
                    &master_target,
                    chip_unit);
     if (!rc.ok())
     {
     FAPI_ERR("Error retreiving MCS chiplet number!");
     return rc;
     }

     // swizzle to DMI number
     if (master_interface == CP_IOMC0_P0)
     {
          chip_unit = 3-(chip_unit % 4);
          // swap 0 and 1 due to Clock group swap in layout
          if(chip_unit==1){
               chip_unit=0;
          }
          else if(chip_unit==0){
               chip_unit=1;
          }


          FAPI_DBG("CHIP UNIT IS %d",chip_unit);

     }
     rc = fapiGetScom(master_target, scom_mode_pb_reg_addr[FIR_CP_IOMC0_P0], data);
     if (!rc.ok())
     {
         FAPI_ERR("Error Reading SCOM mode PB register for ioreset_hard_bus0 on master side(=%08X)!",
                  scom_mode_pb_reg_addr[FIR_CP_IOMC0_P0]);
          return rc;
     }

     rc_ecmd = data.setBit(2+chip_unit,1);  // Scom_mode_pb ,ioreset starts at bit 2
     if(rc_ecmd)
     {
        rc.setEcmdError(rc_ecmd);
        return(rc);
     }
     FAPI_DBG("Writing the Hard reset on PU ");
     // use FIR AND mask register to un-mask selected bits
     rc = fapiPutScom(master_target, scom_mode_pb_reg_addr[FIR_CP_IOMC0_P0], data);
     if (!rc.ok())
     {
         FAPI_ERR("Error writing SCOM mode PB register for ioreset_hard_bus0 on master side(=%08X)!",
                  scom_mode_pb_reg_addr[FIR_CP_IOMC0_P0]);
          return rc;
     }

     rc_ecmd = data.flushTo0();
     if(rc_ecmd)
     {
        rc.setEcmdError(rc_ecmd);
        return(rc);
     }
     // Centaur is always bus0 in reset register
     if(slave_interface == CEN_DMI){
          chip_unit=0;
     }
     rc = fapiGetScom(slave_target, scom_mode_pb_reg_addr[FIR_CEN_DMI], data);
     if (!rc.ok())
     {
         FAPI_ERR("Error Reading SCOM mode PB register for ioreset_hard_bus0 on Slave side(=%08X)!",
                   scom_mode_pb_reg_addr[FIR_CEN_DMI]);
          return rc;
     }
     rc_ecmd = data.setBit(2+chip_unit,1);  // Scom_mode_pb ,ioreset starts at bit 2
     if(rc_ecmd)
     {
        rc.setEcmdError(rc_ecmd);
        return(rc);
     }
     // use FIR AND mask register to un-mask selected bits
     rc = fapiPutScom(slave_target, scom_mode_pb_reg_addr[FIR_CEN_DMI], data);
     if (!rc.ok())
     {
         FAPI_ERR("Error writing SCOM mode PB register for ioreset_hard_bus0 on Slave side(=%08X)!",
                   scom_mode_pb_reg_addr[FIR_CEN_DMI]);
          return rc;
     }
     ///////////////////////////////SW256413//////////////////////////////
     ecmdDataBufferBase rx_set_bits(16);
     ecmdDataBufferBase tx_set_bits(16);
     ecmdDataBufferBase mask_bits(  16);

     rc = FAPI_ATTR_GET(ATTR_CHIP_UNIT_POS, &master_target, chip_unit);
     if (!rc.ok()){
        FAPI_ERR("Error retreiving MCS chiplet number, while setting bus id.");
        return rc;
     }
     mask_bits.flushTo0();
     uint32_t rxbits = 0;
     uint32_t txbits = 0;
     // Tuleta has MCS4-7 corresponding to port DMI1
     // Brazos has MCS0-7 corresponding to port DMI0 and DMI1
     if(chip_unit == 0){
        rxbits = 0x0000;    //bus_id: 0 group_id: 0
        txbits = 0x0100;    //bus_id: 0 group_id: 32
     }else if(chip_unit == 1){
        rxbits = 0x0400;    //bus_id: 1 group_id: 0
        txbits = 0x0500;    //bus_id: 1 group_id: 32
     }else if(chip_unit == 2){
        rxbits = 0x0800;    //bus_id: 2 group_id: 0
        txbits = 0x0900;    //bus_id: 2 group_id: 32
     }else if(chip_unit == 3){
        rxbits = 0x0C00;    //bus_id: 3 group_id: 0
        txbits = 0x0D00;    //bus_id: 3 group_id: 32
     }else if(chip_unit == 4){
        rxbits = 0x0000;    //bus_id: 0 group_id: 0
        txbits = 0x0100;    //bus_id: 0 group_id: 32
     }else if(chip_unit == 5){
        rxbits = 0x0400;    //bus_id: 1 group_id: 0
        txbits = 0x0500;    //bus_id: 1 group_id: 32
     }else if(chip_unit == 6){
        rxbits = 0x0800;    //bus_id: 2 group_id: 0
        txbits = 0x0900;    //bus_id: 2 group_id: 32
     }else if(chip_unit == 7){
        rxbits = 0x0C00;    //bus_id: 3 group_id: 0
        txbits = 0x0D00;    //bus_id: 3 group_id: 32
     }else{      //If chip_unit is unkown, set return error
        FAPI_ERR("Invalid io_cleanup HWP invocation . MCS chiplet number is unknown while setting the bus id.");
        const fapi::Target & MASTER_TARGET = master_target;
        FAPI_SET_HWP_ERROR(rc, IO_CLEANUP_INVALID_MCS_RC);
        return rc;
     }
     rc_ecmd |= rx_set_bits.insertFromRight(rxbits, 0, 16);
     rc_ecmd |= tx_set_bits.insertFromRight(txbits, 0, 16);
     if(rc_ecmd)
     {
        rc.setEcmdError(rc_ecmd);
        return(rc);
     }
     rc = GCR_write(master_target, master_interface, rx_id1_pg, master_group, 0, rx_set_bits, mask_bits,1,1);if (rc) {return(rc);}
     rc = GCR_write(master_target, master_interface, tx_id1_pg, master_group, 0, tx_set_bits, mask_bits,1,1);if (rc) {return(rc);}
     ///////////////////////////////SW256413//////////////////////////////


    // NOW We clear FIRS.. need to see if we need to do this or some other procedure will do this . Bellows/Irving to respond

    rc = clear_fir_reg(slave_target,FIR_CEN_DMI);
     if(rc)
     {
        return(rc);
     }
    rc = clear_fir_reg(master_target,FIR_CP_IOMC0_P0);
     if(rc)
     {
        return(rc);
     }
    return rc;
}


// Cleans up for Centaur Reconfig or Abus hot plug case
ReturnCode io_cleanup(const Target &master_target,const Target &slave_target){
     ReturnCode rc;
     io_interface_t master_interface,slave_interface;
     uint32_t master_group=0;
     uint32_t slave_group=0;


     // This is a DMI/MC bus
     if( (master_target.getType() == fapi::TARGET_TYPE_MCS_CHIPLET )&& (slave_target.getType() == fapi::TARGET_TYPE_MEMBUF_CHIP)){
          FAPI_DBG("This is a DMI bus using base DMI scom address");
          master_interface=CP_IOMC0_P0; // base scom for MC bus
          slave_interface=CEN_DMI; // Centaur scom base
          master_group=3; // Design requires us to do this as per scom map and layout
          slave_group=0;
          rc=do_cleanup(master_target,master_interface,master_group,slave_target,slave_interface,slave_group);
          if(rc) return rc;
     }
     //This is an A Bus
     else if( (master_target.getType() == fapi::TARGET_TYPE_ABUS_ENDPOINT )&& (slave_target.getType() == fapi::TARGET_TYPE_ABUS_ENDPOINT)){
        // This procedure only supports DMI for now
     }
     else{
          const Target &MASTER_TARGET = master_target;
          const Target &SLAVE_TARGET = slave_target;
          FAPI_ERR("Invalid io_cleanup HWP invocation . Pair of targets dont belong to DMI or A bus instances");
          FAPI_SET_HWP_ERROR(rc, IO_CLEANUP_INVALID_INVOCATION_RC);
     }
     return rc;
}



} // extern
OpenPOWER on IntegriCloud