i3000_edac.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*
  2. * Intel 3000/3010 Memory Controller kernel module
  3. * Copyright (C) 2007 Akamai Technologies, Inc.
  4. * Shamelessly copied from:
  5. * Intel D82875P Memory Controller kernel module
  6. * (C) 2003 Linux Networx (http://lnxi.com)
  7. *
  8. * This file may be distributed under the terms of the
  9. * GNU General Public License.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/pci.h>
  14. #include <linux/pci_ids.h>
  15. #include <linux/edac.h>
  16. #include "edac_core.h"
  17. #define I3000_REVISION "1.1"
  18. #define EDAC_MOD_STR "i3000_edac"
  19. #define I3000_RANKS 8
  20. #define I3000_RANKS_PER_CHANNEL 4
  21. #define I3000_CHANNELS 2
  22. /* Intel 3000 register addresses - device 0 function 0 - DRAM Controller */
  23. #define I3000_MCHBAR 0x44 /* MCH Memory Mapped Register BAR */
  24. #define I3000_MCHBAR_MASK 0xffffc000
  25. #define I3000_MMR_WINDOW_SIZE 16384
  26. #define I3000_EDEAP 0x70 /* Extended DRAM Error Address Pointer (8b)
  27. *
  28. * 7:1 reserved
  29. * 0 bit 32 of address
  30. */
  31. #define I3000_DEAP 0x58 /* DRAM Error Address Pointer (32b)
  32. *
  33. * 31:7 address
  34. * 6:1 reserved
  35. * 0 Error channel 0/1
  36. */
  37. #define I3000_DEAP_GRAIN (1 << 7)
  38. /*
  39. * Helper functions to decode the DEAP/EDEAP hardware registers.
  40. *
  41. * The type promotion here is deliberate; we're deriving an
  42. * unsigned long pfn and offset from hardware regs which are u8/u32.
  43. */
  44. static inline unsigned long deap_pfn(u8 edeap, u32 deap)
  45. {
  46. deap >>= PAGE_SHIFT;
  47. deap |= (edeap & 1) << (32 - PAGE_SHIFT);
  48. return deap;
  49. }
  50. static inline unsigned long deap_offset(u32 deap)
  51. {
  52. return deap & ~(I3000_DEAP_GRAIN - 1) & ~PAGE_MASK;
  53. }
  54. static inline int deap_channel(u32 deap)
  55. {
  56. return deap & 1;
  57. }
  58. #define I3000_DERRSYN 0x5c /* DRAM Error Syndrome (8b)
  59. *
  60. * 7:0 DRAM ECC Syndrome
  61. */
  62. #define I3000_ERRSTS 0xc8 /* Error Status Register (16b)
  63. *
  64. * 15:12 reserved
  65. * 11 MCH Thermal Sensor Event
  66. * for SMI/SCI/SERR
  67. * 10 reserved
  68. * 9 LOCK to non-DRAM Memory Flag (LCKF)
  69. * 8 Received Refresh Timeout Flag (RRTOF)
  70. * 7:2 reserved
  71. * 1 Multi-bit DRAM ECC Error Flag (DMERR)
  72. * 0 Single-bit DRAM ECC Error Flag (DSERR)
  73. */
  74. #define I3000_ERRSTS_BITS 0x0b03 /* bits which indicate errors */
  75. #define I3000_ERRSTS_UE 0x0002
  76. #define I3000_ERRSTS_CE 0x0001
  77. #define I3000_ERRCMD 0xca /* Error Command (16b)
  78. *
  79. * 15:12 reserved
  80. * 11 SERR on MCH Thermal Sensor Event
  81. * (TSESERR)
  82. * 10 reserved
  83. * 9 SERR on LOCK to non-DRAM Memory
  84. * (LCKERR)
  85. * 8 SERR on DRAM Refresh Timeout
  86. * (DRTOERR)
  87. * 7:2 reserved
  88. * 1 SERR Multi-Bit DRAM ECC Error
  89. * (DMERR)
  90. * 0 SERR on Single-Bit ECC Error
  91. * (DSERR)
  92. */
  93. /* Intel MMIO register space - device 0 function 0 - MMR space */
  94. #define I3000_DRB_SHIFT 25 /* 32MiB grain */
  95. #define I3000_C0DRB 0x100 /* Channel 0 DRAM Rank Boundary (8b x 4)
  96. *
  97. * 7:0 Channel 0 DRAM Rank Boundary Address
  98. */
  99. #define I3000_C1DRB 0x180 /* Channel 1 DRAM Rank Boundary (8b x 4)
  100. *
  101. * 7:0 Channel 1 DRAM Rank Boundary Address
  102. */
  103. #define I3000_C0DRA 0x108 /* Channel 0 DRAM Rank Attribute (8b x 2)
  104. *
  105. * 7 reserved
  106. * 6:4 DRAM odd Rank Attribute
  107. * 3 reserved
  108. * 2:0 DRAM even Rank Attribute
  109. *
  110. * Each attribute defines the page
  111. * size of the corresponding rank:
  112. * 000: unpopulated
  113. * 001: reserved
  114. * 010: 4 KB
  115. * 011: 8 KB
  116. * 100: 16 KB
  117. * Others: reserved
  118. */
  119. #define I3000_C1DRA 0x188 /* Channel 1 DRAM Rank Attribute (8b x 2) */
  120. static inline unsigned char odd_rank_attrib(unsigned char dra)
  121. {
  122. return (dra & 0x70) >> 4;
  123. }
  124. static inline unsigned char even_rank_attrib(unsigned char dra)
  125. {
  126. return dra & 0x07;
  127. }
  128. #define I3000_C0DRC0 0x120 /* DRAM Controller Mode 0 (32b)
  129. *
  130. * 31:30 reserved
  131. * 29 Initialization Complete (IC)
  132. * 28:11 reserved
  133. * 10:8 Refresh Mode Select (RMS)
  134. * 7 reserved
  135. * 6:4 Mode Select (SMS)
  136. * 3:2 reserved
  137. * 1:0 DRAM Type (DT)
  138. */
  139. #define I3000_C0DRC1 0x124 /* DRAM Controller Mode 1 (32b)
  140. *
  141. * 31 Enhanced Addressing Enable (ENHADE)
  142. * 30:0 reserved
  143. */
  144. enum i3000p_chips {
  145. I3000 = 0,
  146. };
  147. struct i3000_dev_info {
  148. const char *ctl_name;
  149. };
  150. struct i3000_error_info {
  151. u16 errsts;
  152. u8 derrsyn;
  153. u8 edeap;
  154. u32 deap;
  155. u16 errsts2;
  156. };
  157. static const struct i3000_dev_info i3000_devs[] = {
  158. [I3000] = {
  159. .ctl_name = "i3000"},
  160. };
  161. static struct pci_dev *mci_pdev;
  162. static int i3000_registered = 1;
  163. static struct edac_pci_ctl_info *i3000_pci;
  164. static void i3000_get_error_info(struct mem_ctl_info *mci,
  165. struct i3000_error_info *info)
  166. {
  167. struct pci_dev *pdev;
  168. pdev = to_pci_dev(mci->dev);
  169. /*
  170. * This is a mess because there is no atomic way to read all the
  171. * registers at once and the registers can transition from CE being
  172. * overwritten by UE.
  173. */
  174. pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts);
  175. if (!(info->errsts & I3000_ERRSTS_BITS))
  176. return;
  177. pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap);
  178. pci_read_config_dword(pdev, I3000_DEAP, &info->deap);
  179. pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn);
  180. pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts2);
  181. /*
  182. * If the error is the same for both reads then the first set
  183. * of reads is valid. If there is a change then there is a CE
  184. * with no info and the second set of reads is valid and
  185. * should be UE info.
  186. */
  187. if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) {
  188. pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap);
  189. pci_read_config_dword(pdev, I3000_DEAP, &info->deap);
  190. pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn);
  191. }
  192. /*
  193. * Clear any error bits.
  194. * (Yes, we really clear bits by writing 1 to them.)
  195. */
  196. pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS,
  197. I3000_ERRSTS_BITS);
  198. }
  199. static int i3000_process_error_info(struct mem_ctl_info *mci,
  200. struct i3000_error_info *info,
  201. int handle_errors)
  202. {
  203. int row, multi_chan, channel;
  204. unsigned long pfn, offset;
  205. multi_chan = mci->csrows[0].nr_channels - 1;
  206. if (!(info->errsts & I3000_ERRSTS_BITS))
  207. return 0;
  208. if (!handle_errors)
  209. return 1;
  210. if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) {
  211. edac_mc_handle_ce_no_info(mci, "UE overwrote CE");
  212. info->errsts = info->errsts2;
  213. }
  214. pfn = deap_pfn(info->edeap, info->deap);
  215. offset = deap_offset(info->deap);
  216. channel = deap_channel(info->deap);
  217. row = edac_mc_find_csrow_by_page(mci, pfn);
  218. if (info->errsts & I3000_ERRSTS_UE)
  219. edac_mc_handle_ue(mci, pfn, offset, row, "i3000 UE");
  220. else
  221. edac_mc_handle_ce(mci, pfn, offset, info->derrsyn, row,
  222. multi_chan ? channel : 0, "i3000 CE");
  223. return 1;
  224. }
  225. static void i3000_check(struct mem_ctl_info *mci)
  226. {
  227. struct i3000_error_info info;
  228. debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
  229. i3000_get_error_info(mci, &info);
  230. i3000_process_error_info(mci, &info, 1);
  231. }
  232. static int i3000_is_interleaved(const unsigned char *c0dra,
  233. const unsigned char *c1dra,
  234. const unsigned char *c0drb,
  235. const unsigned char *c1drb)
  236. {
  237. int i;
  238. /*
  239. * If the channels aren't populated identically then
  240. * we're not interleaved.
  241. */
  242. for (i = 0; i < I3000_RANKS_PER_CHANNEL / 2; i++)
  243. if (odd_rank_attrib(c0dra[i]) != odd_rank_attrib(c1dra[i]) ||
  244. even_rank_attrib(c0dra[i]) !=
  245. even_rank_attrib(c1dra[i]))
  246. return 0;
  247. /*
  248. * If the rank boundaries for the two channels are different
  249. * then we're not interleaved.
  250. */
  251. for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++)
  252. if (c0drb[i] != c1drb[i])
  253. return 0;
  254. return 1;
  255. }
  256. static int i3000_probe1(struct pci_dev *pdev, int dev_idx)
  257. {
  258. int rc;
  259. int i;
  260. struct mem_ctl_info *mci = NULL;
  261. unsigned long last_cumul_size;
  262. int interleaved, nr_channels;
  263. unsigned char dra[I3000_RANKS / 2], drb[I3000_RANKS];
  264. unsigned char *c0dra = dra, *c1dra = &dra[I3000_RANKS_PER_CHANNEL / 2];
  265. unsigned char *c0drb = drb, *c1drb = &drb[I3000_RANKS_PER_CHANNEL];
  266. unsigned long mchbar;
  267. void __iomem *window;
  268. debugf0("MC: %s()\n", __func__);
  269. pci_read_config_dword(pdev, I3000_MCHBAR, (u32 *) & mchbar);
  270. mchbar &= I3000_MCHBAR_MASK;
  271. window = ioremap_nocache(mchbar, I3000_MMR_WINDOW_SIZE);
  272. if (!window) {
  273. printk(KERN_ERR "i3000: cannot map mmio space at 0x%lx\n",
  274. mchbar);
  275. return -ENODEV;
  276. }
  277. c0dra[0] = readb(window + I3000_C0DRA + 0); /* ranks 0,1 */
  278. c0dra[1] = readb(window + I3000_C0DRA + 1); /* ranks 2,3 */
  279. c1dra[0] = readb(window + I3000_C1DRA + 0); /* ranks 0,1 */
  280. c1dra[1] = readb(window + I3000_C1DRA + 1); /* ranks 2,3 */
  281. for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++) {
  282. c0drb[i] = readb(window + I3000_C0DRB + i);
  283. c1drb[i] = readb(window + I3000_C1DRB + i);
  284. }
  285. iounmap(window);
  286. /*
  287. * Figure out how many channels we have.
  288. *
  289. * If we have what the datasheet calls "asymmetric channels"
  290. * (essentially the same as what was called "virtual single
  291. * channel mode" in the i82875) then it's a single channel as
  292. * far as EDAC is concerned.
  293. */
  294. interleaved = i3000_is_interleaved(c0dra, c1dra, c0drb, c1drb);
  295. nr_channels = interleaved ? 2 : 1;
  296. mci = edac_mc_alloc(0, I3000_RANKS / nr_channels, nr_channels, 0);
  297. if (!mci)
  298. return -ENOMEM;
  299. debugf3("MC: %s(): init mci\n", __func__);
  300. mci->dev = &pdev->dev;
  301. mci->mtype_cap = MEM_FLAG_DDR2;
  302. mci->edac_ctl_cap = EDAC_FLAG_SECDED;
  303. mci->edac_cap = EDAC_FLAG_SECDED;
  304. mci->mod_name = EDAC_MOD_STR;
  305. mci->mod_ver = I3000_REVISION;
  306. mci->ctl_name = i3000_devs[dev_idx].ctl_name;
  307. mci->dev_name = pci_name(pdev);
  308. mci->edac_check = i3000_check;
  309. mci->ctl_page_to_phys = NULL;
  310. /*
  311. * The dram rank boundary (DRB) reg values are boundary addresses
  312. * for each DRAM rank with a granularity of 32MB. DRB regs are
  313. * cumulative; the last one will contain the total memory
  314. * contained in all ranks.
  315. *
  316. * If we're in interleaved mode then we're only walking through
  317. * the ranks of controller 0, so we double all the values we see.
  318. */
  319. for (last_cumul_size = i = 0; i < mci->nr_csrows; i++) {
  320. u8 value;
  321. u32 cumul_size;
  322. struct csrow_info *csrow = &mci->csrows[i];
  323. value = drb[i];
  324. cumul_size = value << (I3000_DRB_SHIFT - PAGE_SHIFT);
  325. if (interleaved)
  326. cumul_size <<= 1;
  327. debugf3("MC: %s(): (%d) cumul_size 0x%x\n",
  328. __func__, i, cumul_size);
  329. if (cumul_size == last_cumul_size) {
  330. csrow->mtype = MEM_EMPTY;
  331. continue;
  332. }
  333. csrow->first_page = last_cumul_size;
  334. csrow->last_page = cumul_size - 1;
  335. csrow->nr_pages = cumul_size - last_cumul_size;
  336. last_cumul_size = cumul_size;
  337. csrow->grain = I3000_DEAP_GRAIN;
  338. csrow->mtype = MEM_DDR2;
  339. csrow->dtype = DEV_UNKNOWN;
  340. csrow->edac_mode = EDAC_UNKNOWN;
  341. }
  342. /*
  343. * Clear any error bits.
  344. * (Yes, we really clear bits by writing 1 to them.)
  345. */
  346. pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS,
  347. I3000_ERRSTS_BITS);
  348. rc = -ENODEV;
  349. if (edac_mc_add_mc(mci)) {
  350. debugf3("MC: %s(): failed edac_mc_add_mc()\n", __func__);
  351. goto fail;
  352. }
  353. /* allocating generic PCI control info */
  354. i3000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  355. if (!i3000_pci) {
  356. printk(KERN_WARNING
  357. "%s(): Unable to create PCI control\n",
  358. __func__);
  359. printk(KERN_WARNING
  360. "%s(): PCI error report via EDAC not setup\n",
  361. __func__);
  362. }
  363. /* get this far and it's successful */
  364. debugf3("MC: %s(): success\n", __func__);
  365. return 0;
  366. fail:
  367. if (mci)
  368. edac_mc_free(mci);
  369. return rc;
  370. }
  371. /* returns count (>= 0), or negative on error */
  372. static int __devinit i3000_init_one(struct pci_dev *pdev,
  373. const struct pci_device_id *ent)
  374. {
  375. int rc;
  376. debugf0("MC: %s()\n", __func__);
  377. if (pci_enable_device(pdev) < 0)
  378. return -EIO;
  379. rc = i3000_probe1(pdev, ent->driver_data);
  380. if (!mci_pdev)
  381. mci_pdev = pci_dev_get(pdev);
  382. return rc;
  383. }
  384. static void __devexit i3000_remove_one(struct pci_dev *pdev)
  385. {
  386. struct mem_ctl_info *mci;
  387. debugf0("%s()\n", __func__);
  388. if (i3000_pci)
  389. edac_pci_release_generic_ctl(i3000_pci);
  390. mci = edac_mc_del_mc(&pdev->dev);
  391. if (!mci)
  392. return;
  393. edac_mc_free(mci);
  394. }
  395. static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
  396. {
  397. PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  398. I3000},
  399. {
  400. 0,
  401. } /* 0 terminated list. */
  402. };
  403. MODULE_DEVICE_TABLE(pci, i3000_pci_tbl);
  404. static struct pci_driver i3000_driver = {
  405. .name = EDAC_MOD_STR,
  406. .probe = i3000_init_one,
  407. .remove = __devexit_p(i3000_remove_one),
  408. .id_table = i3000_pci_tbl,
  409. };
  410. static int __init i3000_init(void)
  411. {
  412. int pci_rc;
  413. debugf3("MC: %s()\n", __func__);
  414. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  415. opstate_init();
  416. pci_rc = pci_register_driver(&i3000_driver);
  417. if (pci_rc < 0)
  418. goto fail0;
  419. if (!mci_pdev) {
  420. i3000_registered = 0;
  421. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  422. PCI_DEVICE_ID_INTEL_3000_HB, NULL);
  423. if (!mci_pdev) {
  424. debugf0("i3000 pci_get_device fail\n");
  425. pci_rc = -ENODEV;
  426. goto fail1;
  427. }
  428. pci_rc = i3000_init_one(mci_pdev, i3000_pci_tbl);
  429. if (pci_rc < 0) {
  430. debugf0("i3000 init fail\n");
  431. pci_rc = -ENODEV;
  432. goto fail1;
  433. }
  434. }
  435. return 0;
  436. fail1:
  437. pci_unregister_driver(&i3000_driver);
  438. fail0:
  439. if (mci_pdev)
  440. pci_dev_put(mci_pdev);
  441. return pci_rc;
  442. }
  443. static void __exit i3000_exit(void)
  444. {
  445. debugf3("MC: %s()\n", __func__);
  446. pci_unregister_driver(&i3000_driver);
  447. if (!i3000_registered) {
  448. i3000_remove_one(mci_pdev);
  449. pci_dev_put(mci_pdev);
  450. }
  451. }
  452. module_init(i3000_init);
  453. module_exit(i3000_exit);
  454. MODULE_LICENSE("GPL");
  455. MODULE_AUTHOR("Akamai Technologies Arthur Ulfeldt/Jason Uhlenkott");
  456. MODULE_DESCRIPTION("MC support for Intel 3000 memory hub controllers");
  457. module_param(edac_op_state, int, 0444);
  458. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");