octeon-model.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: [email protected]
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2017 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. #include <asm/octeon/octeon.h>
  28. enum octeon_feature_bits __octeon_feature_bits __read_mostly;
  29. EXPORT_SYMBOL_GPL(__octeon_feature_bits);
  30. /**
  31. * Read a byte of fuse data
  32. * @byte_addr: address to read
  33. *
  34. * Returns fuse value: 0 or 1
  35. */
  36. static uint8_t __init cvmx_fuse_read_byte(int byte_addr)
  37. {
  38. union cvmx_mio_fus_rcmd read_cmd;
  39. read_cmd.u64 = 0;
  40. read_cmd.s.addr = byte_addr;
  41. read_cmd.s.pend = 1;
  42. cvmx_write_csr(CVMX_MIO_FUS_RCMD, read_cmd.u64);
  43. while ((read_cmd.u64 = cvmx_read_csr(CVMX_MIO_FUS_RCMD))
  44. && read_cmd.s.pend)
  45. ;
  46. return read_cmd.s.dat;
  47. }
  48. /*
  49. * Version of octeon_model_get_string() that takes buffer as argument,
  50. * as running early in u-boot static/global variables don't work when
  51. * running from flash.
  52. */
  53. static const char *__init octeon_model_get_string_buffer(uint32_t chip_id,
  54. char *buffer)
  55. {
  56. const char *family;
  57. const char *core_model;
  58. char pass[4];
  59. int clock_mhz;
  60. const char *suffix;
  61. int num_cores;
  62. union cvmx_mio_fus_dat2 fus_dat2;
  63. union cvmx_mio_fus_dat3 fus_dat3;
  64. char fuse_model[10];
  65. uint32_t fuse_data = 0;
  66. uint64_t l2d_fus3 = 0;
  67. if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN5XXX))
  68. l2d_fus3 = (cvmx_read_csr(CVMX_L2D_FUS3) >> 34) & 0x3;
  69. fus_dat2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
  70. fus_dat3.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT3);
  71. num_cores = cvmx_octeon_num_cores();
  72. /* Make sure the non existent devices look disabled */
  73. switch ((chip_id >> 8) & 0xff) {
  74. case 6: /* CN50XX */
  75. case 2: /* CN30XX */
  76. fus_dat3.s.nodfa_dte = 1;
  77. fus_dat3.s.nozip = 1;
  78. break;
  79. case 4: /* CN57XX or CN56XX */
  80. fus_dat3.s.nodfa_dte = 1;
  81. break;
  82. default:
  83. break;
  84. }
  85. /* Make a guess at the suffix */
  86. /* NSP = everything */
  87. /* EXP = No crypto */
  88. /* SCP = No DFA, No zip */
  89. /* CP = No DFA, No crypto, No zip */
  90. if (fus_dat3.s.nodfa_dte) {
  91. if (fus_dat2.s.nocrypto)
  92. suffix = "CP";
  93. else
  94. suffix = "SCP";
  95. } else if (fus_dat2.s.nocrypto)
  96. suffix = "EXP";
  97. else
  98. suffix = "NSP";
  99. if (!fus_dat2.s.nocrypto)
  100. __octeon_feature_bits |= OCTEON_HAS_CRYPTO;
  101. /*
  102. * Assume pass number is encoded using <5:3><2:0>. Exceptions
  103. * will be fixed later.
  104. */
  105. sprintf(pass, "%d.%d", (int)((chip_id >> 3) & 7) + 1, (int)chip_id & 7);
  106. /*
  107. * Use the number of cores to determine the last 2 digits of
  108. * the model number. There are some exceptions that are fixed
  109. * later.
  110. */
  111. switch (num_cores) {
  112. case 48:
  113. core_model = "90";
  114. break;
  115. case 44:
  116. core_model = "88";
  117. break;
  118. case 40:
  119. core_model = "85";
  120. break;
  121. case 32:
  122. core_model = "80";
  123. break;
  124. case 24:
  125. core_model = "70";
  126. break;
  127. case 16:
  128. core_model = "60";
  129. break;
  130. case 15:
  131. core_model = "58";
  132. break;
  133. case 14:
  134. core_model = "55";
  135. break;
  136. case 13:
  137. core_model = "52";
  138. break;
  139. case 12:
  140. core_model = "50";
  141. break;
  142. case 11:
  143. core_model = "48";
  144. break;
  145. case 10:
  146. core_model = "45";
  147. break;
  148. case 9:
  149. core_model = "42";
  150. break;
  151. case 8:
  152. core_model = "40";
  153. break;
  154. case 7:
  155. core_model = "38";
  156. break;
  157. case 6:
  158. core_model = "34";
  159. break;
  160. case 5:
  161. core_model = "32";
  162. break;
  163. case 4:
  164. core_model = "30";
  165. break;
  166. case 3:
  167. core_model = "25";
  168. break;
  169. case 2:
  170. core_model = "20";
  171. break;
  172. case 1:
  173. core_model = "10";
  174. break;
  175. default:
  176. core_model = "XX";
  177. break;
  178. }
  179. /* Now figure out the family, the first two digits */
  180. switch ((chip_id >> 8) & 0xff) {
  181. case 0: /* CN38XX, CN37XX or CN36XX */
  182. if (l2d_fus3) {
  183. /*
  184. * For some unknown reason, the 16 core one is
  185. * called 37 instead of 36.
  186. */
  187. if (num_cores >= 16)
  188. family = "37";
  189. else
  190. family = "36";
  191. } else
  192. family = "38";
  193. /*
  194. * This series of chips didn't follow the standard
  195. * pass numbering.
  196. */
  197. switch (chip_id & 0xf) {
  198. case 0:
  199. strcpy(pass, "1.X");
  200. break;
  201. case 1:
  202. strcpy(pass, "2.X");
  203. break;
  204. case 3:
  205. strcpy(pass, "3.X");
  206. break;
  207. default:
  208. strcpy(pass, "X.X");
  209. break;
  210. }
  211. break;
  212. case 1: /* CN31XX or CN3020 */
  213. if ((chip_id & 0x10) || l2d_fus3)
  214. family = "30";
  215. else
  216. family = "31";
  217. /*
  218. * This series of chips didn't follow the standard
  219. * pass numbering.
  220. */
  221. switch (chip_id & 0xf) {
  222. case 0:
  223. strcpy(pass, "1.0");
  224. break;
  225. case 2:
  226. strcpy(pass, "1.1");
  227. break;
  228. default:
  229. strcpy(pass, "X.X");
  230. break;
  231. }
  232. break;
  233. case 2: /* CN3010 or CN3005 */
  234. family = "30";
  235. /* A chip with half cache is an 05 */
  236. if (l2d_fus3)
  237. core_model = "05";
  238. /*
  239. * This series of chips didn't follow the standard
  240. * pass numbering.
  241. */
  242. switch (chip_id & 0xf) {
  243. case 0:
  244. strcpy(pass, "1.0");
  245. break;
  246. case 2:
  247. strcpy(pass, "1.1");
  248. break;
  249. default:
  250. strcpy(pass, "X.X");
  251. break;
  252. }
  253. break;
  254. case 3: /* CN58XX */
  255. family = "58";
  256. /* Special case. 4 core, half cache (CP with half cache) */
  257. if ((num_cores == 4) && l2d_fus3 && !strncmp(suffix, "CP", 2))
  258. core_model = "29";
  259. /* Pass 1 uses different encodings for pass numbers */
  260. if ((chip_id & 0xFF) < 0x8) {
  261. switch (chip_id & 0x3) {
  262. case 0:
  263. strcpy(pass, "1.0");
  264. break;
  265. case 1:
  266. strcpy(pass, "1.1");
  267. break;
  268. case 3:
  269. strcpy(pass, "1.2");
  270. break;
  271. default:
  272. strcpy(pass, "1.X");
  273. break;
  274. }
  275. }
  276. break;
  277. case 4: /* CN57XX, CN56XX, CN55XX, CN54XX */
  278. if (fus_dat2.cn56xx.raid_en) {
  279. if (l2d_fus3)
  280. family = "55";
  281. else
  282. family = "57";
  283. if (fus_dat2.cn56xx.nocrypto)
  284. suffix = "SP";
  285. else
  286. suffix = "SSP";
  287. } else {
  288. if (fus_dat2.cn56xx.nocrypto)
  289. suffix = "CP";
  290. else {
  291. suffix = "NSP";
  292. if (fus_dat3.s.nozip)
  293. suffix = "SCP";
  294. if (fus_dat3.cn38xx.bar2_en)
  295. suffix = "NSPB2";
  296. }
  297. if (l2d_fus3)
  298. family = "54";
  299. else
  300. family = "56";
  301. }
  302. break;
  303. case 6: /* CN50XX */
  304. family = "50";
  305. break;
  306. case 7: /* CN52XX */
  307. if (l2d_fus3)
  308. family = "51";
  309. else
  310. family = "52";
  311. break;
  312. case 0x93: /* CN61XX */
  313. family = "61";
  314. if (fus_dat2.cn61xx.nocrypto && fus_dat2.cn61xx.dorm_crypto)
  315. suffix = "AP";
  316. if (fus_dat2.cn61xx.nocrypto)
  317. suffix = "CP";
  318. else if (fus_dat2.cn61xx.dorm_crypto)
  319. suffix = "DAP";
  320. else if (fus_dat3.cn61xx.nozip)
  321. suffix = "SCP";
  322. break;
  323. case 0x90: /* CN63XX */
  324. family = "63";
  325. if (fus_dat3.s.l2c_crip == 2)
  326. family = "62";
  327. if (num_cores == 6) /* Other core counts match generic */
  328. core_model = "35";
  329. if (fus_dat2.cn63xx.nocrypto)
  330. suffix = "CP";
  331. else if (fus_dat2.cn63xx.dorm_crypto)
  332. suffix = "DAP";
  333. else if (fus_dat3.cn61xx.nozip)
  334. suffix = "SCP";
  335. else
  336. suffix = "AAP";
  337. break;
  338. case 0x92: /* CN66XX */
  339. family = "66";
  340. if (num_cores == 6) /* Other core counts match generic */
  341. core_model = "35";
  342. if (fus_dat2.cn66xx.nocrypto && fus_dat2.cn66xx.dorm_crypto)
  343. suffix = "AP";
  344. if (fus_dat2.cn66xx.nocrypto)
  345. suffix = "CP";
  346. else if (fus_dat2.cn66xx.dorm_crypto)
  347. suffix = "DAP";
  348. else if (fus_dat3.cn61xx.nozip)
  349. suffix = "SCP";
  350. else
  351. suffix = "AAP";
  352. break;
  353. case 0x91: /* CN68XX */
  354. family = "68";
  355. if (fus_dat2.cn68xx.nocrypto && fus_dat3.cn61xx.nozip)
  356. suffix = "CP";
  357. else if (fus_dat2.cn68xx.dorm_crypto)
  358. suffix = "DAP";
  359. else if (fus_dat3.cn61xx.nozip)
  360. suffix = "SCP";
  361. else if (fus_dat2.cn68xx.nocrypto)
  362. suffix = "SP";
  363. else
  364. suffix = "AAP";
  365. break;
  366. case 0x94: /* CNF71XX */
  367. family = "F71";
  368. if (fus_dat3.cn61xx.nozip)
  369. suffix = "SCP";
  370. else
  371. suffix = "AAP";
  372. break;
  373. case 0x95: /* CN78XX */
  374. if (num_cores == 6) /* Other core counts match generic */
  375. core_model = "35";
  376. if (OCTEON_IS_MODEL(OCTEON_CN76XX))
  377. family = "76";
  378. else
  379. family = "78";
  380. if (fus_dat3.cn78xx.l2c_crip == 2)
  381. family = "77";
  382. if (fus_dat3.cn78xx.nozip
  383. && fus_dat3.cn78xx.nodfa_dte
  384. && fus_dat3.cn78xx.nohna_dte) {
  385. if (fus_dat3.cn78xx.nozip &&
  386. !fus_dat2.cn78xx.raid_en &&
  387. fus_dat3.cn78xx.nohna_dte) {
  388. suffix = "CP";
  389. } else {
  390. suffix = "SCP";
  391. }
  392. } else if (fus_dat2.cn78xx.raid_en == 0)
  393. suffix = "HCP";
  394. else
  395. suffix = "AAP";
  396. break;
  397. case 0x96: /* CN70XX */
  398. family = "70";
  399. if (cvmx_read_csr(CVMX_MIO_FUS_PDF) & (0x1ULL << 32))
  400. family = "71";
  401. if (fus_dat2.cn70xx.nocrypto)
  402. suffix = "CP";
  403. else if (fus_dat3.cn70xx.nodfa_dte)
  404. suffix = "SCP";
  405. else
  406. suffix = "AAP";
  407. break;
  408. case 0x97: /* CN73XX */
  409. if (num_cores == 6) /* Other core counts match generic */
  410. core_model = "35";
  411. family = "73";
  412. if (fus_dat3.cn73xx.l2c_crip == 2)
  413. family = "72";
  414. if (fus_dat3.cn73xx.nozip
  415. && fus_dat3.cn73xx.nodfa_dte
  416. && fus_dat3.cn73xx.nohna_dte) {
  417. if (!fus_dat2.cn73xx.raid_en)
  418. suffix = "CP";
  419. else
  420. suffix = "SCP";
  421. } else
  422. suffix = "AAP";
  423. break;
  424. case 0x98: /* CN75XX */
  425. family = "F75";
  426. if (fus_dat3.cn78xx.nozip
  427. && fus_dat3.cn78xx.nodfa_dte
  428. && fus_dat3.cn78xx.nohna_dte)
  429. suffix = "SCP";
  430. else
  431. suffix = "AAP";
  432. break;
  433. default:
  434. family = "XX";
  435. core_model = "XX";
  436. strcpy(pass, "X.X");
  437. suffix = "XXX";
  438. break;
  439. }
  440. clock_mhz = octeon_get_clock_rate() / 1000000;
  441. if (family[0] != '3') {
  442. int fuse_base = 384 / 8;
  443. if (family[0] == '6')
  444. fuse_base = 832 / 8;
  445. /* Check for model in fuses, overrides normal decode */
  446. /* This is _not_ valid for Octeon CN3XXX models */
  447. fuse_data |= cvmx_fuse_read_byte(fuse_base + 3);
  448. fuse_data = fuse_data << 8;
  449. fuse_data |= cvmx_fuse_read_byte(fuse_base + 2);
  450. fuse_data = fuse_data << 8;
  451. fuse_data |= cvmx_fuse_read_byte(fuse_base + 1);
  452. fuse_data = fuse_data << 8;
  453. fuse_data |= cvmx_fuse_read_byte(fuse_base);
  454. if (fuse_data & 0x7ffff) {
  455. int model = fuse_data & 0x3fff;
  456. int suffix = (fuse_data >> 14) & 0x1f;
  457. if (suffix && model) {
  458. /* Have both number and suffix in fuses, so both */
  459. sprintf(fuse_model, "%d%c", model, 'A' + suffix - 1);
  460. core_model = "";
  461. family = fuse_model;
  462. } else if (suffix && !model) {
  463. /* Only have suffix, so add suffix to 'normal' model number */
  464. sprintf(fuse_model, "%s%c", core_model, 'A' + suffix - 1);
  465. core_model = fuse_model;
  466. } else {
  467. /* Don't have suffix, so just use model from fuses */
  468. sprintf(fuse_model, "%d", model);
  469. core_model = "";
  470. family = fuse_model;
  471. }
  472. }
  473. }
  474. sprintf(buffer, "CN%s%sp%s-%d-%s", family, core_model, pass, clock_mhz, suffix);
  475. return buffer;
  476. }
  477. /**
  478. * Given the chip processor ID from COP0, this function returns a
  479. * string representing the chip model number. The string is of the
  480. * form CNXXXXpX.X-FREQ-SUFFIX.
  481. * - XXXX = The chip model number
  482. * - X.X = Chip pass number
  483. * - FREQ = Current frequency in Mhz
  484. * - SUFFIX = NSP, EXP, SCP, SSP, or CP
  485. *
  486. * @chip_id: Chip ID
  487. *
  488. * Returns Model string
  489. */
  490. const char *__init octeon_model_get_string(uint32_t chip_id)
  491. {
  492. static char buffer[32];
  493. return octeon_model_get_string_buffer(chip_id, buffer);
  494. }