i82860_edac.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * Intel 82860 Memory Controller kernel module
  3. * (C) 2005 Red Hat (http://www.redhat.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Ben Woodard <woodard@redhat.com>
  8. * shamelessly copied from and based upon the edac_i82875 driver
  9. * by Thayne Harbaugh of Linux Networx. (http://lnxi.com)
  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 I82860_REVISION " Ver: 2.0.2"
  18. #define EDAC_MOD_STR "i82860_edac"
  19. #define i82860_printk(level, fmt, arg...) \
  20. edac_printk(level, "i82860", fmt, ##arg)
  21. #define i82860_mc_printk(mci, level, fmt, arg...) \
  22. edac_mc_chipset_printk(mci, level, "i82860", fmt, ##arg)
  23. #ifndef PCI_DEVICE_ID_INTEL_82860_0
  24. #define PCI_DEVICE_ID_INTEL_82860_0 0x2531
  25. #endif /* PCI_DEVICE_ID_INTEL_82860_0 */
  26. #define I82860_MCHCFG 0x50
  27. #define I82860_GBA 0x60
  28. #define I82860_GBA_MASK 0x7FF
  29. #define I82860_GBA_SHIFT 24
  30. #define I82860_ERRSTS 0xC8
  31. #define I82860_EAP 0xE4
  32. #define I82860_DERRCTL_STS 0xE2
  33. enum i82860_chips {
  34. I82860 = 0,
  35. };
  36. struct i82860_dev_info {
  37. const char *ctl_name;
  38. };
  39. struct i82860_error_info {
  40. u16 errsts;
  41. u32 eap;
  42. u16 derrsyn;
  43. u16 errsts2;
  44. };
  45. static const struct i82860_dev_info i82860_devs[] = {
  46. [I82860] = {
  47. .ctl_name = "i82860"},
  48. };
  49. static struct pci_dev *mci_pdev; /* init dev: in case that AGP code
  50. * has already registered driver
  51. */
  52. static struct edac_pci_ctl_info *i82860_pci;
  53. static void i82860_get_error_info(struct mem_ctl_info *mci,
  54. struct i82860_error_info *info)
  55. {
  56. struct pci_dev *pdev;
  57. pdev = to_pci_dev(mci->dev);
  58. /*
  59. * This is a mess because there is no atomic way to read all the
  60. * registers at once and the registers can transition from CE being
  61. * overwritten by UE.
  62. */
  63. pci_read_config_word(pdev, I82860_ERRSTS, &info->errsts);
  64. pci_read_config_dword(pdev, I82860_EAP, &info->eap);
  65. pci_read_config_word(pdev, I82860_DERRCTL_STS, &info->derrsyn);
  66. pci_read_config_word(pdev, I82860_ERRSTS, &info->errsts2);
  67. pci_write_bits16(pdev, I82860_ERRSTS, 0x0003, 0x0003);
  68. /*
  69. * If the error is the same for both reads then the first set of reads
  70. * is valid. If there is a change then there is a CE no info and the
  71. * second set of reads is valid and should be UE info.
  72. */
  73. if (!(info->errsts2 & 0x0003))
  74. return;
  75. if ((info->errsts ^ info->errsts2) & 0x0003) {
  76. pci_read_config_dword(pdev, I82860_EAP, &info->eap);
  77. pci_read_config_word(pdev, I82860_DERRCTL_STS, &info->derrsyn);
  78. }
  79. }
  80. static int i82860_process_error_info(struct mem_ctl_info *mci,
  81. struct i82860_error_info *info,
  82. int handle_errors)
  83. {
  84. struct dimm_info *dimm;
  85. int row;
  86. if (!(info->errsts2 & 0x0003))
  87. return 0;
  88. if (!handle_errors)
  89. return 1;
  90. if ((info->errsts ^ info->errsts2) & 0x0003) {
  91. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 0, 0, 0,
  92. -1, -1, -1, "UE overwrote CE", "", NULL);
  93. info->errsts = info->errsts2;
  94. }
  95. info->eap >>= PAGE_SHIFT;
  96. row = edac_mc_find_csrow_by_page(mci, info->eap);
  97. dimm = mci->csrows[row].channels[0].dimm;
  98. if (info->errsts & 0x0002)
  99. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci,
  100. info->eap, 0, 0,
  101. dimm->location[0], dimm->location[1], -1,
  102. "i82860 UE", "", NULL);
  103. else
  104. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci,
  105. info->eap, 0, info->derrsyn,
  106. dimm->location[0], dimm->location[1], -1,
  107. "i82860 CE", "", NULL);
  108. return 1;
  109. }
  110. static void i82860_check(struct mem_ctl_info *mci)
  111. {
  112. struct i82860_error_info info;
  113. debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
  114. i82860_get_error_info(mci, &info);
  115. i82860_process_error_info(mci, &info, 1);
  116. }
  117. static void i82860_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev)
  118. {
  119. unsigned long last_cumul_size;
  120. u16 mchcfg_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
  121. u16 value;
  122. u32 cumul_size;
  123. struct csrow_info *csrow;
  124. struct dimm_info *dimm;
  125. int index;
  126. pci_read_config_word(pdev, I82860_MCHCFG, &mchcfg_ddim);
  127. mchcfg_ddim = mchcfg_ddim & 0x180;
  128. last_cumul_size = 0;
  129. /* The group row boundary (GRA) reg values are boundary address
  130. * for each DRAM row with a granularity of 16MB. GRA regs are
  131. * cumulative; therefore GRA15 will contain the total memory contained
  132. * in all eight rows.
  133. */
  134. for (index = 0; index < mci->nr_csrows; index++) {
  135. csrow = &mci->csrows[index];
  136. dimm = csrow->channels[0].dimm;
  137. pci_read_config_word(pdev, I82860_GBA + index * 2, &value);
  138. cumul_size = (value & I82860_GBA_MASK) <<
  139. (I82860_GBA_SHIFT - PAGE_SHIFT);
  140. debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
  141. cumul_size);
  142. if (cumul_size == last_cumul_size)
  143. continue; /* not populated */
  144. csrow->first_page = last_cumul_size;
  145. csrow->last_page = cumul_size - 1;
  146. dimm->nr_pages = cumul_size - last_cumul_size;
  147. last_cumul_size = cumul_size;
  148. dimm->grain = 1 << 12; /* I82860_EAP has 4KiB reolution */
  149. dimm->mtype = MEM_RMBS;
  150. dimm->dtype = DEV_UNKNOWN;
  151. dimm->edac_mode = mchcfg_ddim ? EDAC_SECDED : EDAC_NONE;
  152. }
  153. }
  154. static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
  155. {
  156. struct mem_ctl_info *mci;
  157. struct edac_mc_layer layers[2];
  158. struct i82860_error_info discard;
  159. /*
  160. * RDRAM has channels but these don't map onto the csrow abstraction.
  161. * According with the datasheet, there are 2 Rambus channels, supporting
  162. * up to 16 direct RDRAM devices.
  163. * The device groups from the GRA registers seem to map reasonably
  164. * well onto the notion of a chip select row.
  165. * There are 16 GRA registers and since the name is associated with
  166. * the channel and the GRA registers map to physical devices so we are
  167. * going to make 1 channel for group.
  168. */
  169. layers[0].type = EDAC_MC_LAYER_CHANNEL;
  170. layers[0].size = 2;
  171. layers[0].is_virt_csrow = true;
  172. layers[1].type = EDAC_MC_LAYER_SLOT;
  173. layers[1].size = 8;
  174. layers[1].is_virt_csrow = true;
  175. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
  176. if (!mci)
  177. return -ENOMEM;
  178. debugf3("%s(): init mci\n", __func__);
  179. mci->dev = &pdev->dev;
  180. mci->mtype_cap = MEM_FLAG_DDR;
  181. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  182. /* I"m not sure about this but I think that all RDRAM is SECDED */
  183. mci->edac_cap = EDAC_FLAG_SECDED;
  184. mci->mod_name = EDAC_MOD_STR;
  185. mci->mod_ver = I82860_REVISION;
  186. mci->ctl_name = i82860_devs[dev_idx].ctl_name;
  187. mci->dev_name = pci_name(pdev);
  188. mci->edac_check = i82860_check;
  189. mci->ctl_page_to_phys = NULL;
  190. i82860_init_csrows(mci, pdev);
  191. i82860_get_error_info(mci, &discard); /* clear counters */
  192. /* Here we assume that we will never see multiple instances of this
  193. * type of memory controller. The ID is therefore hardcoded to 0.
  194. */
  195. if (edac_mc_add_mc(mci)) {
  196. debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
  197. goto fail;
  198. }
  199. /* allocating generic PCI control info */
  200. i82860_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  201. if (!i82860_pci) {
  202. printk(KERN_WARNING
  203. "%s(): Unable to create PCI control\n",
  204. __func__);
  205. printk(KERN_WARNING
  206. "%s(): PCI error report via EDAC not setup\n",
  207. __func__);
  208. }
  209. /* get this far and it's successful */
  210. debugf3("%s(): success\n", __func__);
  211. return 0;
  212. fail:
  213. edac_mc_free(mci);
  214. return -ENODEV;
  215. }
  216. /* returns count (>= 0), or negative on error */
  217. static int __devinit i82860_init_one(struct pci_dev *pdev,
  218. const struct pci_device_id *ent)
  219. {
  220. int rc;
  221. debugf0("%s()\n", __func__);
  222. i82860_printk(KERN_INFO, "i82860 init one\n");
  223. if (pci_enable_device(pdev) < 0)
  224. return -EIO;
  225. rc = i82860_probe1(pdev, ent->driver_data);
  226. if (rc == 0)
  227. mci_pdev = pci_dev_get(pdev);
  228. return rc;
  229. }
  230. static void __devexit i82860_remove_one(struct pci_dev *pdev)
  231. {
  232. struct mem_ctl_info *mci;
  233. debugf0("%s()\n", __func__);
  234. if (i82860_pci)
  235. edac_pci_release_generic_ctl(i82860_pci);
  236. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  237. return;
  238. edac_mc_free(mci);
  239. }
  240. static DEFINE_PCI_DEVICE_TABLE(i82860_pci_tbl) = {
  241. {
  242. PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  243. I82860},
  244. {
  245. 0,
  246. } /* 0 terminated list. */
  247. };
  248. MODULE_DEVICE_TABLE(pci, i82860_pci_tbl);
  249. static struct pci_driver i82860_driver = {
  250. .name = EDAC_MOD_STR,
  251. .probe = i82860_init_one,
  252. .remove = __devexit_p(i82860_remove_one),
  253. .id_table = i82860_pci_tbl,
  254. };
  255. static int __init i82860_init(void)
  256. {
  257. int pci_rc;
  258. debugf3("%s()\n", __func__);
  259. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  260. opstate_init();
  261. if ((pci_rc = pci_register_driver(&i82860_driver)) < 0)
  262. goto fail0;
  263. if (!mci_pdev) {
  264. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  265. PCI_DEVICE_ID_INTEL_82860_0, NULL);
  266. if (mci_pdev == NULL) {
  267. debugf0("860 pci_get_device fail\n");
  268. pci_rc = -ENODEV;
  269. goto fail1;
  270. }
  271. pci_rc = i82860_init_one(mci_pdev, i82860_pci_tbl);
  272. if (pci_rc < 0) {
  273. debugf0("860 init fail\n");
  274. pci_rc = -ENODEV;
  275. goto fail1;
  276. }
  277. }
  278. return 0;
  279. fail1:
  280. pci_unregister_driver(&i82860_driver);
  281. fail0:
  282. if (mci_pdev != NULL)
  283. pci_dev_put(mci_pdev);
  284. return pci_rc;
  285. }
  286. static void __exit i82860_exit(void)
  287. {
  288. debugf3("%s()\n", __func__);
  289. pci_unregister_driver(&i82860_driver);
  290. if (mci_pdev != NULL)
  291. pci_dev_put(mci_pdev);
  292. }
  293. module_init(i82860_init);
  294. module_exit(i82860_exit);
  295. MODULE_LICENSE("GPL");
  296. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com) "
  297. "Ben Woodard <woodard@redhat.com>");
  298. MODULE_DESCRIPTION("ECC support for Intel 82860 memory hub controllers");
  299. module_param(edac_op_state, int, 0444);
  300. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");