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