i82860_edac.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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->pdev);
  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, 1, 0, 0, 0,
  92. -1, -1, -1, "UE overwrote CE", "");
  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, 1,
  100. info->eap, 0, 0,
  101. dimm->location[0], dimm->location[1], -1,
  102. "i82860 UE", "");
  103. else
  104. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  105. info->eap, 0, info->derrsyn,
  106. dimm->location[0], dimm->location[1], -1,
  107. "i82860 CE", "");
  108. return 1;
  109. }
  110. static void i82860_check(struct mem_ctl_info *mci)
  111. {
  112. struct i82860_error_info info;
  113. edac_dbg(1, "MC%d\n", mci->mc_idx);
  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. edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
  141. if (cumul_size == last_cumul_size)
  142. continue; /* not populated */
  143. csrow->first_page = last_cumul_size;
  144. csrow->last_page = cumul_size - 1;
  145. dimm->nr_pages = cumul_size - last_cumul_size;
  146. last_cumul_size = cumul_size;
  147. dimm->grain = 1 << 12; /* I82860_EAP has 4KiB reolution */
  148. dimm->mtype = MEM_RMBS;
  149. dimm->dtype = DEV_UNKNOWN;
  150. dimm->edac_mode = mchcfg_ddim ? EDAC_SECDED : EDAC_NONE;
  151. }
  152. }
  153. static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
  154. {
  155. struct mem_ctl_info *mci;
  156. struct edac_mc_layer layers[2];
  157. struct i82860_error_info discard;
  158. /*
  159. * RDRAM has channels but these don't map onto the csrow abstraction.
  160. * According with the datasheet, there are 2 Rambus channels, supporting
  161. * up to 16 direct RDRAM devices.
  162. * The device groups from the GRA registers seem to map reasonably
  163. * well onto the notion of a chip select row.
  164. * There are 16 GRA registers and since the name is associated with
  165. * the channel and the GRA registers map to physical devices so we are
  166. * going to make 1 channel for group.
  167. */
  168. layers[0].type = EDAC_MC_LAYER_CHANNEL;
  169. layers[0].size = 2;
  170. layers[0].is_virt_csrow = true;
  171. layers[1].type = EDAC_MC_LAYER_SLOT;
  172. layers[1].size = 8;
  173. layers[1].is_virt_csrow = true;
  174. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
  175. if (!mci)
  176. return -ENOMEM;
  177. edac_dbg(3, "init mci\n");
  178. mci->pdev = &pdev->dev;
  179. mci->mtype_cap = MEM_FLAG_DDR;
  180. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  181. /* I"m not sure about this but I think that all RDRAM is SECDED */
  182. mci->edac_cap = EDAC_FLAG_SECDED;
  183. mci->mod_name = EDAC_MOD_STR;
  184. mci->mod_ver = I82860_REVISION;
  185. mci->ctl_name = i82860_devs[dev_idx].ctl_name;
  186. mci->dev_name = pci_name(pdev);
  187. mci->edac_check = i82860_check;
  188. mci->ctl_page_to_phys = NULL;
  189. i82860_init_csrows(mci, pdev);
  190. i82860_get_error_info(mci, &discard); /* clear counters */
  191. /* Here we assume that we will never see multiple instances of this
  192. * type of memory controller. The ID is therefore hardcoded to 0.
  193. */
  194. if (edac_mc_add_mc(mci)) {
  195. edac_dbg(3, "failed edac_mc_add_mc()\n");
  196. goto fail;
  197. }
  198. /* allocating generic PCI control info */
  199. i82860_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  200. if (!i82860_pci) {
  201. printk(KERN_WARNING
  202. "%s(): Unable to create PCI control\n",
  203. __func__);
  204. printk(KERN_WARNING
  205. "%s(): PCI error report via EDAC not setup\n",
  206. __func__);
  207. }
  208. /* get this far and it's successful */
  209. edac_dbg(3, "success\n");
  210. return 0;
  211. fail:
  212. edac_mc_free(mci);
  213. return -ENODEV;
  214. }
  215. /* returns count (>= 0), or negative on error */
  216. static int i82860_init_one(struct pci_dev *pdev,
  217. const struct pci_device_id *ent)
  218. {
  219. int rc;
  220. edac_dbg(0, "\n");
  221. i82860_printk(KERN_INFO, "i82860 init one\n");
  222. if (pci_enable_device(pdev) < 0)
  223. return -EIO;
  224. rc = i82860_probe1(pdev, ent->driver_data);
  225. if (rc == 0)
  226. mci_pdev = pci_dev_get(pdev);
  227. return rc;
  228. }
  229. static void i82860_remove_one(struct pci_dev *pdev)
  230. {
  231. struct mem_ctl_info *mci;
  232. edac_dbg(0, "\n");
  233. if (i82860_pci)
  234. edac_pci_release_generic_ctl(i82860_pci);
  235. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  236. return;
  237. edac_mc_free(mci);
  238. }
  239. static const struct pci_device_id i82860_pci_tbl[] = {
  240. {
  241. PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  242. I82860},
  243. {
  244. 0,
  245. } /* 0 terminated list. */
  246. };
  247. MODULE_DEVICE_TABLE(pci, i82860_pci_tbl);
  248. static struct pci_driver i82860_driver = {
  249. .name = EDAC_MOD_STR,
  250. .probe = i82860_init_one,
  251. .remove = i82860_remove_one,
  252. .id_table = i82860_pci_tbl,
  253. };
  254. static int __init i82860_init(void)
  255. {
  256. int pci_rc;
  257. edac_dbg(3, "\n");
  258. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  259. opstate_init();
  260. if ((pci_rc = pci_register_driver(&i82860_driver)) < 0)
  261. goto fail0;
  262. if (!mci_pdev) {
  263. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  264. PCI_DEVICE_ID_INTEL_82860_0, NULL);
  265. if (mci_pdev == NULL) {
  266. edac_dbg(0, "860 pci_get_device fail\n");
  267. pci_rc = -ENODEV;
  268. goto fail1;
  269. }
  270. pci_rc = i82860_init_one(mci_pdev, i82860_pci_tbl);
  271. if (pci_rc < 0) {
  272. edac_dbg(0, "860 init fail\n");
  273. pci_rc = -ENODEV;
  274. goto fail1;
  275. }
  276. }
  277. return 0;
  278. fail1:
  279. pci_unregister_driver(&i82860_driver);
  280. fail0:
  281. pci_dev_put(mci_pdev);
  282. return pci_rc;
  283. }
  284. static void __exit i82860_exit(void)
  285. {
  286. edac_dbg(3, "\n");
  287. pci_unregister_driver(&i82860_driver);
  288. pci_dev_put(mci_pdev);
  289. }
  290. module_init(i82860_init);
  291. module_exit(i82860_exit);
  292. MODULE_LICENSE("GPL");
  293. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com) "
  294. "Ben Woodard <woodard@redhat.com>");
  295. MODULE_DESCRIPTION("ECC support for Intel 82860 memory hub controllers");
  296. module_param(edac_op_state, int, 0444);
  297. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");