ie31200_edac.c 20 KB

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