ie31200_edac.c 17 KB

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