ie31200_edac.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel E3-1200
  4. * Copyright (C) 2014 Jason Baron <[email protected]>
  5. *
  6. * Support for the E3-1200 processor family. Heavily based on previous
  7. * Intel EDAC drivers.
  8. *
  9. * Since the DRAM controller is on the cpu chip, we can use its PCI device
  10. * id to identify these processors.
  11. *
  12. * PCI DRAM controller device ids (Taken from The PCI ID Repository - https://pci-ids.ucw.cz/)
  13. *
  14. * 0108: Xeon E3-1200 Processor Family DRAM Controller
  15. * 010c: Xeon E3-1200/2nd Generation Core Processor Family DRAM Controller
  16. * 0150: Xeon E3-1200 v2/3rd Gen Core processor DRAM Controller
  17. * 0158: Xeon E3-1200 v2/Ivy Bridge DRAM Controller
  18. * 015c: Xeon E3-1200 v2/3rd Gen Core processor DRAM Controller
  19. * 0c04: Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller
  20. * 0c08: Xeon E3-1200 v3 Processor DRAM Controller
  21. * 1918: Xeon E3-1200 v5 Skylake Host Bridge/DRAM Registers
  22. * 5918: Xeon E3-1200 Xeon E3-1200 v6/7th Gen Core Processor Host Bridge/DRAM Registers
  23. * 190f: 6th Gen Core Dual-Core Processor Host Bridge/DRAM Registers
  24. * 191f: 6th Gen Core Quad-Core Processor Host Bridge/DRAM Registers
  25. * 3e..: 8th/9th Gen Core Processor Host Bridge/DRAM Registers
  26. *
  27. * Based on Intel specification:
  28. * https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e3-1200v3-vol-2-datasheet.pdf
  29. * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e3-1200-family-vol-2-datasheet.html
  30. * https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/desktop-6th-gen-core-family-datasheet-vol-2.pdf
  31. * https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e3-1200v6-vol-2-datasheet.pdf
  32. * https://www.intel.com/content/www/us/en/processors/core/7th-gen-core-family-mobile-h-processor-lines-datasheet-vol-2.html
  33. * https://www.intel.com/content/www/us/en/products/docs/processors/core/8th-gen-core-family-datasheet-vol-2.html
  34. *
  35. * According to the above datasheet (p.16):
  36. * "
  37. * 6. Software must not access B0/D0/F0 32-bit memory-mapped registers with
  38. * requests that cross a DW boundary.
  39. * "
  40. *
  41. * Thus, we make use of the explicit: lo_hi_readq(), which breaks the readq into
  42. * 2 readl() calls. This restriction may be lifted in subsequent chip releases,
  43. * but lo_hi_readq() ensures that we are safe across all e3-1200 processors.
  44. */
  45. #include <linux/module.h>
  46. #include <linux/init.h>
  47. #include <linux/pci.h>
  48. #include <linux/pci_ids.h>
  49. #include <linux/edac.h>
  50. #include <linux/io-64-nonatomic-lo-hi.h>
  51. #include "edac_module.h"
  52. #define EDAC_MOD_STR "ie31200_edac"
  53. #define ie31200_printk(level, fmt, arg...) \
  54. edac_printk(level, "ie31200", fmt, ##arg)
  55. #define PCI_DEVICE_ID_INTEL_IE31200_HB_1 0x0108
  56. #define PCI_DEVICE_ID_INTEL_IE31200_HB_2 0x010c
  57. #define PCI_DEVICE_ID_INTEL_IE31200_HB_3 0x0150
  58. #define PCI_DEVICE_ID_INTEL_IE31200_HB_4 0x0158
  59. #define PCI_DEVICE_ID_INTEL_IE31200_HB_5 0x015c
  60. #define PCI_DEVICE_ID_INTEL_IE31200_HB_6 0x0c04
  61. #define PCI_DEVICE_ID_INTEL_IE31200_HB_7 0x0c08
  62. #define PCI_DEVICE_ID_INTEL_IE31200_HB_8 0x190F
  63. #define PCI_DEVICE_ID_INTEL_IE31200_HB_9 0x1918
  64. #define PCI_DEVICE_ID_INTEL_IE31200_HB_10 0x191F
  65. #define PCI_DEVICE_ID_INTEL_IE31200_HB_11 0x5918
  66. /* Coffee Lake-S */
  67. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_MASK 0x3e00
  68. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_1 0x3e0f
  69. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_2 0x3e18
  70. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_3 0x3e1f
  71. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_4 0x3e30
  72. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_5 0x3e31
  73. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_6 0x3e32
  74. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_7 0x3e33
  75. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_8 0x3ec2
  76. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_9 0x3ec6
  77. #define PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_10 0x3eca
  78. /* Test if HB is for Skylake or later. */
  79. #define DEVICE_ID_SKYLAKE_OR_LATER(did) \
  80. (((did) == PCI_DEVICE_ID_INTEL_IE31200_HB_8) || \
  81. ((did) == PCI_DEVICE_ID_INTEL_IE31200_HB_9) || \
  82. ((did) == PCI_DEVICE_ID_INTEL_IE31200_HB_10) || \
  83. ((did) == PCI_DEVICE_ID_INTEL_IE31200_HB_11) || \
  84. (((did) & PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_MASK) == \
  85. PCI_DEVICE_ID_INTEL_IE31200_HB_CFL_MASK))
  86. #define IE31200_DIMMS 4
  87. #define IE31200_RANKS 8
  88. #define IE31200_RANKS_PER_CHANNEL 4
  89. #define IE31200_DIMMS_PER_CHANNEL 2
  90. #define IE31200_CHANNELS 2
  91. /* Intel IE31200 register addresses - device 0 function 0 - DRAM Controller */
  92. #define IE31200_MCHBAR_LOW 0x48
  93. #define IE31200_MCHBAR_HIGH 0x4c
  94. #define IE31200_MCHBAR_MASK GENMASK_ULL(38, 15)
  95. #define IE31200_MMR_WINDOW_SIZE BIT(15)
  96. /*
  97. * Error Status Register (16b)
  98. *
  99. * 15 reserved
  100. * 14 Isochronous TBWRR Run Behind FIFO Full
  101. * (ITCV)
  102. * 13 Isochronous TBWRR Run Behind FIFO Put
  103. * (ITSTV)
  104. * 12 reserved
  105. * 11 MCH Thermal Sensor Event
  106. * for SMI/SCI/SERR (GTSE)
  107. * 10 reserved
  108. * 9 LOCK to non-DRAM Memory Flag (LCKF)
  109. * 8 reserved
  110. * 7 DRAM Throttle Flag (DTF)
  111. * 6:2 reserved
  112. * 1 Multi-bit DRAM ECC Error Flag (DMERR)
  113. * 0 Single-bit DRAM ECC Error Flag (DSERR)
  114. */
  115. #define IE31200_ERRSTS 0xc8
  116. #define IE31200_ERRSTS_UE BIT(1)
  117. #define IE31200_ERRSTS_CE BIT(0)
  118. #define IE31200_ERRSTS_BITS (IE31200_ERRSTS_UE | IE31200_ERRSTS_CE)
  119. /*
  120. * Channel 0 ECC Error Log (64b)
  121. *
  122. * 63:48 Error Column Address (ERRCOL)
  123. * 47:32 Error Row Address (ERRROW)
  124. * 31:29 Error Bank Address (ERRBANK)
  125. * 28:27 Error Rank Address (ERRRANK)
  126. * 26:24 reserved
  127. * 23:16 Error Syndrome (ERRSYND)
  128. * 15: 2 reserved
  129. * 1 Multiple Bit Error Status (MERRSTS)
  130. * 0 Correctable Error Status (CERRSTS)
  131. */
  132. #define IE31200_C0ECCERRLOG 0x40c8
  133. #define IE31200_C1ECCERRLOG 0x44c8
  134. #define IE31200_C0ECCERRLOG_SKL 0x4048
  135. #define IE31200_C1ECCERRLOG_SKL 0x4448
  136. #define IE31200_ECCERRLOG_CE BIT(0)
  137. #define IE31200_ECCERRLOG_UE BIT(1)
  138. #define IE31200_ECCERRLOG_RANK_BITS GENMASK_ULL(28, 27)
  139. #define IE31200_ECCERRLOG_RANK_SHIFT 27
  140. #define IE31200_ECCERRLOG_SYNDROME_BITS GENMASK_ULL(23, 16)
  141. #define IE31200_ECCERRLOG_SYNDROME_SHIFT 16
  142. #define IE31200_ECCERRLOG_SYNDROME(log) \
  143. ((log & IE31200_ECCERRLOG_SYNDROME_BITS) >> \
  144. IE31200_ECCERRLOG_SYNDROME_SHIFT)
  145. #define IE31200_CAPID0 0xe4
  146. #define IE31200_CAPID0_PDCD BIT(4)
  147. #define IE31200_CAPID0_DDPCD BIT(6)
  148. #define IE31200_CAPID0_ECC BIT(1)
  149. #define IE31200_MAD_DIMM_0_OFFSET 0x5004
  150. #define IE31200_MAD_DIMM_0_OFFSET_SKL 0x500C
  151. #define IE31200_MAD_DIMM_SIZE GENMASK_ULL(7, 0)
  152. #define IE31200_MAD_DIMM_A_RANK BIT(17)
  153. #define IE31200_MAD_DIMM_A_RANK_SHIFT 17
  154. #define IE31200_MAD_DIMM_A_RANK_SKL BIT(10)
  155. #define IE31200_MAD_DIMM_A_RANK_SKL_SHIFT 10
  156. #define IE31200_MAD_DIMM_A_WIDTH BIT(19)
  157. #define IE31200_MAD_DIMM_A_WIDTH_SHIFT 19
  158. #define IE31200_MAD_DIMM_A_WIDTH_SKL GENMASK_ULL(9, 8)
  159. #define IE31200_MAD_DIMM_A_WIDTH_SKL_SHIFT 8
  160. /* Skylake reports 1GB increments, everything else is 256MB */
  161. #define IE31200_PAGES(n, skl) \
  162. (n << (28 + (2 * skl) - PAGE_SHIFT))
  163. static int nr_channels;
  164. static struct pci_dev *mci_pdev;
  165. static int ie31200_registered = 1;
  166. struct ie31200_priv {
  167. void __iomem *window;
  168. void __iomem *c0errlog;
  169. void __iomem *c1errlog;
  170. };
  171. enum ie31200_chips {
  172. IE31200 = 0,
  173. };
  174. struct ie31200_dev_info {
  175. const char *ctl_name;
  176. };
  177. struct ie31200_error_info {
  178. u16 errsts;
  179. u16 errsts2;
  180. u64 eccerrlog[IE31200_CHANNELS];
  181. };
  182. static const struct ie31200_dev_info ie31200_devs[] = {
  183. [IE31200] = {
  184. .ctl_name = "IE31200"
  185. },
  186. };
  187. struct dimm_data {
  188. u8 size; /* in multiples of 256MB, except Skylake is 1GB */
  189. u8 dual_rank : 1,
  190. x16_width : 2; /* 0 means x8 width */
  191. };
  192. static int how_many_channels(struct pci_dev *pdev)
  193. {
  194. int n_channels;
  195. unsigned char capid0_2b; /* 2nd byte of CAPID0 */
  196. pci_read_config_byte(pdev, IE31200_CAPID0 + 1, &capid0_2b);
  197. /* check PDCD: Dual Channel Disable */
  198. if (capid0_2b & IE31200_CAPID0_PDCD) {
  199. edac_dbg(0, "In single channel mode\n");
  200. n_channels = 1;
  201. } else {
  202. edac_dbg(0, "In dual channel mode\n");
  203. n_channels = 2;
  204. }
  205. /* check DDPCD - check if both channels are filled */
  206. if (capid0_2b & IE31200_CAPID0_DDPCD)
  207. edac_dbg(0, "2 DIMMS per channel disabled\n");
  208. else
  209. edac_dbg(0, "2 DIMMS per channel enabled\n");
  210. return n_channels;
  211. }
  212. static bool ecc_capable(struct pci_dev *pdev)
  213. {
  214. unsigned char capid0_4b; /* 4th byte of CAPID0 */
  215. pci_read_config_byte(pdev, IE31200_CAPID0 + 3, &capid0_4b);
  216. if (capid0_4b & IE31200_CAPID0_ECC)
  217. return false;
  218. return true;
  219. }
  220. static int eccerrlog_row(u64 log)
  221. {
  222. return ((log & IE31200_ECCERRLOG_RANK_BITS) >>
  223. IE31200_ECCERRLOG_RANK_SHIFT);
  224. }
  225. static void ie31200_clear_error_info(struct mem_ctl_info *mci)
  226. {
  227. /*
  228. * Clear any error bits.
  229. * (Yes, we really clear bits by writing 1 to them.)
  230. */
  231. pci_write_bits16(to_pci_dev(mci->pdev), IE31200_ERRSTS,
  232. IE31200_ERRSTS_BITS, IE31200_ERRSTS_BITS);
  233. }
  234. static void ie31200_get_and_clear_error_info(struct mem_ctl_info *mci,
  235. struct ie31200_error_info *info)
  236. {
  237. struct pci_dev *pdev;
  238. struct ie31200_priv *priv = mci->pvt_info;
  239. pdev = to_pci_dev(mci->pdev);
  240. /*
  241. * This is a mess because there is no atomic way to read all the
  242. * registers at once and the registers can transition from CE being
  243. * overwritten by UE.
  244. */
  245. pci_read_config_word(pdev, IE31200_ERRSTS, &info->errsts);
  246. if (!(info->errsts & IE31200_ERRSTS_BITS))
  247. return;
  248. info->eccerrlog[0] = lo_hi_readq(priv->c0errlog);
  249. if (nr_channels == 2)
  250. info->eccerrlog[1] = lo_hi_readq(priv->c1errlog);
  251. pci_read_config_word(pdev, IE31200_ERRSTS, &info->errsts2);
  252. /*
  253. * If the error is the same for both reads then the first set
  254. * of reads is valid. If there is a change then there is a CE
  255. * with no info and the second set of reads is valid and
  256. * should be UE info.
  257. */
  258. if ((info->errsts ^ info->errsts2) & IE31200_ERRSTS_BITS) {
  259. info->eccerrlog[0] = lo_hi_readq(priv->c0errlog);
  260. if (nr_channels == 2)
  261. info->eccerrlog[1] =
  262. lo_hi_readq(priv->c1errlog);
  263. }
  264. ie31200_clear_error_info(mci);
  265. }
  266. static void ie31200_process_error_info(struct mem_ctl_info *mci,
  267. struct ie31200_error_info *info)
  268. {
  269. int channel;
  270. u64 log;
  271. if (!(info->errsts & IE31200_ERRSTS_BITS))
  272. return;
  273. if ((info->errsts ^ info->errsts2) & IE31200_ERRSTS_BITS) {
  274. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
  275. -1, -1, -1, "UE overwrote CE", "");
  276. info->errsts = info->errsts2;
  277. }
  278. for (channel = 0; channel < nr_channels; channel++) {
  279. log = info->eccerrlog[channel];
  280. if (log & IE31200_ECCERRLOG_UE) {
  281. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  282. 0, 0, 0,
  283. eccerrlog_row(log),
  284. channel, -1,
  285. "ie31200 UE", "");
  286. } else if (log & IE31200_ECCERRLOG_CE) {
  287. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  288. 0, 0,
  289. IE31200_ECCERRLOG_SYNDROME(log),
  290. eccerrlog_row(log),
  291. channel, -1,
  292. "ie31200 CE", "");
  293. }
  294. }
  295. }
  296. static void ie31200_check(struct mem_ctl_info *mci)
  297. {
  298. struct ie31200_error_info info;
  299. ie31200_get_and_clear_error_info(mci, &info);
  300. ie31200_process_error_info(mci, &info);
  301. }
  302. static void __iomem *ie31200_map_mchbar(struct pci_dev *pdev)
  303. {
  304. union {
  305. u64 mchbar;
  306. struct {
  307. u32 mchbar_low;
  308. u32 mchbar_high;
  309. };
  310. } u;
  311. void __iomem *window;
  312. pci_read_config_dword(pdev, IE31200_MCHBAR_LOW, &u.mchbar_low);
  313. pci_read_config_dword(pdev, IE31200_MCHBAR_HIGH, &u.mchbar_high);
  314. u.mchbar &= IE31200_MCHBAR_MASK;
  315. if (u.mchbar != (resource_size_t)u.mchbar) {
  316. ie31200_printk(KERN_ERR, "mmio space beyond accessible range (0x%llx)\n",
  317. (unsigned long long)u.mchbar);
  318. return NULL;
  319. }
  320. window = ioremap(u.mchbar, IE31200_MMR_WINDOW_SIZE);
  321. if (!window)
  322. ie31200_printk(KERN_ERR, "Cannot map mmio space at 0x%llx\n",
  323. (unsigned long long)u.mchbar);
  324. return window;
  325. }
  326. static void __skl_populate_dimm_info(struct dimm_data *dd, u32 addr_decode,
  327. int chan)
  328. {
  329. dd->size = (addr_decode >> (chan << 4)) & IE31200_MAD_DIMM_SIZE;
  330. dd->dual_rank = (addr_decode & (IE31200_MAD_DIMM_A_RANK_SKL << (chan << 4))) ? 1 : 0;
  331. dd->x16_width = ((addr_decode & (IE31200_MAD_DIMM_A_WIDTH_SKL << (chan << 4))) >>
  332. (IE31200_MAD_DIMM_A_WIDTH_SKL_SHIFT + (chan << 4)));
  333. }
  334. static void __populate_dimm_info(struct dimm_data *dd, u32 addr_decode,
  335. int chan)
  336. {
  337. dd->size = (addr_decode >> (chan << 3)) & IE31200_MAD_DIMM_SIZE;
  338. dd->dual_rank = (addr_decode & (IE31200_MAD_DIMM_A_RANK << chan)) ? 1 : 0;
  339. dd->x16_width = (addr_decode & (IE31200_MAD_DIMM_A_WIDTH << chan)) ? 1 : 0;
  340. }
  341. static void populate_dimm_info(struct dimm_data *dd, u32 addr_decode, int chan,
  342. bool skl)
  343. {
  344. if (skl)
  345. __skl_populate_dimm_info(dd, addr_decode, chan);
  346. else
  347. __populate_dimm_info(dd, addr_decode, chan);
  348. }
  349. static int ie31200_probe1(struct pci_dev *pdev, int dev_idx)
  350. {
  351. int i, j, ret;
  352. struct mem_ctl_info *mci = NULL;
  353. struct edac_mc_layer layers[2];
  354. struct dimm_data dimm_info[IE31200_CHANNELS][IE31200_DIMMS_PER_CHANNEL];
  355. void __iomem *window;
  356. struct ie31200_priv *priv;
  357. u32 addr_decode, mad_offset;
  358. /*
  359. * Kaby Lake, Coffee Lake seem to work like Skylake. Please re-visit
  360. * this logic when adding new CPU support.
  361. */
  362. bool skl = DEVICE_ID_SKYLAKE_OR_LATER(pdev->device);
  363. edac_dbg(0, "MC:\n");
  364. if (!ecc_capable(pdev)) {
  365. ie31200_printk(KERN_INFO, "No ECC support\n");
  366. return -ENODEV;
  367. }
  368. nr_channels = how_many_channels(pdev);
  369. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  370. layers[0].size = IE31200_DIMMS;
  371. layers[0].is_virt_csrow = true;
  372. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  373. layers[1].size = nr_channels;
  374. layers[1].is_virt_csrow = false;
  375. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
  376. sizeof(struct ie31200_priv));
  377. if (!mci)
  378. return -ENOMEM;
  379. window = ie31200_map_mchbar(pdev);
  380. if (!window) {
  381. ret = -ENODEV;
  382. goto fail_free;
  383. }
  384. edac_dbg(3, "MC: init mci\n");
  385. mci->pdev = &pdev->dev;
  386. if (skl)
  387. mci->mtype_cap = MEM_FLAG_DDR4;
  388. else
  389. mci->mtype_cap = MEM_FLAG_DDR3;
  390. mci->edac_ctl_cap = EDAC_FLAG_SECDED;
  391. mci->edac_cap = EDAC_FLAG_SECDED;
  392. mci->mod_name = EDAC_MOD_STR;
  393. mci->ctl_name = ie31200_devs[dev_idx].ctl_name;
  394. mci->dev_name = pci_name(pdev);
  395. mci->edac_check = ie31200_check;
  396. mci->ctl_page_to_phys = NULL;
  397. priv = mci->pvt_info;
  398. priv->window = window;
  399. if (skl) {
  400. priv->c0errlog = window + IE31200_C0ECCERRLOG_SKL;
  401. priv->c1errlog = window + IE31200_C1ECCERRLOG_SKL;
  402. mad_offset = IE31200_MAD_DIMM_0_OFFSET_SKL;
  403. } else {
  404. priv->c0errlog = window + IE31200_C0ECCERRLOG;
  405. priv->c1errlog = window + IE31200_C1ECCERRLOG;
  406. mad_offset = IE31200_MAD_DIMM_0_OFFSET;
  407. }
  408. /* populate DIMM info */
  409. for (i = 0; i < IE31200_CHANNELS; i++) {
  410. addr_decode = readl(window + mad_offset +
  411. (i * 4));
  412. edac_dbg(0, "addr_decode: 0x%x\n", addr_decode);
  413. for (j = 0; j < IE31200_DIMMS_PER_CHANNEL; j++) {
  414. populate_dimm_info(&dimm_info[i][j], addr_decode, j,
  415. skl);
  416. edac_dbg(0, "size: 0x%x, rank: %d, width: %d\n",
  417. dimm_info[i][j].size,
  418. dimm_info[i][j].dual_rank,
  419. dimm_info[i][j].x16_width);
  420. }
  421. }
  422. /*
  423. * The dram rank boundary (DRB) reg values are boundary addresses
  424. * for each DRAM rank with a granularity of 64MB. DRB regs are
  425. * cumulative; the last one will contain the total memory
  426. * contained in all ranks.
  427. */
  428. for (i = 0; i < IE31200_DIMMS_PER_CHANNEL; i++) {
  429. for (j = 0; j < IE31200_CHANNELS; j++) {
  430. struct dimm_info *dimm;
  431. unsigned long nr_pages;
  432. nr_pages = IE31200_PAGES(dimm_info[j][i].size, skl);
  433. if (nr_pages == 0)
  434. continue;
  435. if (dimm_info[j][i].dual_rank) {
  436. nr_pages = nr_pages / 2;
  437. dimm = edac_get_dimm(mci, (i * 2) + 1, j, 0);
  438. dimm->nr_pages = nr_pages;
  439. edac_dbg(0, "set nr pages: 0x%lx\n", nr_pages);
  440. dimm->grain = 8; /* just a guess */
  441. if (skl)
  442. dimm->mtype = MEM_DDR4;
  443. else
  444. dimm->mtype = MEM_DDR3;
  445. dimm->dtype = DEV_UNKNOWN;
  446. dimm->edac_mode = EDAC_UNKNOWN;
  447. }
  448. dimm = edac_get_dimm(mci, i * 2, j, 0);
  449. dimm->nr_pages = nr_pages;
  450. edac_dbg(0, "set nr pages: 0x%lx\n", nr_pages);
  451. dimm->grain = 8; /* same guess */
  452. if (skl)
  453. dimm->mtype = MEM_DDR4;
  454. else
  455. dimm->mtype = MEM_DDR3;
  456. dimm->dtype = DEV_UNKNOWN;
  457. dimm->edac_mode = EDAC_UNKNOWN;
  458. }
  459. }
  460. ie31200_clear_error_info(mci);
  461. if (edac_mc_add_mc(mci)) {
  462. edac_dbg(3, "MC: failed edac_mc_add_mc()\n");
  463. ret = -ENODEV;
  464. goto fail_unmap;
  465. }
  466. /* get this far and it's successful */
  467. edac_dbg(3, "MC: success\n");
  468. return 0;
  469. fail_unmap:
  470. iounmap(window);
  471. fail_free:
  472. edac_mc_free(mci);
  473. return ret;
  474. }
  475. static int ie31200_init_one(struct pci_dev *pdev,
  476. const struct pci_device_id *ent)
  477. {
  478. int rc;
  479. edac_dbg(0, "MC:\n");
  480. if (pci_enable_device(pdev) < 0)
  481. return -EIO;
  482. rc = ie31200_probe1(pdev, ent->driver_data);
  483. if (rc == 0 && !mci_pdev)
  484. mci_pdev = pci_dev_get(pdev);
  485. return rc;
  486. }
  487. static void ie31200_remove_one(struct pci_dev *pdev)
  488. {
  489. struct mem_ctl_info *mci;
  490. struct ie31200_priv *priv;
  491. edac_dbg(0, "\n");
  492. pci_dev_put(mci_pdev);
  493. mci_pdev = NULL;
  494. mci = edac_mc_del_mc(&pdev->dev);
  495. if (!mci)
  496. return;
  497. priv = mci->pvt_info;
  498. iounmap(priv->window);
  499. edac_mc_free(mci);
  500. }
  501. static const struct pci_device_id ie31200_pci_tbl[] = {
  502. { PCI_VEND_DEV(INTEL, IE31200_HB_1), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  503. { PCI_VEND_DEV(INTEL, IE31200_HB_2), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  504. { PCI_VEND_DEV(INTEL, IE31200_HB_3), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  505. { PCI_VEND_DEV(INTEL, IE31200_HB_4), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  506. { PCI_VEND_DEV(INTEL, IE31200_HB_5), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  507. { PCI_VEND_DEV(INTEL, IE31200_HB_6), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  508. { PCI_VEND_DEV(INTEL, IE31200_HB_7), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  509. { PCI_VEND_DEV(INTEL, IE31200_HB_8), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  510. { PCI_VEND_DEV(INTEL, IE31200_HB_9), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  511. { PCI_VEND_DEV(INTEL, IE31200_HB_10), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  512. { PCI_VEND_DEV(INTEL, IE31200_HB_11), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  513. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_1), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  514. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_2), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  515. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_3), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  516. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_4), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  517. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_5), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  518. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_6), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  519. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_7), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  520. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_8), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  521. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_9), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  522. { PCI_VEND_DEV(INTEL, IE31200_HB_CFL_10), PCI_ANY_ID, PCI_ANY_ID, 0, 0, IE31200 },
  523. { 0, } /* 0 terminated list. */
  524. };
  525. MODULE_DEVICE_TABLE(pci, ie31200_pci_tbl);
  526. static struct pci_driver ie31200_driver = {
  527. .name = EDAC_MOD_STR,
  528. .probe = ie31200_init_one,
  529. .remove = ie31200_remove_one,
  530. .id_table = ie31200_pci_tbl,
  531. };
  532. static int __init ie31200_init(void)
  533. {
  534. int pci_rc, i;
  535. edac_dbg(3, "MC:\n");
  536. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  537. opstate_init();
  538. pci_rc = pci_register_driver(&ie31200_driver);
  539. if (pci_rc < 0)
  540. goto fail0;
  541. if (!mci_pdev) {
  542. ie31200_registered = 0;
  543. for (i = 0; ie31200_pci_tbl[i].vendor != 0; i++) {
  544. mci_pdev = pci_get_device(ie31200_pci_tbl[i].vendor,
  545. ie31200_pci_tbl[i].device,
  546. NULL);
  547. if (mci_pdev)
  548. break;
  549. }
  550. if (!mci_pdev) {
  551. edac_dbg(0, "ie31200 pci_get_device fail\n");
  552. pci_rc = -ENODEV;
  553. goto fail1;
  554. }
  555. pci_rc = ie31200_init_one(mci_pdev, &ie31200_pci_tbl[i]);
  556. if (pci_rc < 0) {
  557. edac_dbg(0, "ie31200 init fail\n");
  558. pci_rc = -ENODEV;
  559. goto fail1;
  560. }
  561. }
  562. return 0;
  563. fail1:
  564. pci_unregister_driver(&ie31200_driver);
  565. fail0:
  566. pci_dev_put(mci_pdev);
  567. return pci_rc;
  568. }
  569. static void __exit ie31200_exit(void)
  570. {
  571. edac_dbg(3, "MC:\n");
  572. pci_unregister_driver(&ie31200_driver);
  573. if (!ie31200_registered)
  574. ie31200_remove_one(mci_pdev);
  575. }
  576. module_init(ie31200_init);
  577. module_exit(ie31200_exit);
  578. MODULE_LICENSE("GPL");
  579. MODULE_AUTHOR("Jason Baron <[email protected]>");
  580. MODULE_DESCRIPTION("MC support for Intel Processor E31200 memory hub controllers");