cerr-sb1.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2001,2002,2003 Broadcom Corporation
  4. */
  5. #include <linux/sched.h>
  6. #include <asm/mipsregs.h>
  7. #include <asm/sibyte/sb1250.h>
  8. #include <asm/sibyte/sb1250_regs.h>
  9. #if !defined(CONFIG_SIBYTE_BUS_WATCHER) || defined(CONFIG_SIBYTE_BW_TRACE)
  10. #include <asm/io.h>
  11. #include <asm/sibyte/sb1250_scd.h>
  12. #endif
  13. /*
  14. * We'd like to dump the L2_ECC_TAG register on errors, but errata make
  15. * that unsafe... So for now we don't. (BCM1250/BCM112x erratum SOC-48.)
  16. */
  17. #undef DUMP_L2_ECC_TAG_ON_ERROR
  18. /* SB1 definitions */
  19. /* XXX should come from config1 XXX */
  20. #define SB1_CACHE_INDEX_MASK 0x1fe0
  21. #define CP0_ERRCTL_RECOVERABLE (1 << 31)
  22. #define CP0_ERRCTL_DCACHE (1 << 30)
  23. #define CP0_ERRCTL_ICACHE (1 << 29)
  24. #define CP0_ERRCTL_MULTIBUS (1 << 23)
  25. #define CP0_ERRCTL_MC_TLB (1 << 15)
  26. #define CP0_ERRCTL_MC_TIMEOUT (1 << 14)
  27. #define CP0_CERRI_TAG_PARITY (1 << 29)
  28. #define CP0_CERRI_DATA_PARITY (1 << 28)
  29. #define CP0_CERRI_EXTERNAL (1 << 26)
  30. #define CP0_CERRI_IDX_VALID(c) (!((c) & CP0_CERRI_EXTERNAL))
  31. #define CP0_CERRI_DATA (CP0_CERRI_DATA_PARITY)
  32. #define CP0_CERRD_MULTIPLE (1 << 31)
  33. #define CP0_CERRD_TAG_STATE (1 << 30)
  34. #define CP0_CERRD_TAG_ADDRESS (1 << 29)
  35. #define CP0_CERRD_DATA_SBE (1 << 28)
  36. #define CP0_CERRD_DATA_DBE (1 << 27)
  37. #define CP0_CERRD_EXTERNAL (1 << 26)
  38. #define CP0_CERRD_LOAD (1 << 25)
  39. #define CP0_CERRD_STORE (1 << 24)
  40. #define CP0_CERRD_FILLWB (1 << 23)
  41. #define CP0_CERRD_COHERENCY (1 << 22)
  42. #define CP0_CERRD_DUPTAG (1 << 21)
  43. #define CP0_CERRD_DPA_VALID(c) (!((c) & CP0_CERRD_EXTERNAL))
  44. #define CP0_CERRD_IDX_VALID(c) \
  45. (((c) & (CP0_CERRD_LOAD | CP0_CERRD_STORE)) ? (!((c) & CP0_CERRD_EXTERNAL)) : 0)
  46. #define CP0_CERRD_CAUSES \
  47. (CP0_CERRD_LOAD | CP0_CERRD_STORE | CP0_CERRD_FILLWB | CP0_CERRD_COHERENCY | CP0_CERRD_DUPTAG)
  48. #define CP0_CERRD_TYPES \
  49. (CP0_CERRD_TAG_STATE | CP0_CERRD_TAG_ADDRESS | CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE | CP0_CERRD_EXTERNAL)
  50. #define CP0_CERRD_DATA (CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE)
  51. static uint32_t extract_ic(unsigned short addr, int data);
  52. static uint32_t extract_dc(unsigned short addr, int data);
  53. static inline void breakout_errctl(unsigned int val)
  54. {
  55. if (val & CP0_ERRCTL_RECOVERABLE)
  56. printk(" recoverable");
  57. if (val & CP0_ERRCTL_DCACHE)
  58. printk(" dcache");
  59. if (val & CP0_ERRCTL_ICACHE)
  60. printk(" icache");
  61. if (val & CP0_ERRCTL_MULTIBUS)
  62. printk(" multiple-buserr");
  63. printk("\n");
  64. }
  65. static inline void breakout_cerri(unsigned int val)
  66. {
  67. if (val & CP0_CERRI_TAG_PARITY)
  68. printk(" tag-parity");
  69. if (val & CP0_CERRI_DATA_PARITY)
  70. printk(" data-parity");
  71. if (val & CP0_CERRI_EXTERNAL)
  72. printk(" external");
  73. printk("\n");
  74. }
  75. static inline void breakout_cerrd(unsigned int val)
  76. {
  77. switch (val & CP0_CERRD_CAUSES) {
  78. case CP0_CERRD_LOAD:
  79. printk(" load,");
  80. break;
  81. case CP0_CERRD_STORE:
  82. printk(" store,");
  83. break;
  84. case CP0_CERRD_FILLWB:
  85. printk(" fill/wb,");
  86. break;
  87. case CP0_CERRD_COHERENCY:
  88. printk(" coherency,");
  89. break;
  90. case CP0_CERRD_DUPTAG:
  91. printk(" duptags,");
  92. break;
  93. default:
  94. printk(" NO CAUSE,");
  95. break;
  96. }
  97. if (!(val & CP0_CERRD_TYPES))
  98. printk(" NO TYPE");
  99. else {
  100. if (val & CP0_CERRD_MULTIPLE)
  101. printk(" multi-err");
  102. if (val & CP0_CERRD_TAG_STATE)
  103. printk(" tag-state");
  104. if (val & CP0_CERRD_TAG_ADDRESS)
  105. printk(" tag-address");
  106. if (val & CP0_CERRD_DATA_SBE)
  107. printk(" data-SBE");
  108. if (val & CP0_CERRD_DATA_DBE)
  109. printk(" data-DBE");
  110. if (val & CP0_CERRD_EXTERNAL)
  111. printk(" external");
  112. }
  113. printk("\n");
  114. }
  115. #ifndef CONFIG_SIBYTE_BUS_WATCHER
  116. static void check_bus_watcher(void)
  117. {
  118. uint32_t status, l2_err, memio_err;
  119. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  120. uint64_t l2_tag;
  121. #endif
  122. /* Destructive read, clears register and interrupt */
  123. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  124. /* Bit 31 is always on, but there's no #define for that */
  125. if (status & ~(1UL << 31)) {
  126. l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  127. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  128. l2_tag = in64(IOADDR(A_L2_ECC_TAG));
  129. #endif
  130. memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  131. printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
  132. printk("\nLast recorded signature:\n");
  133. printk("Request %02x from %d, answered by %d with Dcode %d\n",
  134. (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
  135. (int)(G_SCD_BERR_TID(status) >> 6),
  136. (int)G_SCD_BERR_RID(status),
  137. (int)G_SCD_BERR_DCODE(status));
  138. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  139. printk("Last L2 tag w/ bad ECC: %016llx\n", l2_tag);
  140. #endif
  141. } else {
  142. printk("Bus watcher indicates no error\n");
  143. }
  144. }
  145. #else
  146. extern void check_bus_watcher(void);
  147. #endif
  148. asmlinkage void sb1_cache_error(void)
  149. {
  150. uint32_t errctl, cerr_i, cerr_d, dpalo, dpahi, eepc, res;
  151. unsigned long long cerr_dpa;
  152. #ifdef CONFIG_SIBYTE_BW_TRACE
  153. /* Freeze the trace buffer now */
  154. csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
  155. printk("Trace buffer frozen\n");
  156. #endif
  157. printk("Cache error exception on CPU %x:\n",
  158. (read_c0_prid() >> 25) & 0x7);
  159. __asm__ __volatile__ (
  160. " .set push\n\t"
  161. " .set mips64\n\t"
  162. " .set noat\n\t"
  163. " mfc0 %0, $26\n\t"
  164. " mfc0 %1, $27\n\t"
  165. " mfc0 %2, $27, 1\n\t"
  166. " dmfc0 $1, $27, 3\n\t"
  167. " dsrl32 %3, $1, 0 \n\t"
  168. " sll %4, $1, 0 \n\t"
  169. " mfc0 %5, $30\n\t"
  170. " .set pop"
  171. : "=r" (errctl), "=r" (cerr_i), "=r" (cerr_d),
  172. "=r" (dpahi), "=r" (dpalo), "=r" (eepc));
  173. cerr_dpa = (((uint64_t)dpahi) << 32) | dpalo;
  174. printk(" c0_errorepc == %08x\n", eepc);
  175. printk(" c0_errctl == %08x", errctl);
  176. breakout_errctl(errctl);
  177. if (errctl & CP0_ERRCTL_ICACHE) {
  178. printk(" c0_cerr_i == %08x", cerr_i);
  179. breakout_cerri(cerr_i);
  180. if (CP0_CERRI_IDX_VALID(cerr_i)) {
  181. /* Check index of EPC, allowing for delay slot */
  182. if (((eepc & SB1_CACHE_INDEX_MASK) != (cerr_i & SB1_CACHE_INDEX_MASK)) &&
  183. ((eepc & SB1_CACHE_INDEX_MASK) != ((cerr_i & SB1_CACHE_INDEX_MASK) - 4)))
  184. printk(" cerr_i idx doesn't match eepc\n");
  185. else {
  186. res = extract_ic(cerr_i & SB1_CACHE_INDEX_MASK,
  187. (cerr_i & CP0_CERRI_DATA) != 0);
  188. if (!(res & cerr_i))
  189. printk("...didn't see indicated icache problem\n");
  190. }
  191. }
  192. }
  193. if (errctl & CP0_ERRCTL_DCACHE) {
  194. printk(" c0_cerr_d == %08x", cerr_d);
  195. breakout_cerrd(cerr_d);
  196. if (CP0_CERRD_DPA_VALID(cerr_d)) {
  197. printk(" c0_cerr_dpa == %010llx\n", cerr_dpa);
  198. if (!CP0_CERRD_IDX_VALID(cerr_d)) {
  199. res = extract_dc(cerr_dpa & SB1_CACHE_INDEX_MASK,
  200. (cerr_d & CP0_CERRD_DATA) != 0);
  201. if (!(res & cerr_d))
  202. printk("...didn't see indicated dcache problem\n");
  203. } else {
  204. if ((cerr_dpa & SB1_CACHE_INDEX_MASK) != (cerr_d & SB1_CACHE_INDEX_MASK))
  205. printk(" cerr_d idx doesn't match cerr_dpa\n");
  206. else {
  207. res = extract_dc(cerr_d & SB1_CACHE_INDEX_MASK,
  208. (cerr_d & CP0_CERRD_DATA) != 0);
  209. if (!(res & cerr_d))
  210. printk("...didn't see indicated problem\n");
  211. }
  212. }
  213. }
  214. }
  215. check_bus_watcher();
  216. /*
  217. * Calling panic() when a fatal cache error occurs scrambles the
  218. * state of the system (and the cache), making it difficult to
  219. * investigate after the fact. However, if you just stall the CPU,
  220. * the other CPU may keep on running, which is typically very
  221. * undesirable.
  222. */
  223. #ifdef CONFIG_SB1_CERR_STALL
  224. while (1)
  225. ;
  226. #else
  227. panic("unhandled cache error");
  228. #endif
  229. }
  230. /* Parity lookup table. */
  231. static const uint8_t parity[256] = {
  232. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  233. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  234. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  235. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  236. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  237. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  238. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  239. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  240. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  241. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  242. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  243. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  244. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  245. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  246. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  247. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0
  248. };
  249. /* Masks to select bits for Hamming parity, mask_72_64[i] for bit[i] */
  250. static const uint64_t mask_72_64[8] = {
  251. 0x0738C808099264FFULL,
  252. 0x38C808099264FF07ULL,
  253. 0xC808099264FF0738ULL,
  254. 0x08099264FF0738C8ULL,
  255. 0x099264FF0738C808ULL,
  256. 0x9264FF0738C80809ULL,
  257. 0x64FF0738C8080992ULL,
  258. 0xFF0738C808099264ULL
  259. };
  260. /* Calculate the parity on a range of bits */
  261. static char range_parity(uint64_t dword, int max, int min)
  262. {
  263. char parity = 0;
  264. int i;
  265. dword >>= min;
  266. for (i=max-min; i>=0; i--) {
  267. if (dword & 0x1)
  268. parity = !parity;
  269. dword >>= 1;
  270. }
  271. return parity;
  272. }
  273. /* Calculate the 4-bit even byte-parity for an instruction */
  274. static unsigned char inst_parity(uint32_t word)
  275. {
  276. int i, j;
  277. char parity = 0;
  278. for (j=0; j<4; j++) {
  279. char byte_parity = 0;
  280. for (i=0; i<8; i++) {
  281. if (word & 0x80000000)
  282. byte_parity = !byte_parity;
  283. word <<= 1;
  284. }
  285. parity <<= 1;
  286. parity |= byte_parity;
  287. }
  288. return parity;
  289. }
  290. static uint32_t extract_ic(unsigned short addr, int data)
  291. {
  292. unsigned short way;
  293. int valid;
  294. uint32_t taghi, taglolo, taglohi;
  295. unsigned long long taglo, va;
  296. uint64_t tlo_tmp;
  297. uint8_t lru;
  298. int res = 0;
  299. printk("Icache index 0x%04x ", addr);
  300. for (way = 0; way < 4; way++) {
  301. /* Index-load-tag-I */
  302. __asm__ __volatile__ (
  303. " .set push \n\t"
  304. " .set noreorder \n\t"
  305. " .set mips64 \n\t"
  306. " .set noat \n\t"
  307. " cache 4, 0(%3) \n\t"
  308. " mfc0 %0, $29 \n\t"
  309. " dmfc0 $1, $28 \n\t"
  310. " dsrl32 %1, $1, 0 \n\t"
  311. " sll %2, $1, 0 \n\t"
  312. " .set pop"
  313. : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
  314. : "r" ((way << 13) | addr));
  315. taglo = ((unsigned long long)taglohi << 32) | taglolo;
  316. if (way == 0) {
  317. lru = (taghi >> 14) & 0xff;
  318. printk("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
  319. ((addr >> 5) & 0x3), /* bank */
  320. ((addr >> 7) & 0x3f), /* index */
  321. (lru & 0x3),
  322. ((lru >> 2) & 0x3),
  323. ((lru >> 4) & 0x3),
  324. ((lru >> 6) & 0x3));
  325. }
  326. va = (taglo & 0xC0000FFFFFFFE000ULL) | addr;
  327. if ((taglo & (1 << 31)) && (((taglo >> 62) & 0x3) == 3))
  328. va |= 0x3FFFF00000000000ULL;
  329. valid = ((taghi >> 29) & 1);
  330. if (valid) {
  331. tlo_tmp = taglo & 0xfff3ff;
  332. if (((taglo >> 10) & 1) ^ range_parity(tlo_tmp, 23, 0)) {
  333. printk(" ** bad parity in VTag0/G/ASID\n");
  334. res |= CP0_CERRI_TAG_PARITY;
  335. }
  336. if (((taglo >> 11) & 1) ^ range_parity(taglo, 63, 24)) {
  337. printk(" ** bad parity in R/VTag1\n");
  338. res |= CP0_CERRI_TAG_PARITY;
  339. }
  340. }
  341. if (valid ^ ((taghi >> 27) & 1)) {
  342. printk(" ** bad parity for valid bit\n");
  343. res |= CP0_CERRI_TAG_PARITY;
  344. }
  345. printk(" %d [VA %016llx] [Vld? %d] raw tags: %08X-%016llX\n",
  346. way, va, valid, taghi, taglo);
  347. if (data) {
  348. uint32_t datahi, insta, instb;
  349. uint8_t predecode;
  350. int offset;
  351. /* (hit all banks and ways) */
  352. for (offset = 0; offset < 4; offset++) {
  353. /* Index-load-data-I */
  354. __asm__ __volatile__ (
  355. " .set push\n\t"
  356. " .set noreorder\n\t"
  357. " .set mips64\n\t"
  358. " .set noat\n\t"
  359. " cache 6, 0(%3) \n\t"
  360. " mfc0 %0, $29, 1\n\t"
  361. " dmfc0 $1, $28, 1\n\t"
  362. " dsrl32 %1, $1, 0 \n\t"
  363. " sll %2, $1, 0 \n\t"
  364. " .set pop \n"
  365. : "=r" (datahi), "=r" (insta), "=r" (instb)
  366. : "r" ((way << 13) | addr | (offset << 3)));
  367. predecode = (datahi >> 8) & 0xff;
  368. if (((datahi >> 16) & 1) != (uint32_t)range_parity(predecode, 7, 0)) {
  369. printk(" ** bad parity in predecode\n");
  370. res |= CP0_CERRI_DATA_PARITY;
  371. }
  372. /* XXXKW should/could check predecode bits themselves */
  373. if (((datahi >> 4) & 0xf) ^ inst_parity(insta)) {
  374. printk(" ** bad parity in instruction a\n");
  375. res |= CP0_CERRI_DATA_PARITY;
  376. }
  377. if ((datahi & 0xf) ^ inst_parity(instb)) {
  378. printk(" ** bad parity in instruction b\n");
  379. res |= CP0_CERRI_DATA_PARITY;
  380. }
  381. printk(" %05X-%08X%08X", datahi, insta, instb);
  382. }
  383. printk("\n");
  384. }
  385. }
  386. return res;
  387. }
  388. /* Compute the ECC for a data doubleword */
  389. static uint8_t dc_ecc(uint64_t dword)
  390. {
  391. uint64_t t;
  392. uint32_t w;
  393. uint8_t p;
  394. int i;
  395. p = 0;
  396. for (i = 7; i >= 0; i--)
  397. {
  398. p <<= 1;
  399. t = dword & mask_72_64[i];
  400. w = (uint32_t)(t >> 32);
  401. p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
  402. ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
  403. w = (uint32_t)(t & 0xFFFFFFFF);
  404. p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
  405. ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
  406. }
  407. return p;
  408. }
  409. struct dc_state {
  410. unsigned char val;
  411. char *name;
  412. };
  413. static struct dc_state dc_states[] = {
  414. { 0x00, "INVALID" },
  415. { 0x0f, "COH-SHD" },
  416. { 0x13, "NCO-E-C" },
  417. { 0x19, "NCO-E-D" },
  418. { 0x16, "COH-E-C" },
  419. { 0x1c, "COH-E-D" },
  420. { 0xff, "*ERROR*" }
  421. };
  422. #define DC_TAG_VALID(state) \
  423. (((state) == 0x0) || ((state) == 0xf) || ((state) == 0x13) || \
  424. ((state) == 0x19) || ((state) == 0x16) || ((state) == 0x1c))
  425. static char *dc_state_str(unsigned char state)
  426. {
  427. struct dc_state *dsc = dc_states;
  428. while (dsc->val != 0xff) {
  429. if (dsc->val == state)
  430. break;
  431. dsc++;
  432. }
  433. return dsc->name;
  434. }
  435. static uint32_t extract_dc(unsigned short addr, int data)
  436. {
  437. int valid, way;
  438. unsigned char state;
  439. uint32_t taghi, taglolo, taglohi;
  440. unsigned long long taglo, pa;
  441. uint8_t ecc, lru;
  442. int res = 0;
  443. printk("Dcache index 0x%04x ", addr);
  444. for (way = 0; way < 4; way++) {
  445. __asm__ __volatile__ (
  446. " .set push\n\t"
  447. " .set noreorder\n\t"
  448. " .set mips64\n\t"
  449. " .set noat\n\t"
  450. " cache 5, 0(%3)\n\t" /* Index-load-tag-D */
  451. " mfc0 %0, $29, 2\n\t"
  452. " dmfc0 $1, $28, 2\n\t"
  453. " dsrl32 %1, $1, 0\n\t"
  454. " sll %2, $1, 0\n\t"
  455. " .set pop"
  456. : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
  457. : "r" ((way << 13) | addr));
  458. taglo = ((unsigned long long)taglohi << 32) | taglolo;
  459. pa = (taglo & 0xFFFFFFE000ULL) | addr;
  460. if (way == 0) {
  461. lru = (taghi >> 14) & 0xff;
  462. printk("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
  463. ((addr >> 11) & 0x2) | ((addr >> 5) & 1), /* bank */
  464. ((addr >> 6) & 0x3f), /* index */
  465. (lru & 0x3),
  466. ((lru >> 2) & 0x3),
  467. ((lru >> 4) & 0x3),
  468. ((lru >> 6) & 0x3));
  469. }
  470. state = (taghi >> 25) & 0x1f;
  471. valid = DC_TAG_VALID(state);
  472. printk(" %d [PA %010llx] [state %s (%02x)] raw tags: %08X-%016llX\n",
  473. way, pa, dc_state_str(state), state, taghi, taglo);
  474. if (valid) {
  475. if (((taglo >> 11) & 1) ^ range_parity(taglo, 39, 26)) {
  476. printk(" ** bad parity in PTag1\n");
  477. res |= CP0_CERRD_TAG_ADDRESS;
  478. }
  479. if (((taglo >> 10) & 1) ^ range_parity(taglo, 25, 13)) {
  480. printk(" ** bad parity in PTag0\n");
  481. res |= CP0_CERRD_TAG_ADDRESS;
  482. }
  483. } else {
  484. res |= CP0_CERRD_TAG_STATE;
  485. }
  486. if (data) {
  487. uint32_t datalohi, datalolo, datahi;
  488. unsigned long long datalo;
  489. int offset;
  490. char bad_ecc = 0;
  491. for (offset = 0; offset < 4; offset++) {
  492. /* Index-load-data-D */
  493. __asm__ __volatile__ (
  494. " .set push\n\t"
  495. " .set noreorder\n\t"
  496. " .set mips64\n\t"
  497. " .set noat\n\t"
  498. " cache 7, 0(%3)\n\t" /* Index-load-data-D */
  499. " mfc0 %0, $29, 3\n\t"
  500. " dmfc0 $1, $28, 3\n\t"
  501. " dsrl32 %1, $1, 0 \n\t"
  502. " sll %2, $1, 0 \n\t"
  503. " .set pop"
  504. : "=r" (datahi), "=r" (datalohi), "=r" (datalolo)
  505. : "r" ((way << 13) | addr | (offset << 3)));
  506. datalo = ((unsigned long long)datalohi << 32) | datalolo;
  507. ecc = dc_ecc(datalo);
  508. if (ecc != datahi) {
  509. int bits;
  510. bad_ecc |= 1 << (3-offset);
  511. ecc ^= datahi;
  512. bits = hweight8(ecc);
  513. res |= (bits == 1) ? CP0_CERRD_DATA_SBE : CP0_CERRD_DATA_DBE;
  514. }
  515. printk(" %02X-%016llX", datahi, datalo);
  516. }
  517. printk("\n");
  518. if (bad_ecc)
  519. printk(" dwords w/ bad ECC: %d %d %d %d\n",
  520. !!(bad_ecc & 8), !!(bad_ecc & 4),
  521. !!(bad_ecc & 2), !!(bad_ecc & 1));
  522. }
  523. }
  524. return res;
  525. }