octeon-model.c revision 232812
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials provided 16 * with the distribution. 17 18 * * Neither the name of Cavium Inc. nor the names of 19 * its contributors may be used to endorse or promote products 20 * derived from this software without specific prior written 21 * permission. 22 23 * This Software, including technical data, may be subject to U.S. export control 24 * laws, including the U.S. Export Administration Act and its associated 25 * regulations, and may be subject to export or import regulations in other 26 * countries. 27 28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR 30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 38 ***********************license end**************************************/ 39 40 41 42 43 44 45 46/** 47 * @file 48 * 49 * File defining functions for working with different Octeon 50 * models. 51 * 52 * <hr>$Revision: 70030 $<hr> 53 */ 54#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 55#include <asm/octeon/octeon.h> 56#include <asm/octeon/cvmx-clock.h> 57#else 58#include "cvmx.h" 59#include "cvmx-pow.h" 60#include "cvmx-warn.h" 61#endif 62 63#if defined(CVMX_BUILD_FOR_LINUX_USER) || defined(CVMX_BUILD_FOR_STANDALONE) 64#include <octeon-app-init.h> 65#include "cvmx-sysinfo.h" 66 67/** 68 * This function checks to see if the software is compatible with the 69 * chip it is running on. This is called in the application startup code 70 * and does not need to be called directly by the application. 71 * Does not return if software is incompatible. 72 * 73 * @param chip_id chip id that the software is being run on. 74 * 75 * @return 0: runtime checking or exact version match 76 * 1: chip is newer revision than compiled for, but software will run properly. 77 */ 78int octeon_model_version_check(uint32_t chip_id __attribute__ ((unused))) 79{ 80 //printf("Model Number: %s\n", octeon_model_get_string(chip_id)); 81#if !OCTEON_IS_COMMON_BINARY() 82 /* Check for special case of mismarked 3005 samples, and adjust cpuid */ 83 if (chip_id == OCTEON_CN3010_PASS1 && (cvmx_read_csr(0x80011800800007B8ull) & (1ull << 34))) 84 chip_id |= 0x10; 85 86 if ((OCTEON_MODEL & 0xffffff) != chip_id) 87 { 88 if (!OCTEON_IS_MODEL((OM_IGNORE_REVISION | chip_id)) || (OCTEON_MODEL & 0xffffff) > chip_id || (((OCTEON_MODEL & 0xffffff) ^ chip_id) & 0x10)) 89 { 90 printf("ERROR: Software not configured for this chip\n" 91 " Expecting ID=0x%08x, Chip is 0x%08x\n", (OCTEON_MODEL & 0xffffff), (unsigned int)chip_id); 92 if ((OCTEON_MODEL & 0xffffff) > chip_id) 93 printf("Refusing to run on older revision than program was compiled for.\n"); 94 exit(-1); 95 } 96 else 97 { 98 printf("\n###################################################\n"); 99 printf("WARNING: Software configured for older revision than running on.\n" 100 " Compiled for ID=0x%08x, Chip is 0x%08x\n", (OCTEON_MODEL & 0xffffff), (unsigned int)chip_id); 101 printf("###################################################\n\n"); 102 return(1); 103 } 104 } 105#endif 106 107 cvmx_warn_if(CVMX_ENABLE_PARAMETER_CHECKING, "Parameter checks are enabled. Expect some performance loss due to the extra checking\n"); 108 cvmx_warn_if(CVMX_ENABLE_CSR_ADDRESS_CHECKING, "CSR address checks are enabled. Expect some performance loss due to the extra checking\n"); 109 cvmx_warn_if(CVMX_ENABLE_POW_CHECKS, "POW state checks are enabled. Expect some performance loss due to the extra checking\n"); 110 111 return(0); 112} 113 114#endif 115/** 116 * Given the chip processor ID from COP0, this function returns a 117 * string representing the chip model number. The string is of the 118 * form CNXXXXpX.X-FREQ-SUFFIX. 119 * - XXXX = The chip model number 120 * - X.X = Chip pass number 121 * - FREQ = Current frequency in Mhz 122 * - SUFFIX = NSP, EXP, SCP, SSP, or CP 123 * 124 * @param chip_id Chip ID 125 * 126 * @return Model string 127 */ 128const char *octeon_model_get_string(uint32_t chip_id) 129{ 130 static char buffer[32]; 131 return octeon_model_get_string_buffer(chip_id,buffer); 132} 133 134/* Version of octeon_model_get_string() that takes buffer as argument, as 135** running early in u-boot static/global variables don't work when running from 136** flash 137*/ 138const char *octeon_model_get_string_buffer(uint32_t chip_id, char * buffer) 139{ 140 const char * family; 141 const char * core_model; 142 char pass[4]; 143#ifndef CVMX_BUILD_FOR_UBOOT 144 int clock_mhz; 145#endif 146 const char * suffix; 147 cvmx_l2d_fus3_t fus3; 148 int num_cores; 149 cvmx_mio_fus_dat2_t fus_dat2; 150 cvmx_mio_fus_dat3_t fus_dat3; 151 char fuse_model[10]; 152 uint32_t fuse_data = 0; 153 154 fus3.u64 = 0; 155 if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN5XXX)) 156 fus3.u64 = cvmx_read_csr(CVMX_L2D_FUS3); 157 fus_dat2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2); 158 fus_dat3.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT3); 159 num_cores = cvmx_pop(cvmx_read_csr(CVMX_CIU_FUSE)); 160 161 /* Make sure the non existent devices look disabled */ 162 switch ((chip_id >> 8) & 0xff) 163 { 164 case 6: /* CN50XX */ 165 case 2: /* CN30XX */ 166 fus_dat3.s.nodfa_dte = 1; 167 fus_dat3.s.nozip = 1; 168 break; 169 case 4: /* CN57XX or CN56XX */ 170 fus_dat3.s.nodfa_dte = 1; 171 break; 172 default: 173 break; 174 } 175 176 /* Make a guess at the suffix */ 177 /* NSP = everything */ 178 /* EXP = No crypto */ 179 /* SCP = No DFA, No zip */ 180 /* CP = No DFA, No crypto, No zip */ 181 if (fus_dat3.s.nodfa_dte) 182 { 183 if (fus_dat2.s.nocrypto) 184 suffix = "CP"; 185 else 186 suffix = "SCP"; 187 } 188 else if (fus_dat2.s.nocrypto) 189 suffix = "EXP"; 190 else 191 suffix = "NSP"; 192 193 /* Assume pass number is encoded using <5:3><2:0>. Exceptions will be 194 fixed later */ 195 sprintf(pass, "%d.%d", (int)((chip_id>>3)&7)+1, (int)chip_id&7); 196 197 /* Use the number of cores to determine the last 2 digits of the model 198 number. There are some exceptions that are fixed later */ 199 switch (num_cores) 200 { 201 case 32: core_model = "80"; break; 202 case 24: core_model = "70"; break; 203 case 16: core_model = "60"; break; 204 case 15: core_model = "58"; break; 205 case 14: core_model = "55"; break; 206 case 13: core_model = "52"; break; 207 case 12: core_model = "50"; break; 208 case 11: core_model = "48"; break; 209 case 10: core_model = "45"; break; 210 case 9: core_model = "42"; break; 211 case 8: core_model = "40"; break; 212 case 7: core_model = "38"; break; 213 case 6: core_model = "34"; break; 214 case 5: core_model = "32"; break; 215 case 4: core_model = "30"; break; 216 case 3: core_model = "25"; break; 217 case 2: core_model = "20"; break; 218 case 1: core_model = "10"; break; 219 default: core_model = "XX"; break; 220 } 221 222 /* Now figure out the family, the first two digits */ 223 switch ((chip_id >> 8) & 0xff) 224 { 225 case 0: /* CN38XX, CN37XX or CN36XX */ 226 if (fus3.cn38xx.crip_512k) 227 { 228 /* For some unknown reason, the 16 core one is called 37 instead of 36 */ 229 if (num_cores >= 16) 230 family = "37"; 231 else 232 family = "36"; 233 } 234 else 235 family = "38"; 236 /* This series of chips didn't follow the standard pass numbering */ 237 switch (chip_id & 0xf) 238 { 239 case 0: strcpy(pass, "1.X"); break; 240 case 1: strcpy(pass, "2.X"); break; 241 case 3: strcpy(pass, "3.X"); break; 242 default:strcpy(pass, "X.X"); break; 243 } 244 break; 245 case 1: /* CN31XX or CN3020 */ 246 if ((chip_id & 0x10) || fus3.cn31xx.crip_128k) 247 family = "30"; 248 else 249 family = "31"; 250 /* This series of chips didn't follow the standard pass numbering */ 251 switch (chip_id & 0xf) 252 { 253 case 0: strcpy(pass, "1.0"); break; 254 case 2: strcpy(pass, "1.1"); break; 255 default:strcpy(pass, "X.X"); break; 256 } 257 break; 258 case 2: /* CN3010 or CN3005 */ 259 family = "30"; 260 /* A chip with half cache is an 05 */ 261 if (fus3.cn30xx.crip_64k) 262 core_model = "05"; 263 /* This series of chips didn't follow the standard pass numbering */ 264 switch (chip_id & 0xf) 265 { 266 case 0: strcpy(pass, "1.0"); break; 267 case 2: strcpy(pass, "1.1"); break; 268 default:strcpy(pass, "X.X"); break; 269 } 270 break; 271 case 3: /* CN58XX */ 272 family = "58"; 273 /* Special case. 4 core, half cache (CP with half cache) */ 274 if ((num_cores == 4) && fus3.cn58xx.crip_1024k && !strncmp(suffix, "CP", 2)) 275 core_model = "29"; 276 277 /* Pass 1 uses different encodings for pass numbers */ 278 if ((chip_id & 0xFF)< 0x8) 279 { 280 switch (chip_id & 0x3) 281 { 282 case 0: strcpy(pass, "1.0"); break; 283 case 1: strcpy(pass, "1.1"); break; 284 case 3: strcpy(pass, "1.2"); break; 285 default:strcpy(pass, "1.X"); break; 286 } 287 } 288 break; 289 case 4: /* CN57XX, CN56XX, CN55XX, CN54XX */ 290 if (fus_dat2.cn56xx.raid_en) 291 { 292 if (fus3.cn56xx.crip_1024k) 293 family = "55"; 294 else 295 family = "57"; 296 if (fus_dat2.cn56xx.nocrypto) 297 suffix = "SP"; 298 else 299 suffix = "SSP"; 300 } 301 else 302 { 303 if (fus_dat2.cn56xx.nocrypto) 304 suffix = "CP"; 305 else 306 { 307 suffix = "NSP"; 308 if (fus_dat3.s.nozip) 309 suffix = "SCP"; 310 311 if (fus_dat3.s.bar2_en) 312 suffix = "NSPB2"; 313 } 314 if (fus3.cn56xx.crip_1024k) 315 family = "54"; 316 else 317 family = "56"; 318 } 319 break; 320 case 6: /* CN50XX */ 321 family = "50"; 322 break; 323 case 7: /* CN52XX */ 324 if (fus3.cn52xx.crip_256k) 325 family = "51"; 326 else 327 family = "52"; 328 break; 329 case 0x93: /* CN61XX */ 330 family = "61"; 331 if (fus_dat3.cn61xx.nozip) 332 suffix = "SCP"; 333 else 334 suffix = "AAP"; 335 break; 336 case 0x90: /* CN63XX */ 337 family = "63"; 338 if (fus_dat3.s.l2c_crip == 2) 339 family = "62"; 340 if (num_cores == 6) /* Other core counts match generic */ 341 core_model = "35"; 342 if (fus_dat2.cn63xx.nocrypto) 343 suffix = "CP"; 344 else if (fus_dat2.cn63xx.dorm_crypto) 345 suffix = "DAP"; 346 else if (fus_dat3.cn63xx.nozip) 347 suffix = "SCP"; 348 else 349 suffix = "AAP"; 350 break; 351 case 0x92: /* CN66XX */ 352 family = "66"; 353 if (num_cores == 6) /* Other core counts match generic */ 354 core_model = "35"; 355 if (fus_dat2.cn66xx.nocrypto && fus_dat2.cn66xx.dorm_crypto) 356 suffix = "AP"; 357 if (fus_dat2.cn66xx.nocrypto) 358 suffix = "CP"; 359 else if (fus_dat2.cn66xx.dorm_crypto) 360 suffix = "DAP"; 361 else if (fus_dat3.cn66xx.nozip && fus_dat2.cn66xx.raid_en) 362 suffix = "SCP"; 363 else if (!fus_dat2.cn66xx.raid_en) 364 suffix = "HAP"; 365 else 366 suffix = "AAP"; 367 break; 368 case 0x91: /* CN68XX */ 369 family = "68"; 370 if (fus_dat2.cn68xx.nocrypto && fus_dat3.cn68xx.nozip) 371 suffix = "CP"; 372 else if (fus_dat2.cn68xx.dorm_crypto) 373 suffix = "DAP"; 374 else if (fus_dat3.cn68xx.nozip) 375 suffix = "SCP"; 376 else if (fus_dat2.cn68xx.nocrypto) 377 suffix = "SP"; 378 else if (!fus_dat2.cn68xx.raid_en) 379 suffix = "HAP"; 380 else 381 suffix = "AAP"; 382 break; 383 case 0x94: /* CNF71XX */ 384 family = "F71"; 385 if (fus_dat3.cnf71xx.nozip) 386 suffix = "SCP"; 387 else 388 suffix = "AAP"; 389 break; 390 default: 391 family = "XX"; 392 core_model = "XX"; 393 strcpy(pass, "X.X"); 394 suffix = "XXX"; 395 break; 396 } 397 398#ifndef CVMX_BUILD_FOR_UBOOT 399 clock_mhz = cvmx_clock_get_rate(CVMX_CLOCK_RCLK) / 1000000; 400#endif 401 402 if (family[0] != '3') 403 { 404 int fuse_base = 384/8; 405 if (family[0] == '6') 406 fuse_base = 832/8; 407 408 /* Check for model in fuses, overrides normal decode */ 409 /* This is _not_ valid for Octeon CN3XXX models */ 410 fuse_data |= cvmx_fuse_read_byte(fuse_base + 3); 411 fuse_data = fuse_data << 8; 412 fuse_data |= cvmx_fuse_read_byte(fuse_base + 2); 413 fuse_data = fuse_data << 8; 414 fuse_data |= cvmx_fuse_read_byte(fuse_base + 1); 415 fuse_data = fuse_data << 8; 416 fuse_data |= cvmx_fuse_read_byte(fuse_base); 417 if (fuse_data & 0x7ffff) 418 { 419 int model = fuse_data & 0x3fff; 420 int suffix = (fuse_data >> 14) & 0x1f; 421 if (suffix && model) /* Have both number and suffix in fuses, so both */ 422 { 423 sprintf(fuse_model, "%d%c",model, 'A' + suffix - 1); 424 core_model = ""; 425 family = fuse_model; 426 } 427 else if (suffix && !model) /* Only have suffix, so add suffix to 'normal' model number */ 428 { 429 sprintf(fuse_model, "%s%c", core_model, 'A' + suffix - 1); 430 core_model = fuse_model; 431 } 432 else /* Don't have suffix, so just use model from fuses */ 433 { 434 sprintf(fuse_model, "%d",model); 435 core_model = ""; 436 family = fuse_model; 437 } 438 } 439 } 440#ifdef CVMX_BUILD_FOR_UBOOT 441 sprintf(buffer, "CN%s%s-%s pass %s", family, core_model, suffix, pass); 442#else 443 sprintf(buffer, "CN%s%sp%s-%d-%s", family, core_model, pass, clock_mhz, suffix); 444#endif 445 return buffer; 446} 447