ie31200_edac.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /*
  2. * Intel E3-1200
  3. * Copyright (C) 2014 Jason Baron <jbaron@akamai.com>
  4. *
  5. * Support for the E3-1200 processor family. Heavily based on previous
  6. * Intel EDAC drivers.
  7. *
  8. * Since the DRAM controller is on the cpu chip, we can use its PCI device
  9. * id to identify these processors.
  10. *
  11. * PCI DRAM controller device ids (Taken from The PCI ID Repository - http://pci-ids.ucw.cz/)
  12. *
  13. * 0108: Xeon E3-1200 Processor Family DRAM Controller
  14. * 010c: Xeon E3-1200/2nd Generation Core Processor Family DRAM Controller
  15. * 0150: Xeon E3-1200 v2/3rd Gen Core processor DRAM Controller
  16. * 0158: Xeon E3-1200 v2/Ivy Bridge DRAM Controller
  17. * 015c: Xeon E3-1200 v2/3rd Gen Core processor DRAM Controller
  18. * 0c04: Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller
  19. * 0c08: Xeon E3-1200 v3 Processor DRAM Controller
  20. *
  21. * Based on Intel specification:
  22. * http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e3-1200v3-vol-2-datasheet.pdf
  23. * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e3-1200-family-vol-2-datasheet.html
  24. *
  25. * According to the above datasheet (p.16):
  26. * "
  27. * 6. Software must not access B0/D0/F0 32-bit memory-mapped registers with
  28. * requests that cross a DW boundary.
  29. * "
  30. *
  31. * Thus, we make use of the explicit: lo_hi_readq(), which breaks the readq into
  32. * 2 readl() calls. This restriction may be lifted in subsequent chip releases,
  33. * but lo_hi_readq() ensures that we are safe across all e3-1200 processors.
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/pci.h>
  38. #include <linux/pci_ids.h>
  39. #include <linux/edac.h>
  40. #include <linux/io-64-nonatomic-lo-hi.h>
  41. #include "edac_core.h"
  42. #define IE31200_REVISION "1.0"
  43. #define EDAC_MOD_STR "ie31200_edac"
  44. #define ie31200_printk(level, fmt, arg...) \
  45. edac_printk(level, "ie31200", fmt, ##arg)
  46. #define PCI_DEVICE_ID_INTEL_IE31200_HB_1 0x0108
  47. #define PCI_DEVICE_ID_INTEL_IE31200_HB_2 0x010c
  48. #define PCI_DEVICE_ID_INTEL_IE31200_HB_3 0x0150
  49. #define PCI_DEVICE_ID_INTEL_IE31200_HB_4 0x0158
  50. #define PCI_DEVICE_ID_INTEL_IE31200_HB_5 0x015c
  51. #define PCI_DEVICE_ID_INTEL_IE31200_HB_6 0x0c04
  52. #define PCI_DEVICE_ID_INTEL_IE31200_HB_7 0x0c08
  53. #define IE31200_DIMMS 4
  54. #define IE31200_RANKS 8
  55. #define IE31200_RANKS_PER_CHANNEL 4
  56. #define IE31200_DIMMS_PER_CHANNEL 2
  57. #define IE31200_CHANNELS 2
  58. /* Intel IE31200 register addresses - device 0 function 0 - DRAM Controller */
  59. #define IE31200_MCHBAR_LOW 0x48
  60. #define IE31200_MCHBAR_HIGH 0x4c
  61. #define IE31200_MCHBAR_MASK GENMASK_ULL(38, 15)
  62. #define IE31200_MMR_WINDOW_SIZE BIT(15)
  63. /*
  64. * Error Status Register (16b)
  65. *
  66. * 15 reserved
  67. * 14 Isochronous TBWRR Run Behind FIFO Full
  68. * (ITCV)
  69. * 13 Isochronous TBWRR Run Behind FIFO Put
  70. * (ITSTV)
  71. * 12 reserved
  72. * 11 MCH Thermal Sensor Event
  73. * for SMI/SCI/SERR (GTSE)
  74. * 10 reserved
  75. * 9 LOCK to non-DRAM Memory Flag (LCKF)
  76. * 8 reserved
  77. * 7 DRAM Throttle Flag (DTF)
  78. * 6:2 reserved
  79. * 1 Multi-bit DRAM ECC Error Flag (DMERR)
  80. * 0 Single-bit DRAM ECC Error Flag (DSERR)
  81. */
  82. #define IE31200_ERRSTS 0xc8
  83. #define IE31200_ERRSTS_UE BIT(1)
  84. #define IE31200_ERRSTS_CE BIT(0)
  85. #define IE31200_ERRSTS_BITS (IE31200_ERRSTS_UE | IE31200_ERRSTS_CE)
  86. /*
  87. * Channel 0 ECC Error Log (64b)
  88. *
  89. * 63:48 Error Column Address (ERRCOL)
  90. * 47:32 Error Row Address (ERRROW)
  91. * 31:29 Error Bank Address (ERRBANK)
  92. * 28:27 Error Rank Address (ERRRANK)
  93. * 26:24 reserved
  94. * 23:16 Error Syndrome (ERRSYND)
  95. * 15: 2 reserved
  96. * 1 Multiple Bit Error Status (MERRSTS)
  97. * 0 Correctable Error Status (CERRSTS)
  98. */
  99. #define IE31200_C0ECCERRLOG 0x40c8
  100. #define IE31200_C1ECCERRLOG 0x44c8
  101. #define IE31200_ECCERRLOG_CE BIT(0)
  102. #define IE31200_ECCERRLOG_UE BIT(1)
  103. #define IE31200_ECCERRLOG_RANK_BITS GENMASK_ULL(28, 27)
  104. #define IE31200_ECCERRLOG_RANK_SHIFT 27
  105. #define IE31200_ECCERRLOG_SYNDROME_BITS GENMASK_ULL(23, 16)
  106. #define IE31200_ECCERRLOG_SYNDROME_SHIFT 16
  107. #define IE31200_ECCERRLOG_SYNDROME(log) \
  108. ((log & IE31200_ECCERRLOG_SYNDROME_BITS) >> \
  109. IE31200_ECCERRLOG_SYNDROME_SHIFT)
  110. #define IE31200_CAPID0 0xe4
  111. #define IE31200_CAPID0_PDCD BIT(4)
  112. #define IE31200_CAPID0_DDPCD BIT(6)
  113. #define IE31200_CAPID0_ECC BIT(1)
  114. #define IE31200_MAD_DIMM_0_OFFSET 0x5004
  115. #define IE31200_MAD_DIMM_SIZE GENMASK_ULL(7, 0)
  116. #define IE31200_MAD_DIMM_A_RANK BIT(17)
  117. #define IE31200_MAD_DIMM_A_WIDTH BIT(19)
  118. #define IE31200_PAGES(n) (n << (28 - PAGE_SHIFT))
  119. static int nr_channels;
  120. struct ie31200_priv {
  121. void __iomem *window;
  122. };
  123. enum ie31200_chips {
  124. IE31200 = 0,
  125. };
  126. struct ie31200_dev_info {
  127. const char *ctl_name;
  128. };
  129. struct ie31200_error_info {
  130. u16 errsts;
  131. u16 errsts2;
  132. u64 eccerrlog[IE31200_CHANNELS];
  133. };
  134. static const struct ie31200_dev_info ie31200_devs[] = {
  135. [IE31200] = {
  136. .ctl_name = "IE31200"
  137. },
  138. };
  139. struct dimm_data {
  140. u8 size; /* in 256MB multiples */
  141. u8 dual_rank : 1,
  142. x16_width : 1; /* 0 means x8 width */
  143. };
  144. static int how_many_channels(struct pci_dev *pdev)
  145. {
  146. int n_channels;
  147. unsigned char capid0_2b; /* 2nd byte of CAPID0 */
  148. pci_read_config_byte(pdev, IE31200_CAPID0 + 1, &capid0_2b);
  149. /* check PDCD: Dual Channel Disable */
  150. if (capid0_2b & IE31200_CAPID0_PDCD) {
  151. edac_dbg(0, "In single channel mode\n");
  152. n_channels = 1;
  153. } else {
  154. edac_dbg(0, "In dual channel mode\n");
  155. n_channels = 2;
  156. }
  157. /* check DDPCD - check if both channels are filled */
  158. if (capid0_2b & IE31200_CAPID0_DDPCD)
  159. edac_dbg(0, "2 DIMMS per channel disabled\n");
  160. else
  161. edac_dbg(0, "2 DIMMS per channel enabled\n");
  162. return n_channels;
  163. }
  164. static bool ecc_capable(struct pci_dev *pdev)
  165. {
  166. unsigned char capid0_4b; /* 4th byte of CAPID0 */
  167. pci_read_config_byte(pdev, IE31200_CAPID0 + 3, &capid0_4b);
  168. if (capid0_4b & IE31200_CAPID0_ECC)
  169. return false;
  170. return true;
  171. }
  172. static int eccerrlog_row(int channel, u64 log)
  173. {
  174. int rank = ((log & IE31200_ECCERRLOG_RANK_BITS) >>
  175. IE31200_ECCERRLOG_RANK_SHIFT);
  176. return rank | (channel * IE31200_RANKS_PER_CHANNEL);
  177. }
  178. static void ie31200_clear_error_info(struct mem_ctl_info *mci)
  179. {
  180. /*
  181. * Clear any error bits.
  182. * (Yes, we really clear bits by writing 1 to them.)
  183. */
  184. pci_write_bits16(to_pci_dev(mci->pdev), IE31200_ERRSTS,
  185. IE31200_ERRSTS_BITS, IE31200_ERRSTS_BITS);
  186. }
  187. static void ie31200_get_and_clear_error_info(struct mem_ctl_info *mci,
  188. struct ie31200_error_info *info)
  189. {
  190. struct pci_dev *pdev;
  191. struct ie31200_priv *priv = mci->pvt_info;
  192. void __iomem *window = priv->window;
  193. pdev = to_pci_dev(mci->pdev);
  194. /*
  195. * This is a mess because there is no atomic way to read all the
  196. * registers at once and the registers can transition from CE being
  197. * overwritten by UE.
  198. */
  199. pci_read_config_word(pdev, IE31200_ERRSTS, &info->errsts);
  200. if (!(info->errsts & IE31200_ERRSTS_BITS))
  201. return;
  202. info->eccerrlog[0] = lo_hi_readq(window + IE31200_C0ECCERRLOG);
  203. if (nr_channels == 2)
  204. info->eccerrlog[1] = lo_hi_readq(window + IE31200_C1ECCERRLOG);
  205. pci_read_config_word(pdev, IE31200_ERRSTS, &info->errsts2);
  206. /*
  207. * If the error is the same for both reads then the first set
  208. * of reads is valid. If there is a change then there is a CE
  209. * with no info and the second set of reads is valid and
  210. * should be UE info.
  211. */
  212. if ((info->errsts ^ info->errsts2) & IE31200_ERRSTS_BITS) {
  213. info->eccerrlog[0] = lo_hi_readq(window + IE31200_C0ECCERRLOG);
  214. if (nr_channels == 2)
  215. info->eccerrlog[1] =
  216. lo_hi_readq(window + IE31200_C1ECCERRLOG);
  217. }
  218. ie31200_clear_error_info(mci);
  219. }
  220. static void ie31200_process_error_info(struct mem_ctl_info *mci,
  221. struct ie31200_error_info *info)
  222. {
  223. int channel;
  224. u64 log;
  225. if (!(info->errsts & IE31200_ERRSTS_BITS))
  226. return;
  227. if ((info->errsts ^ info->errsts2) & IE31200_ERRSTS_BITS) {
  228. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
  229. -1, -1, -1, "UE overwrote CE", "");
  230. info->errsts = info->errsts2;
  231. }
  232. for (channel = 0; channel < nr_channels; channel++) {
  233. log = info->eccerrlog[channel];
  234. if (log & IE31200_ECCERRLOG_UE) {
  235. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  236. 0, 0, 0,
  237. eccerrlog_row(channel, log),
  238. channel, -1,
  239. "ie31200 UE", "");
  240. } else if (log & IE31200_ECCERRLOG_CE) {
  241. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  242. 0, 0,
  243. IE31200_ECCERRLOG_SYNDROME(log),
  244. eccerrlog_row(channel, log),
  245. channel, -1,
  246. "ie31200 CE", "");
  247. }
  248. }
  249. }
  250. static void ie31200_check(struct mem_ctl_info *mci)
  251. {
  252. struct ie31200_error_info info;
  253. edac_dbg(1, "MC%d\n", mci->mc_idx);
  254. ie31200_get_and_clear_error_info(mci, &info);
  255. ie31200_process_error_info(mci, &info);
  256. }
  257. static void __iomem *ie31200_map_mchbar(struct pci_dev *pdev)
  258. {
  259. union {
  260. u64 mchbar;
  261. struct {
  262. u32 mchbar_low;
  263. u32 mchbar_high;
  264. };
  265. } u;
  266. void __iomem *window;
  267. pci_read_config_dword(pdev, IE31200_MCHBAR_LOW, &u.mchbar_low);
  268. pci_read_config_dword(pdev, IE31200_MCHBAR_HIGH, &u.mchbar_high);
  269. u.mchbar &= IE31200_MCHBAR_MASK;
  270. if (u.mchbar != (resource_size_t)u.mchbar) {
  271. ie31200_printk(KERN_ERR, "mmio space beyond accessible range (0x%llx)\n",
  272. (unsigned long long)u.mchbar);
  273. return NULL;
  274. }
  275. window = ioremap_nocache(u.mchbar, IE31200_MMR_WINDOW_SIZE);
  276. if (!window)
  277. ie31200_printk(KERN_ERR, "Cannot map mmio space at 0x%llx\n",
  278. (unsigned long long)u.mchbar);
  279. return window;
  280. }
  281. static int ie31200_probe1(struct pci_dev *pdev, int dev_idx)
  282. {
  283. int i, j, ret;
  284. struct mem_ctl_info *mci = NULL;
  285. struct edac_mc_layer layers[2];
  286. struct dimm_data dimm_info[IE31200_CHANNELS][IE31200_DIMMS_PER_CHANNEL];
  287. void __iomem *window;
  288. struct ie31200_priv *priv;
  289. u32 addr_decode;
  290. edac_dbg(0, "MC:\n");
  291. if (!ecc_capable(pdev)) {
  292. ie31200_printk(KERN_INFO, "No ECC support\n");
  293. return -ENODEV;
  294. }
  295. nr_channels = how_many_channels(pdev);
  296. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  297. layers[0].size = IE31200_DIMMS;
  298. layers[0].is_virt_csrow = true;
  299. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  300. layers[1].size = nr_channels;
  301. layers[1].is_virt_csrow = false;
  302. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
  303. sizeof(struct ie31200_priv));
  304. if (!mci)
  305. return -ENOMEM;
  306. window = ie31200_map_mchbar(pdev);
  307. if (!window) {
  308. ret = -ENODEV;
  309. goto fail_free;
  310. }
  311. edac_dbg(3, "MC: init mci\n");
  312. mci->pdev = &pdev->dev;
  313. mci->mtype_cap = MEM_FLAG_DDR3;
  314. mci->edac_ctl_cap = EDAC_FLAG_SECDED;
  315. mci->edac_cap = EDAC_FLAG_SECDED;
  316. mci->mod_name = EDAC_MOD_STR;
  317. mci->mod_ver = IE31200_REVISION;
  318. mci->ctl_name = ie31200_devs[dev_idx].ctl_name;
  319. mci->dev_name = pci_name(pdev);
  320. mci->edac_check = ie31200_check;
  321. mci->ctl_page_to_phys = NULL;
  322. priv = mci->pvt_info;
  323. priv->window = window;
  324. /* populate DIMM info */
  325. for (i = 0; i < IE31200_CHANNELS; i++) {
  326. addr_decode = readl(window + IE31200_MAD_DIMM_0_OFFSET +
  327. (i * 4));
  328. edac_dbg(0, "addr_decode: 0x%x\n", addr_decode);
  329. for (j = 0; j < IE31200_DIMMS_PER_CHANNEL; j++) {
  330. dimm_info[i][j].size = (addr_decode >> (j * 8)) &
  331. IE31200_MAD_DIMM_SIZE;
  332. dimm_info[i][j].dual_rank = (addr_decode &
  333. (IE31200_MAD_DIMM_A_RANK << j)) ? 1 : 0;
  334. dimm_info[i][j].x16_width = (addr_decode &
  335. (IE31200_MAD_DIMM_A_WIDTH << j)) ? 1 : 0;
  336. edac_dbg(0, "size: 0x%x, rank: %d, width: %d\n",
  337. dimm_info[i][j].size,
  338. dimm_info[i][j].dual_rank,
  339. dimm_info[i][j].x16_width);
  340. }
  341. }
  342. /*
  343. * The dram rank boundary (DRB) reg values are boundary addresses
  344. * for each DRAM rank with a granularity of 64MB. DRB regs are
  345. * cumulative; the last one will contain the total memory
  346. * contained in all ranks.
  347. */
  348. for (i = 0; i < IE31200_DIMMS_PER_CHANNEL; i++) {
  349. for (j = 0; j < IE31200_CHANNELS; j++) {
  350. struct dimm_info *dimm;
  351. unsigned long nr_pages;
  352. nr_pages = IE31200_PAGES(dimm_info[j][i].size);
  353. if (nr_pages == 0)
  354. continue;
  355. if (dimm_info[j][i].dual_rank) {
  356. nr_pages = nr_pages / 2;
  357. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
  358. mci->n_layers, (i * 2) + 1,
  359. j, 0);
  360. dimm->nr_pages = nr_pages;
  361. edac_dbg(0, "set nr pages: 0x%lx\n", nr_pages);
  362. dimm->grain = 8; /* just a guess */
  363. dimm->mtype = MEM_DDR3;
  364. dimm->dtype = DEV_UNKNOWN;
  365. dimm->edac_mode = EDAC_UNKNOWN;
  366. }
  367. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
  368. mci->n_layers, i * 2, j, 0);
  369. dimm->nr_pages = nr_pages;
  370. edac_dbg(0, "set nr pages: 0x%lx\n", nr_pages);
  371. dimm->grain = 8; /* same guess */
  372. dimm->mtype = MEM_DDR3;
  373. dimm->dtype = DEV_UNKNOWN;
  374. dimm->edac_mode = EDAC_UNKNOWN;
  375. }
  376. }
  377. ie31200_clear_error_info(mci);
  378. if (edac_mc_add_mc(mci)) {
  379. edac_dbg(3, "MC: failed edac_mc_add_mc()\n");
  380. ret = -ENODEV;
  381. goto fail_unmap;
  382. }
  383. /* get this far and it's successful */
  384. edac_dbg(3, "MC: success\n");
  385. return 0;
  386. fail_unmap:
  387. iounmap(window);
  388. fail_free:
  389. edac_mc_free(mci);
  390. return ret;
  391. }
  392. static int ie31200_init_one(struct pci_dev *pdev,
  393. const struct pci_device_id *ent)
  394. {
  395. edac_dbg(0, "MC:\n");
  396. if (pci_enable_device(pdev) < 0)
  397. return -EIO;
  398. return ie31200_probe1(pdev, ent->driver_data);
  399. }
  400. static void ie31200_remove_one(struct pci_dev *pdev)
  401. {
  402. struct mem_ctl_info *mci;
  403. struct ie31200_priv *priv;
  404. edac_dbg(0, "\n");
  405. mci = edac_mc_del_mc(&pdev->dev);
  406. if (!mci)
  407. return;
  408. priv = mci->pvt_info;
  409. iounmap(priv->window);
  410. edac_mc_free(mci);
  411. }
  412. static const struct pci_device_id ie31200_pci_tbl[] = {
  413. {
  414. PCI_VEND_DEV(INTEL, IE31200_HB_1), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  415. IE31200},
  416. {
  417. PCI_VEND_DEV(INTEL, IE31200_HB_2), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  418. IE31200},
  419. {
  420. PCI_VEND_DEV(INTEL, IE31200_HB_3), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  421. IE31200},
  422. {
  423. PCI_VEND_DEV(INTEL, IE31200_HB_4), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  424. IE31200},
  425. {
  426. PCI_VEND_DEV(INTEL, IE31200_HB_5), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  427. IE31200},
  428. {
  429. PCI_VEND_DEV(INTEL, IE31200_HB_6), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  430. IE31200},
  431. {
  432. PCI_VEND_DEV(INTEL, IE31200_HB_7), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  433. IE31200},
  434. {
  435. 0,
  436. } /* 0 terminated list. */
  437. };
  438. MODULE_DEVICE_TABLE(pci, ie31200_pci_tbl);
  439. static struct pci_driver ie31200_driver = {
  440. .name = EDAC_MOD_STR,
  441. .probe = ie31200_init_one,
  442. .remove = ie31200_remove_one,
  443. .id_table = ie31200_pci_tbl,
  444. };
  445. static int __init ie31200_init(void)
  446. {
  447. edac_dbg(3, "MC:\n");
  448. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  449. opstate_init();
  450. return pci_register_driver(&ie31200_driver);
  451. }
  452. static void __exit ie31200_exit(void)
  453. {
  454. edac_dbg(3, "MC:\n");
  455. pci_unregister_driver(&ie31200_driver);
  456. }
  457. module_init(ie31200_init);
  458. module_exit(ie31200_exit);
  459. MODULE_LICENSE("GPL");
  460. MODULE_AUTHOR("Jason Baron <jbaron@akamai.com>");
  461. MODULE_DESCRIPTION("MC support for Intel Processor E31200 memory hub controllers");