r82600_edac.c 11 KB

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