r82600_edac.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*
  2. * Radisys 82600 Embedded chipset Memory Controller kernel module
  3. * (C) 2005 EADS Astrium
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Tim Small <tim@buttersideup.com>, based on work by Thayne
  8. * Harbaugh, Dan Hollis <goemon at anime dot net> and others.
  9. *
  10. * $Id: edac_r82600.c,v 1.1.2.6 2005/10/05 00:43:44 dsp_llnl Exp $
  11. *
  12. * Written with reference to 82600 High Integration Dual PCI System
  13. * Controller Data Book:
  14. * www.radisys.com/files/support_downloads/007-01277-0002.82600DataBook.pdf
  15. * references to this document given in []
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/pci.h>
  20. #include <linux/pci_ids.h>
  21. #include <linux/edac.h>
  22. #include "edac_core.h"
  23. #define R82600_REVISION " Ver: 2.0.2"
  24. #define EDAC_MOD_STR "r82600_edac"
  25. #define r82600_printk(level, fmt, arg...) \
  26. edac_printk(level, "r82600", fmt, ##arg)
  27. #define r82600_mc_printk(mci, level, fmt, arg...) \
  28. edac_mc_chipset_printk(mci, level, "r82600", fmt, ##arg)
  29. /* Radisys say "The 82600 integrates a main memory SDRAM controller that
  30. * supports up to four banks of memory. The four banks can support a mix of
  31. * sizes of 64 bit wide (72 bits with ECC) Synchronous DRAM (SDRAM) DIMMs,
  32. * each of which can be any size from 16MB to 512MB. Both registered (control
  33. * signals buffered) and unbuffered DIMM types are supported. Mixing of
  34. * registered and unbuffered DIMMs as well as mixing of ECC and non-ECC DIMMs
  35. * is not allowed. The 82600 SDRAM interface operates at the same frequency as
  36. * the CPU bus, 66MHz, 100MHz or 133MHz."
  37. */
  38. #define R82600_NR_CSROWS 4
  39. #define R82600_NR_CHANS 1
  40. #define R82600_NR_DIMMS 4
  41. #define R82600_BRIDGE_ID 0x8200
  42. /* Radisys 82600 register addresses - device 0 function 0 - PCI bridge */
  43. #define R82600_DRAMC 0x57 /* Various SDRAM related control bits
  44. * all bits are R/W
  45. *
  46. * 7 SDRAM ISA Hole Enable
  47. * 6 Flash Page Mode Enable
  48. * 5 ECC Enable: 1=ECC 0=noECC
  49. * 4 DRAM DIMM Type: 1=
  50. * 3 BIOS Alias Disable
  51. * 2 SDRAM BIOS Flash Write Enable
  52. * 1:0 SDRAM Refresh Rate: 00=Disabled
  53. * 01=7.8usec (256Mbit SDRAMs)
  54. * 10=15.6us 11=125usec
  55. */
  56. #define R82600_SDRAMC 0x76 /* "SDRAM Control Register"
  57. * More SDRAM related control bits
  58. * all bits are R/W
  59. *
  60. * 15:8 Reserved.
  61. *
  62. * 7:5 Special SDRAM Mode Select
  63. *
  64. * 4 Force ECC
  65. *
  66. * 1=Drive ECC bits to 0 during
  67. * write cycles (i.e. ECC test mode)
  68. *
  69. * 0=Normal ECC functioning
  70. *
  71. * 3 Enhanced Paging Enable
  72. *
  73. * 2 CAS# Latency 0=3clks 1=2clks
  74. *
  75. * 1 RAS# to CAS# Delay 0=3 1=2
  76. *
  77. * 0 RAS# Precharge 0=3 1=2
  78. */
  79. #define R82600_EAP 0x80 /* ECC Error Address Pointer Register
  80. *
  81. * 31 Disable Hardware Scrubbing (RW)
  82. * 0=Scrub on corrected read
  83. * 1=Don't scrub on corrected read
  84. *
  85. * 30:12 Error Address Pointer (RO)
  86. * Upper 19 bits of error address
  87. *
  88. * 11:4 Syndrome Bits (RO)
  89. *
  90. * 3 BSERR# on multibit error (RW)
  91. * 1=enable 0=disable
  92. *
  93. * 2 NMI on Single Bit Eror (RW)
  94. * 1=NMI triggered by SBE n.b. other
  95. * prerequeists
  96. * 0=NMI not triggered
  97. *
  98. * 1 MBE (R/WC)
  99. * read 1=MBE at EAP (see above)
  100. * read 0=no MBE, or SBE occurred first
  101. * write 1=Clear MBE status (must also
  102. * clear SBE)
  103. * write 0=NOP
  104. *
  105. * 1 SBE (R/WC)
  106. * read 1=SBE at EAP (see above)
  107. * read 0=no SBE, or MBE occurred first
  108. * write 1=Clear SBE status (must also
  109. * clear MBE)
  110. * write 0=NOP
  111. */
  112. #define R82600_DRBA 0x60 /* + 0x60..0x63 SDRAM Row Boundary Address
  113. * Registers
  114. *
  115. * 7:0 Address lines 30:24 - upper limit of
  116. * each row [p57]
  117. */
  118. struct r82600_error_info {
  119. u32 eapr;
  120. };
  121. static bool disable_hardware_scrub;
  122. static struct edac_pci_ctl_info *r82600_pci;
  123. static void r82600_get_error_info(struct mem_ctl_info *mci,
  124. struct r82600_error_info *info)
  125. {
  126. struct pci_dev *pdev;
  127. pdev = to_pci_dev(mci->pdev);
  128. pci_read_config_dword(pdev, R82600_EAP, &info->eapr);
  129. if (info->eapr & BIT(0))
  130. /* Clear error to allow next error to be reported [p.62] */
  131. pci_write_bits32(pdev, R82600_EAP,
  132. ((u32) BIT(0) & (u32) BIT(1)),
  133. ((u32) BIT(0) & (u32) BIT(1)));
  134. if (info->eapr & BIT(1))
  135. /* Clear error to allow next error to be reported [p.62] */
  136. pci_write_bits32(pdev, R82600_EAP,
  137. ((u32) BIT(0) & (u32) BIT(1)),
  138. ((u32) BIT(0) & (u32) BIT(1)));
  139. }
  140. static int r82600_process_error_info(struct mem_ctl_info *mci,
  141. struct r82600_error_info *info,
  142. int handle_errors)
  143. {
  144. int error_found;
  145. u32 eapaddr, page;
  146. u32 syndrome;
  147. error_found = 0;
  148. /* bits 30:12 store the upper 19 bits of the 32 bit error address */
  149. eapaddr = ((info->eapr >> 12) & 0x7FFF) << 13;
  150. /* Syndrome in bits 11:4 [p.62] */
  151. syndrome = (info->eapr >> 4) & 0xFF;
  152. /* the R82600 reports at less than page *
  153. * granularity (upper 19 bits only) */
  154. page = eapaddr >> PAGE_SHIFT;
  155. if (info->eapr & BIT(0)) { /* CE? */
  156. error_found = 1;
  157. if (handle_errors)
  158. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  159. page, 0, syndrome,
  160. edac_mc_find_csrow_by_page(mci, page),
  161. 0, -1,
  162. mci->ctl_name, "");
  163. }
  164. if (info->eapr & BIT(1)) { /* UE? */
  165. error_found = 1;
  166. if (handle_errors)
  167. /* 82600 doesn't give enough info */
  168. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  169. page, 0, 0,
  170. edac_mc_find_csrow_by_page(mci, page),
  171. 0, -1,
  172. mci->ctl_name, "");
  173. }
  174. return error_found;
  175. }
  176. static void r82600_check(struct mem_ctl_info *mci)
  177. {
  178. struct r82600_error_info info;
  179. edac_dbg(1, "MC%d\n", mci->mc_idx);
  180. r82600_get_error_info(mci, &info);
  181. r82600_process_error_info(mci, &info, 1);
  182. }
  183. static inline int ecc_enabled(u8 dramcr)
  184. {
  185. return dramcr & BIT(5);
  186. }
  187. static void r82600_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
  188. u8 dramcr)
  189. {
  190. struct csrow_info *csrow;
  191. struct dimm_info *dimm;
  192. int index;
  193. u8 drbar; /* SDRAM Row Boundary Address Register */
  194. u32 row_high_limit, row_high_limit_last;
  195. u32 reg_sdram, ecc_on, row_base;
  196. ecc_on = ecc_enabled(dramcr);
  197. reg_sdram = dramcr & BIT(4);
  198. row_high_limit_last = 0;
  199. for (index = 0; index < mci->nr_csrows; index++) {
  200. csrow = mci->csrows[index];
  201. dimm = csrow->channels[0]->dimm;
  202. /* find the DRAM Chip Select Base address and mask */
  203. pci_read_config_byte(pdev, R82600_DRBA + index, &drbar);
  204. edac_dbg(1, "Row=%d DRBA = %#0x\n", index, drbar);
  205. row_high_limit = ((u32) drbar << 24);
  206. /* row_high_limit = ((u32)drbar << 24) | 0xffffffUL; */
  207. edac_dbg(1, "Row=%d, Boundary Address=%#0x, Last = %#0x\n",
  208. index, row_high_limit, row_high_limit_last);
  209. /* Empty row [p.57] */
  210. if (row_high_limit == row_high_limit_last)
  211. continue;
  212. row_base = row_high_limit_last;
  213. csrow->first_page = row_base >> PAGE_SHIFT;
  214. csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1;
  215. dimm->nr_pages = csrow->last_page - csrow->first_page + 1;
  216. /* Error address is top 19 bits - so granularity is *
  217. * 14 bits */
  218. dimm->grain = 1 << 14;
  219. dimm->mtype = reg_sdram ? MEM_RDDR : MEM_DDR;
  220. /* FIXME - check that this is unknowable with this chipset */
  221. dimm->dtype = DEV_UNKNOWN;
  222. /* Mode is global on 82600 */
  223. dimm->edac_mode = ecc_on ? EDAC_SECDED : EDAC_NONE;
  224. row_high_limit_last = row_high_limit;
  225. }
  226. }
  227. static int r82600_probe1(struct pci_dev *pdev, int dev_idx)
  228. {
  229. struct mem_ctl_info *mci;
  230. struct edac_mc_layer layers[2];
  231. u8 dramcr;
  232. u32 eapr;
  233. u32 scrub_disabled;
  234. u32 sdram_refresh_rate;
  235. struct r82600_error_info discard;
  236. edac_dbg(0, "\n");
  237. pci_read_config_byte(pdev, R82600_DRAMC, &dramcr);
  238. pci_read_config_dword(pdev, R82600_EAP, &eapr);
  239. scrub_disabled = eapr & BIT(31);
  240. sdram_refresh_rate = dramcr & (BIT(0) | BIT(1));
  241. edac_dbg(2, "sdram refresh rate = %#0x\n", sdram_refresh_rate);
  242. edac_dbg(2, "DRAMC register = %#0x\n", dramcr);
  243. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  244. layers[0].size = R82600_NR_CSROWS;
  245. layers[0].is_virt_csrow = true;
  246. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  247. layers[1].size = R82600_NR_CHANS;
  248. layers[1].is_virt_csrow = false;
  249. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
  250. if (mci == NULL)
  251. return -ENOMEM;
  252. edac_dbg(0, "mci = %p\n", mci);
  253. mci->pdev = &pdev->dev;
  254. mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR;
  255. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  256. /* FIXME try to work out if the chip leads have been used for COM2
  257. * instead on this board? [MA6?] MAYBE:
  258. */
  259. /* On the R82600, the pins for memory bits 72:65 - i.e. the *
  260. * EC bits are shared with the pins for COM2 (!), so if COM2 *
  261. * is enabled, we assume COM2 is wired up, and thus no EDAC *
  262. * is possible. */
  263. mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  264. if (ecc_enabled(dramcr)) {
  265. if (scrub_disabled)
  266. edac_dbg(3, "mci = %p - Scrubbing disabled! EAP: %#0x\n",
  267. mci, eapr);
  268. } else
  269. mci->edac_cap = EDAC_FLAG_NONE;
  270. mci->mod_name = EDAC_MOD_STR;
  271. mci->mod_ver = R82600_REVISION;
  272. mci->ctl_name = "R82600";
  273. mci->dev_name = pci_name(pdev);
  274. mci->edac_check = r82600_check;
  275. mci->ctl_page_to_phys = NULL;
  276. r82600_init_csrows(mci, pdev, dramcr);
  277. r82600_get_error_info(mci, &discard); /* clear counters */
  278. /* Here we assume that we will never see multiple instances of this
  279. * type of memory controller. The ID is therefore hardcoded to 0.
  280. */
  281. if (edac_mc_add_mc(mci)) {
  282. edac_dbg(3, "failed edac_mc_add_mc()\n");
  283. goto fail;
  284. }
  285. /* get this far and it's successful */
  286. if (disable_hardware_scrub) {
  287. edac_dbg(3, "Disabling Hardware Scrub (scrub on error)\n");
  288. pci_write_bits32(pdev, R82600_EAP, BIT(31), BIT(31));
  289. }
  290. /* allocating generic PCI control info */
  291. r82600_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  292. if (!r82600_pci) {
  293. printk(KERN_WARNING
  294. "%s(): Unable to create PCI control\n",
  295. __func__);
  296. printk(KERN_WARNING
  297. "%s(): PCI error report via EDAC not setup\n",
  298. __func__);
  299. }
  300. edac_dbg(3, "success\n");
  301. return 0;
  302. fail:
  303. edac_mc_free(mci);
  304. return -ENODEV;
  305. }
  306. /* returns count (>= 0), or negative on error */
  307. static int r82600_init_one(struct pci_dev *pdev,
  308. const struct pci_device_id *ent)
  309. {
  310. edac_dbg(0, "\n");
  311. /* don't need to call pci_enable_device() */
  312. return r82600_probe1(pdev, ent->driver_data);
  313. }
  314. static void r82600_remove_one(struct pci_dev *pdev)
  315. {
  316. struct mem_ctl_info *mci;
  317. edac_dbg(0, "\n");
  318. if (r82600_pci)
  319. edac_pci_release_generic_ctl(r82600_pci);
  320. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  321. return;
  322. edac_mc_free(mci);
  323. }
  324. static const struct pci_device_id r82600_pci_tbl[] = {
  325. {
  326. PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
  327. },
  328. {
  329. 0,
  330. } /* 0 terminated list. */
  331. };
  332. MODULE_DEVICE_TABLE(pci, r82600_pci_tbl);
  333. static struct pci_driver r82600_driver = {
  334. .name = EDAC_MOD_STR,
  335. .probe = r82600_init_one,
  336. .remove = r82600_remove_one,
  337. .id_table = r82600_pci_tbl,
  338. };
  339. static int __init r82600_init(void)
  340. {
  341. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  342. opstate_init();
  343. return pci_register_driver(&r82600_driver);
  344. }
  345. static void __exit r82600_exit(void)
  346. {
  347. pci_unregister_driver(&r82600_driver);
  348. }
  349. module_init(r82600_init);
  350. module_exit(r82600_exit);
  351. MODULE_LICENSE("GPL");
  352. MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD Ltd. "
  353. "on behalf of EADS Astrium");
  354. MODULE_DESCRIPTION("MC support for Radisys 82600 memory controllers");
  355. module_param(disable_hardware_scrub, bool, 0644);
  356. MODULE_PARM_DESC(disable_hardware_scrub,
  357. "If set, disable the chipset's automatic scrub for CEs");
  358. module_param(edac_op_state, int, 0444);
  359. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");