i3000_edac.c 14 KB

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