octeon-model.c revision 215990
1/***********************license start***************
2 * Copyright (c) 2003-2010  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 * 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  NETWORKS 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: 49922 $<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)
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    /* Core-14449 errata check. Generate a warning message if application
112       compiled for OcteonPlus/Octeon models are run on Octeon II Pass1 chip */
113    {
114        uint32_t insn;
115
116        asm volatile (
117                      ".set push\n"            \
118                      ".set noreorder\n"       \
119                      "pref_errata:\tpref 0,0($zero)\n"      \
120                      "lw %0, pref_errata\n" \
121                      ".set pop"  : "=r" (insn) : : "memory");
122
123        if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) && ((insn >> 16) & 0x1f) != 28)
124        {
125            printf("\n###################################################\n");
126            printf("WARNING: Application not compiled for cn63xx pass1.x chips, use of\n"
127                   "         certain prefetch operations can cause dcache corruption.\n");
128            printf("###################################################\n\n");
129            return -1;
130        }
131        else if (!OCTEON_IS_MODEL(OCTEON_CN63XX) && ((insn >> 16) & 0x1f) == 28)
132        {
133            printf("\n###################################################\n");
134            printf("WARNING: Software configured with -mfix-cn63xxp1 (Core-14449 errata), expect some performance loss.\n");
135            printf("###################################################\n\n");
136        }
137    }
138    return(0);
139}
140
141#endif
142/**
143 * Given the chip processor ID from COP0, this function returns a
144 * string representing the chip model number. The string is of the
145 * form CNXXXXpX.X-FREQ-SUFFIX.
146 * - XXXX = The chip model number
147 * - X.X = Chip pass number
148 * - FREQ = Current frequency in Mhz
149 * - SUFFIX = NSP, EXP, SCP, SSP, or CP
150 *
151 * @param chip_id Chip ID
152 *
153 * @return Model string
154 */
155const char *octeon_model_get_string(uint32_t chip_id)
156{
157    static char         buffer[32];
158    return octeon_model_get_string_buffer(chip_id,buffer);
159}
160
161/* Version of octeon_model_get_string() that takes buffer as argument, as
162** running early in u-boot static/global variables don't work when running from
163** flash
164*/
165const char *octeon_model_get_string_buffer(uint32_t chip_id, char * buffer)
166{
167    const char *        family;
168    const char *        core_model;
169    char                pass[4];
170    int                 clock_mhz;
171    const char *        suffix;
172    cvmx_l2d_fus3_t     fus3;
173    int                 num_cores;
174    cvmx_mio_fus_dat2_t fus_dat2;
175    cvmx_mio_fus_dat3_t fus_dat3;
176    char fuse_model[10];
177    uint32_t fuse_data = 0;
178
179    if (!OCTEON_IS_MODEL(OCTEON_CN6XXX))
180        fus3.u64 = cvmx_read_csr(CVMX_L2D_FUS3);
181    fus_dat2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
182    fus_dat3.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT3);
183    num_cores = cvmx_pop(cvmx_read_csr(CVMX_CIU_FUSE));
184
185    /* Make sure the non existant devices look disabled */
186    switch ((chip_id >> 8) & 0xff)
187    {
188        case 6: /* CN50XX */
189        case 2: /* CN30XX */
190            fus_dat3.s.nodfa_dte = 1;
191            fus_dat3.s.nozip = 1;
192            break;
193        case 4: /* CN57XX or CN56XX */
194            fus_dat3.s.nodfa_dte = 1;
195            break;
196        default:
197            break;
198    }
199
200    /* Make a guess at the suffix */
201    /* NSP = everything */
202    /* EXP = No crypto */
203    /* SCP = No DFA, No zip */
204    /* CP = No DFA, No crypto, No zip */
205    if (fus_dat3.s.nodfa_dte)
206    {
207        if (fus_dat2.s.nocrypto)
208            suffix = "CP";
209        else
210            suffix = "SCP";
211    }
212    else if (fus_dat2.s.nocrypto)
213        suffix = "EXP";
214    else
215        suffix = "NSP";
216
217    /* Assume pass number is encoded using <5:3><2:0>. Exceptions will be
218        fixed later */
219    sprintf(pass, "%d.%d", (int)((chip_id>>3)&7)+1, (int)chip_id&7);
220
221    /* Use the number of cores to determine the last 2 digits of the model
222        number. There are some exceptions that are fixed later */
223    switch (num_cores)
224    {
225        case 16: core_model = "60"; break;
226        case 15: core_model = "58"; break;
227        case 14: core_model = "55"; break;
228        case 13: core_model = "52"; break;
229        case 12: core_model = "50"; break;
230        case 11: core_model = "48"; break;
231        case 10: core_model = "45"; break;
232        case  9: core_model = "42"; break;
233        case  8: core_model = "40"; break;
234        case  7: core_model = "38"; break;
235        case  6: core_model = "34"; break;
236        case  5: core_model = "32"; break;
237        case  4: core_model = "30"; break;
238        case  3: core_model = "25"; break;
239        case  2: core_model = "20"; break;
240        case  1: core_model = "10"; break;
241        default: core_model = "XX"; break;
242    }
243
244    /* Now figure out the family, the first two digits */
245    switch ((chip_id >> 8) & 0xff)
246    {
247        case 0: /* CN38XX, CN37XX or CN36XX */
248            if (fus3.cn38xx.crip_512k)
249            {
250                /* For some unknown reason, the 16 core one is called 37 instead of 36 */
251                if (num_cores >= 16)
252                    family = "37";
253                else
254                    family = "36";
255            }
256            else
257                family = "38";
258            /* This series of chips didn't follow the standard pass numbering */
259            switch (chip_id & 0xf)
260            {
261                case 0: strcpy(pass, "1.X"); break;
262                case 1: strcpy(pass, "2.X"); break;
263                case 3: strcpy(pass, "3.X"); break;
264                default:strcpy(pass, "X.X"); break;
265            }
266            break;
267        case 1: /* CN31XX or CN3020 */
268            if ((chip_id & 0x10) || fus3.cn31xx.crip_128k)
269                family = "30";
270            else
271                family = "31";
272            /* This series of chips didn't follow the standard pass numbering */
273            switch (chip_id & 0xf)
274            {
275                case 0: strcpy(pass, "1.0"); break;
276                case 2: strcpy(pass, "1.1"); break;
277                default:strcpy(pass, "X.X"); break;
278            }
279            break;
280        case 2: /* CN3010 or CN3005 */
281            family = "30";
282            /* A chip with half cache is an 05 */
283            if (fus3.cn30xx.crip_64k)
284                core_model = "05";
285            /* This series of chips didn't follow the standard pass numbering */
286            switch (chip_id & 0xf)
287            {
288                case 0: strcpy(pass, "1.0"); break;
289                case 2: strcpy(pass, "1.1"); break;
290                default:strcpy(pass, "X.X"); break;
291            }
292            break;
293        case 3: /* CN58XX */
294            family = "58";
295            /* Special case. 4 core, no crypto */
296            if ((num_cores == 4) && fus_dat2.cn38xx.nocrypto)
297                core_model = "29";
298
299            /* Pass 1 uses different encodings for pass numbers */
300            if ((chip_id & 0xFF)< 0x8)
301            {
302                switch (chip_id & 0x3)
303                {
304                    case 0: strcpy(pass, "1.0"); break;
305                    case 1: strcpy(pass, "1.1"); break;
306                    case 3: strcpy(pass, "1.2"); break;
307                    default:strcpy(pass, "1.X"); break;
308                }
309            }
310            break;
311        case 4: /* CN57XX, CN56XX, CN55XX, CN54XX */
312            if (fus_dat2.cn56xx.raid_en)
313            {
314                if (fus3.cn56xx.crip_1024k)
315                    family = "55";
316                else
317                    family = "57";
318                if (fus_dat2.cn56xx.nocrypto)
319                    suffix = "SP";
320                else
321                    suffix = "SSP";
322            }
323            else
324            {
325                if (fus_dat2.cn56xx.nocrypto)
326                    suffix = "CP";
327                else
328                {
329                    suffix = "NSP";
330                    if (fus_dat3.s.nozip)
331                        suffix = "SCP";
332                }
333                if (fus3.cn56xx.crip_1024k)
334                    family = "54";
335                else
336                    family = "56";
337            }
338            break;
339        case 6: /* CN50XX */
340            family = "50";
341            break;
342        case 7: /* CN52XX */
343            if (fus3.cn52xx.crip_256k)
344                family = "51";
345            else
346                family = "52";
347            break;
348	case 0x90: /* CN63XX */
349            family = "63";
350            if (num_cores == 6)
351                core_model = "35";
352            if (fus_dat2.cn63xx.nocrypto)
353                suffix = "CP";
354            else if (fus_dat2.cn63xx.dorm_crypto)
355                suffix = "DAP";
356            else
357                suffix = "AAP";
358            break;
359        default:
360            family = "XX";
361            core_model = "XX";
362            strcpy(pass, "X.X");
363            suffix = "XXX";
364            break;
365    }
366
367    clock_mhz = cvmx_clock_get_rate(CVMX_CLOCK_RCLK) / 1000000;
368
369    if (family[0] != '3')
370    {
371        /* Check for model in fuses, overrides normal decode */
372        /* This is _not_ valid for Octeon CN3XXX models */
373        fuse_data |= cvmx_fuse_read_byte(51);
374        fuse_data = fuse_data << 8;
375        fuse_data |= cvmx_fuse_read_byte(50);
376        fuse_data = fuse_data << 8;
377        fuse_data |= cvmx_fuse_read_byte(49);
378        fuse_data = fuse_data << 8;
379        fuse_data |= cvmx_fuse_read_byte(48);
380        if (fuse_data & 0x7ffff)
381        {
382            int model = fuse_data & 0x3fff;
383            int suffix = (fuse_data >> 14) & 0x1f;
384            if (suffix && model)  /* Have both number and suffix in fuses, so both */
385            {
386                sprintf(fuse_model, "%d%c",model, 'A' + suffix - 1);
387                core_model = "";
388                family = fuse_model;
389            }
390            else if (suffix && !model)   /* Only have suffix, so add suffix to 'normal' model number */
391            {
392                sprintf(fuse_model, "%s%c", core_model, 'A' + suffix - 1);
393                core_model = fuse_model;
394            }
395            else /* Don't have suffix, so just use model from fuses */
396            {
397                sprintf(fuse_model, "%d",model);
398                core_model = "";
399                family = fuse_model;
400            }
401        }
402    }
403#ifdef CVMX_BUILD_FOR_UBOOT
404    sprintf(buffer, "CN%s%s-%s pass %s", family, core_model, suffix, pass);
405#else
406    sprintf(buffer, "CN%s%sp%s-%d-%s", family, core_model, pass, clock_mhz, suffix);
407#endif
408    return buffer;
409}
410