i82860_edac.c 9.1 KB

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