| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: niu_siu_packet.vr |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | #include <vera_defines.vrh> |
| 36 | #include <ListMacros.vrh> |
| 37 | |
| 38 | #include "niu_mem.vrh" |
| 39 | #include "smx_defines.vri" |
| 40 | #include "niu_error_dfn.vri" |
| 41 | #include "niu_cbclass.vrh" |
| 42 | #include "hostErrInjTab.vrh" |
| 43 | |
| 44 | class Csiu_packet { |
| 45 | |
| 46 | // SIU Interface Packets |
| 47 | |
| 48 | // header |
| 49 | bit [5:0] command; // bits 127:122 |
| 50 | /* |
| 51 | Command Encoding-- |
| 52 | |
| 53 | NIU to SIU |
| 54 | -- Read Request command Encoding |
| 55 | command[5] - response bit - 0 |
| 56 | command[4] - posted bit - 0 |
| 57 | command[3] - read bit - 1 |
| 58 | command[2] - WriteByteMask Active bit - 0 |
| 59 | command[1] - L2 bit - 1 |
| 60 | command[0] - NCU bit - 0 |
| 61 | |
| 62 | command = 6'h0a; |
| 63 | -- Write Request command Encoding |
| 64 | command[5] - response bit - 0 |
| 65 | command[4] - posted bit - 0 -- if ack is needed else 1 |
| 66 | command[3] - read bit - 0 |
| 67 | command[2] - WriteByteMask Active bit - 0 |
| 68 | command[1] - L2 bit - 1 |
| 69 | command[0] - NCU bit - 0 |
| 70 | |
| 71 | |
| 72 | command = 6'h12 for write ack ; command = 6'h02 - for posted writes; |
| 73 | |
| 74 | SIU to NIU |
| 75 | -- Read Response Command Encoding |
| 76 | command[5] - response bit - 1 |
| 77 | command[4] - posted bit - 0 |
| 78 | command[3] - read bit - 1 |
| 79 | command[2] - WriteByteMask Active bit - 0 |
| 80 | command[1] - L2 bit - 1 |
| 81 | command[0] - NCU bit - 0 |
| 82 | |
| 83 | command = 6'h2a; |
| 84 | -- Write Response Command Encoding |
| 85 | command[5] - response bit - 1 |
| 86 | command[4] - posted bit - 0 |
| 87 | command[3] - read bit - 0 |
| 88 | command[2] - WriteByteMask Active bit - 0 |
| 89 | command[1] - L2 bit - 1 |
| 90 | command[0] - NCU bit - 0 |
| 91 | |
| 92 | command = 6'h22; |
| 93 | |
| 94 | |
| 95 | */ |
| 96 | bit TimeOutError; // bit 82:82 |
| 97 | bit UnmappedAddressError; // bit 81:81 |
| 98 | bit UncorrectableError; // bit 80:80 |
| 99 | bit [15:0] id; // bits 79:64 |
| 100 | bit [39:0] PA; |
| 101 | bit [5:0] CtagEcc; |
| 102 | bit CP; |
| 103 | bit [1:0] AP; |
| 104 | |
| 105 | bit [127:0] header; |
| 106 | |
| 107 | |
| 108 | // payload |
| 109 | bit [63:0] data[]; |
| 110 | bit [7:0] be[]; // byte enables |
| 111 | bit [7:0] data_parity[]; |
| 112 | |
| 113 | integer NoOf8Bytes; |
| 114 | |
| 115 | task create_header () { |
| 116 | header[127:122] = command; |
| 117 | header[121:83] = 39'h0; |
| 118 | header[82] = TimeOutError; |
| 119 | header[81] = UnmappedAddressError; |
| 120 | header[80] = UncorrectableError; |
| 121 | header[61:56] = CtagEcc; |
| 122 | header[79:64] = id; |
| 123 | header[63:40] = 24'h0; |
| 124 | header[39:0] = PA; |
| 125 | } |
| 126 | |
| 127 | task parse_header( bit [127:0] h, (bit check_parity = 0) ) { |
| 128 | bit parity; |
| 129 | integer i; |
| 130 | command = h[127:122]; |
| 131 | AP = h[84:83]; |
| 132 | TimeOutError= h[82] ; |
| 133 | UnmappedAddressError = h[81]; |
| 134 | UncorrectableError = h[80] ; |
| 135 | CP = h[62]; |
| 136 | CtagEcc = h[61:56]; |
| 137 | id = h[79:64] ; |
| 138 | PA = h[39:0] ; |
| 139 | // printf(" Header - %x Command = %x \n",h,command); |
| 140 | // This should be part of checker and not here-- |
| 141 | // check_CP |
| 142 | |
| 143 | if(check_parity) { |
| 144 | parity = CP^command[0]^command[1]^command[2]^command[3]^command[4]^command[5]; |
| 145 | if(parity!==1) { |
| 146 | printf("Time:%d WARNING SIU Header - CommandParity Incorrect for ID - %x \n",TIME,h[79:64]); |
| 147 | } |
| 148 | |
| 149 | // check_AP |
| 150 | parity = 0; |
| 151 | for(i = 0 ; i < 20 ; i ++) { |
| 152 | parity = parity ^ PA[2*i]; |
| 153 | } |
| 154 | parity = parity ^ AP[0]; |
| 155 | if(parity!==1) { |
| 156 | printf("Time:%d WARNING SIU Header - AddressParity [0] Incorrect for ID - %x \n",TIME,h[79:64]); |
| 157 | } |
| 158 | parity = 0; |
| 159 | for(i = 0 ; i < 20 ; i ++) { |
| 160 | parity = parity ^ PA[2*i + 1]; |
| 161 | } |
| 162 | parity = parity ^ AP[1]; |
| 163 | if(parity!==1) { |
| 164 | printf("Time:%d WARNING SIU Header - AddressParity [1] Incorrect for ID - %x \n",TIME,h[79:64]); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | task new( integer n =8) {// default of 64 bytes |
| 171 | NoOf8Bytes = n; |
| 172 | } |
| 173 | task print(integer debug =0) { |
| 174 | integer i; |
| 175 | if(debug) { |
| 176 | printf("Csiu_packet::print: Time = %d Header = %x id = %d \n",{get_time(HI), get_time(LO)},header,id); |
| 177 | if(isReadResp() | isNPWrite()) { |
| 178 | printf("Csiu_packet::print: ID - %x Address - %x \n",getTransID(),getReqAddress()); |
| 179 | for(i =0;i< NoOf8Bytes;i++) { |
| 180 | printf("Csiu_packet::print: Data[%d] = %x \n",i,data[i]); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | function integer isReadResp(); |
| 187 | function integer isWriteAck(); |
| 188 | function integer isReadReq(); |
| 189 | function integer isNPWrite(); |
| 190 | function bit[15:0] getTransID(); |
| 191 | function bit[2:0] isPacketError(); |
| 192 | function bit [39:0] getReqAddress(); |
| 193 | task calcDataParity( bit[127:0] data, var bit[7:0] parity ) ; |
| 194 | task calcParity() ; |
| 195 | function bit[127:0] swap(bit [127:0] d); |
| 196 | function bit [5:0] calc_CtagEcc ( bit [15:0] tag); |
| 197 | |
| 198 | } |
| 199 | function bit[127:0] Csiu_packet:: swap ( bit [127:0] d) { |
| 200 | |
| 201 | integer i; |
| 202 | |
| 203 | swap [127:120] = d[7:0]; |
| 204 | swap [119:112] = d[15:8]; |
| 205 | swap [111:104] = d[23:16]; |
| 206 | swap [103:96] = d[31:24]; |
| 207 | swap [95:88] = d[39:32]; |
| 208 | swap [87:80] = d[47:40]; |
| 209 | swap [79:72] = d[55:48]; |
| 210 | swap [71:64] = d[63:56]; |
| 211 | swap [63:56] = d[71:64]; |
| 212 | swap [55:48] = d[79:72]; |
| 213 | swap [47:40] = d[87:80]; |
| 214 | swap [39:32] = d[95:88]; |
| 215 | swap [31:24] = d[103:96]; |
| 216 | swap [23:16] = d[111:104]; |
| 217 | swap [15:8] = d[119:112]; |
| 218 | swap [7:0] = d[127:120]; |
| 219 | |
| 220 | } |
| 221 | function bit[2:0] Csiu_packet::isPacketError() { |
| 222 | isPacketError = {TimeOutError,UnmappedAddressError,UncorrectableError}; |
| 223 | } |
| 224 | function integer Csiu_packet::isReadResp() { |
| 225 | isReadResp = (command === 6'h2a); |
| 226 | } |
| 227 | function integer Csiu_packet::isWriteAck() { |
| 228 | isWriteAck = command[5] & ~command[3]; |
| 229 | } |
| 230 | function integer Csiu_packet::isReadReq() { |
| 231 | isReadReq = (command === 6'ha); |
| 232 | } |
| 233 | function integer Csiu_packet::isNPWrite() { |
| 234 | isNPWrite = (command === 6'h2); |
| 235 | } |
| 236 | function bit[15:0] Csiu_packet::getTransID() { |
| 237 | getTransID = id; |
| 238 | } |
| 239 | function bit [39:0] Csiu_packet::getReqAddress() { |
| 240 | getReqAddress = PA; |
| 241 | } |
| 242 | task Csiu_packet::calcDataParity( bit[127:0] data, var bit [7:0] parity ) { |
| 243 | bit tmp; |
| 244 | integer i,j; |
| 245 | integer start; |
| 246 | |
| 247 | start = 0; |
| 248 | parity = 0; |
| 249 | for(i=0;i<7;i= i + 1 ){ |
| 250 | parity[i] = 0; |
| 251 | for(j=0;j<32;j= j + 2 ) { |
| 252 | tmp = parity[i] ^data[start+j]; |
| 253 | // printf("parity bit - %d calculated with %d\n",i,start+j); |
| 254 | parity[i] = tmp; |
| 255 | // printf(" calcDataParity - i- %d parity - %x data - %x \n",i,parity, data); |
| 256 | } |
| 257 | i++; |
| 258 | start++; |
| 259 | parity[i] = 0; |
| 260 | for(j=0;j<32;j= j + 2 ) { |
| 261 | tmp = parity[i] ^data[start+j]; |
| 262 | parity[i] = tmp; |
| 263 | // printf("parity bit - %d calculated with %d\n",i,start+j); |
| 264 | // printf(" calcDataParity - i- %d parity - %x data - %x \n",i,parity, data); |
| 265 | } |
| 266 | start = start + 31; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | task Csiu_packet::calcParity() { |
| 271 | integer i; |
| 272 | bit[127:0] datai,swap_data; |
| 273 | bit[7:0] parity; |
| 274 | |
| 275 | for(i =0;i<4;i++) { |
| 276 | datai = { data[2*i +1],data[2*i]}; |
| 277 | swap_data = swap(datai); |
| 278 | calcDataParity(swap_data,parity); |
| 279 | data_parity[i] = ~parity; |
| 280 | } |
| 281 | |
| 282 | } |
| 283 | function bit [5:0] Csiu_packet::calc_CtagEcc ( bit [15:0] tag) { |
| 284 | bit [5:0] p; |
| 285 | bit [15:0] d; |
| 286 | d = tag; |
| 287 | p[0] = d[0] ^ d[1]^ d[3]^ d[4]^ d[6]^ d[8]^ d[10]^ d[11]^ d[13]^ d[15]; |
| 288 | p[1] = d[0] ^ d[2]^ d[3]^ d[5]^ d[6]^ d[9]^ d[10]^ d[12]^ d[13]; |
| 289 | p[2] = d[1] ^ d[2]^ d[3]^ d[7]^ d[8]^ d[9]^ d[10]^ d[14]^ d[15]; |
| 290 | p[3] = d[4] ^ d[5]^ d[6]^ d[7]^ d[8]^ d[9]^ d[10]; |
| 291 | p[4] = d[11] ^ d[12]^ d[13]^ d[14]^ d[15]; |
| 292 | p[5] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ p[0] ^ p[1] ^p[2]; |
| 293 | |
| 294 | calc_CtagEcc = p; |
| 295 | |
| 296 | printf("Csiu_packet::calc_CtagEcc id - %x Ecc - %x\n",tag,p); |
| 297 | } |
| 298 | |