amd8131_edac.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * amd8131_edac.c, AMD8131 hypertransport chip EDAC kernel module
  3. *
  4. * Copyright (c) 2008 Wind River Systems, Inc.
  5. *
  6. * Authors: Cao Qingtao <qingtao.cao@windriver.com>
  7. * Benjamin Walsh <benjamin.walsh@windriver.com>
  8. * Hu Yongqi <yongqi.hu@windriver.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/bitops.h>
  28. #include <linux/edac.h>
  29. #include <linux/pci_ids.h>
  30. #include "edac_module.h"
  31. #include "amd8131_edac.h"
  32. #define AMD8131_EDAC_REVISION " Ver: 1.0.0"
  33. #define AMD8131_EDAC_MOD_STR "amd8131_edac"
  34. /* Wrapper functions for accessing PCI configuration space */
  35. static void edac_pci_read_dword(struct pci_dev *dev, int reg, u32 *val32)
  36. {
  37. int ret;
  38. ret = pci_read_config_dword(dev, reg, val32);
  39. if (ret != 0)
  40. printk(KERN_ERR AMD8131_EDAC_MOD_STR
  41. " PCI Access Read Error at 0x%x\n", reg);
  42. }
  43. static void edac_pci_write_dword(struct pci_dev *dev, int reg, u32 val32)
  44. {
  45. int ret;
  46. ret = pci_write_config_dword(dev, reg, val32);
  47. if (ret != 0)
  48. printk(KERN_ERR AMD8131_EDAC_MOD_STR
  49. " PCI Access Write Error at 0x%x\n", reg);
  50. }
  51. static char * const bridge_str[] = {
  52. [NORTH_A] = "NORTH A",
  53. [NORTH_B] = "NORTH B",
  54. [SOUTH_A] = "SOUTH A",
  55. [SOUTH_B] = "SOUTH B",
  56. [NO_BRIDGE] = "NO BRIDGE",
  57. };
  58. /* Support up to two AMD8131 chipsets on a platform */
  59. static struct amd8131_dev_info amd8131_devices[] = {
  60. {
  61. .inst = NORTH_A,
  62. .devfn = DEVFN_PCIX_BRIDGE_NORTH_A,
  63. .ctl_name = "AMD8131_PCIX_NORTH_A",
  64. },
  65. {
  66. .inst = NORTH_B,
  67. .devfn = DEVFN_PCIX_BRIDGE_NORTH_B,
  68. .ctl_name = "AMD8131_PCIX_NORTH_B",
  69. },
  70. {
  71. .inst = SOUTH_A,
  72. .devfn = DEVFN_PCIX_BRIDGE_SOUTH_A,
  73. .ctl_name = "AMD8131_PCIX_SOUTH_A",
  74. },
  75. {
  76. .inst = SOUTH_B,
  77. .devfn = DEVFN_PCIX_BRIDGE_SOUTH_B,
  78. .ctl_name = "AMD8131_PCIX_SOUTH_B",
  79. },
  80. {.inst = NO_BRIDGE,},
  81. };
  82. static void amd8131_pcix_init(struct amd8131_dev_info *dev_info)
  83. {
  84. u32 val32;
  85. struct pci_dev *dev = dev_info->dev;
  86. /* First clear error detection flags */
  87. edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
  88. if (val32 & MEM_LIMIT_MASK)
  89. edac_pci_write_dword(dev, REG_MEM_LIM, val32);
  90. /* Clear Discard Timer Timedout flag */
  91. edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
  92. if (val32 & INT_CTLR_DTS)
  93. edac_pci_write_dword(dev, REG_INT_CTLR, val32);
  94. /* Clear CRC Error flag on link side A */
  95. edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
  96. if (val32 & LNK_CTRL_CRCERR_A)
  97. edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
  98. /* Clear CRC Error flag on link side B */
  99. edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
  100. if (val32 & LNK_CTRL_CRCERR_B)
  101. edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
  102. /*
  103. * Then enable all error detections.
  104. *
  105. * Setup Discard Timer Sync Flood Enable,
  106. * System Error Enable and Parity Error Enable.
  107. */
  108. edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
  109. val32 |= INT_CTLR_PERR | INT_CTLR_SERR | INT_CTLR_DTSE;
  110. edac_pci_write_dword(dev, REG_INT_CTLR, val32);
  111. /* Enable overall SERR Error detection */
  112. edac_pci_read_dword(dev, REG_STS_CMD, &val32);
  113. val32 |= STS_CMD_SERREN;
  114. edac_pci_write_dword(dev, REG_STS_CMD, val32);
  115. /* Setup CRC Flood Enable for link side A */
  116. edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
  117. val32 |= LNK_CTRL_CRCFEN;
  118. edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
  119. /* Setup CRC Flood Enable for link side B */
  120. edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
  121. val32 |= LNK_CTRL_CRCFEN;
  122. edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
  123. }
  124. static void amd8131_pcix_exit(struct amd8131_dev_info *dev_info)
  125. {
  126. u32 val32;
  127. struct pci_dev *dev = dev_info->dev;
  128. /* Disable SERR, PERR and DTSE Error detection */
  129. edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
  130. val32 &= ~(INT_CTLR_PERR | INT_CTLR_SERR | INT_CTLR_DTSE);
  131. edac_pci_write_dword(dev, REG_INT_CTLR, val32);
  132. /* Disable overall System Error detection */
  133. edac_pci_read_dword(dev, REG_STS_CMD, &val32);
  134. val32 &= ~STS_CMD_SERREN;
  135. edac_pci_write_dword(dev, REG_STS_CMD, val32);
  136. /* Disable CRC Sync Flood on link side A */
  137. edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
  138. val32 &= ~LNK_CTRL_CRCFEN;
  139. edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
  140. /* Disable CRC Sync Flood on link side B */
  141. edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
  142. val32 &= ~LNK_CTRL_CRCFEN;
  143. edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
  144. }
  145. static void amd8131_pcix_check(struct edac_pci_ctl_info *edac_dev)
  146. {
  147. struct amd8131_dev_info *dev_info = edac_dev->pvt_info;
  148. struct pci_dev *dev = dev_info->dev;
  149. u32 val32;
  150. /* Check PCI-X Bridge Memory Base-Limit Register for errors */
  151. edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
  152. if (val32 & MEM_LIMIT_MASK) {
  153. printk(KERN_INFO "Error(s) in mem limit register "
  154. "on %s bridge\n", dev_info->ctl_name);
  155. printk(KERN_INFO "DPE: %d, RSE: %d, RMA: %d\n"
  156. "RTA: %d, STA: %d, MDPE: %d\n",
  157. val32 & MEM_LIMIT_DPE,
  158. val32 & MEM_LIMIT_RSE,
  159. val32 & MEM_LIMIT_RMA,
  160. val32 & MEM_LIMIT_RTA,
  161. val32 & MEM_LIMIT_STA,
  162. val32 & MEM_LIMIT_MDPE);
  163. val32 |= MEM_LIMIT_MASK;
  164. edac_pci_write_dword(dev, REG_MEM_LIM, val32);
  165. edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
  166. }
  167. /* Check if Discard Timer timed out */
  168. edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
  169. if (val32 & INT_CTLR_DTS) {
  170. printk(KERN_INFO "Error(s) in interrupt and control register "
  171. "on %s bridge\n", dev_info->ctl_name);
  172. printk(KERN_INFO "DTS: %d\n", val32 & INT_CTLR_DTS);
  173. val32 |= INT_CTLR_DTS;
  174. edac_pci_write_dword(dev, REG_INT_CTLR, val32);
  175. edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
  176. }
  177. /* Check if CRC error happens on link side A */
  178. edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
  179. if (val32 & LNK_CTRL_CRCERR_A) {
  180. printk(KERN_INFO "Error(s) in link conf and control register "
  181. "on %s bridge\n", dev_info->ctl_name);
  182. printk(KERN_INFO "CRCERR: %d\n", val32 & LNK_CTRL_CRCERR_A);
  183. val32 |= LNK_CTRL_CRCERR_A;
  184. edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
  185. edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
  186. }
  187. /* Check if CRC error happens on link side B */
  188. edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
  189. if (val32 & LNK_CTRL_CRCERR_B) {
  190. printk(KERN_INFO "Error(s) in link conf and control register "
  191. "on %s bridge\n", dev_info->ctl_name);
  192. printk(KERN_INFO "CRCERR: %d\n", val32 & LNK_CTRL_CRCERR_B);
  193. val32 |= LNK_CTRL_CRCERR_B;
  194. edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
  195. edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
  196. }
  197. }
  198. static struct amd8131_info amd8131_chipset = {
  199. .err_dev = PCI_DEVICE_ID_AMD_8131_APIC,
  200. .devices = amd8131_devices,
  201. .init = amd8131_pcix_init,
  202. .exit = amd8131_pcix_exit,
  203. .check = amd8131_pcix_check,
  204. };
  205. /*
  206. * There are 4 PCIX Bridges on ATCA-6101 that share the same PCI Device ID,
  207. * so amd8131_probe() would be called by kernel 4 times, with different
  208. * address of pci_dev for each of them each time.
  209. */
  210. static int amd8131_probe(struct pci_dev *dev, const struct pci_device_id *id)
  211. {
  212. struct amd8131_dev_info *dev_info;
  213. for (dev_info = amd8131_chipset.devices; dev_info->inst != NO_BRIDGE;
  214. dev_info++)
  215. if (dev_info->devfn == dev->devfn)
  216. break;
  217. if (dev_info->inst == NO_BRIDGE) /* should never happen */
  218. return -ENODEV;
  219. /*
  220. * We can't call pci_get_device() as we are used to do because
  221. * there are 4 of them but pci_dev_get() instead.
  222. */
  223. dev_info->dev = pci_dev_get(dev);
  224. if (pci_enable_device(dev_info->dev)) {
  225. pci_dev_put(dev_info->dev);
  226. printk(KERN_ERR "failed to enable:"
  227. "vendor %x, device %x, devfn %x, name %s\n",
  228. PCI_VENDOR_ID_AMD, amd8131_chipset.err_dev,
  229. dev_info->devfn, dev_info->ctl_name);
  230. return -ENODEV;
  231. }
  232. /*
  233. * we do not allocate extra private structure for
  234. * edac_pci_ctl_info, but make use of existing
  235. * one instead.
  236. */
  237. dev_info->edac_idx = edac_pci_alloc_index();
  238. dev_info->edac_dev = edac_pci_alloc_ctl_info(0, dev_info->ctl_name);
  239. if (!dev_info->edac_dev)
  240. return -ENOMEM;
  241. dev_info->edac_dev->pvt_info = dev_info;
  242. dev_info->edac_dev->dev = &dev_info->dev->dev;
  243. dev_info->edac_dev->mod_name = AMD8131_EDAC_MOD_STR;
  244. dev_info->edac_dev->ctl_name = dev_info->ctl_name;
  245. dev_info->edac_dev->dev_name = dev_name(&dev_info->dev->dev);
  246. if (edac_op_state == EDAC_OPSTATE_POLL)
  247. dev_info->edac_dev->edac_check = amd8131_chipset.check;
  248. if (amd8131_chipset.init)
  249. amd8131_chipset.init(dev_info);
  250. if (edac_pci_add_device(dev_info->edac_dev, dev_info->edac_idx) > 0) {
  251. printk(KERN_ERR "failed edac_pci_add_device() for %s\n",
  252. dev_info->ctl_name);
  253. edac_pci_free_ctl_info(dev_info->edac_dev);
  254. return -ENODEV;
  255. }
  256. printk(KERN_INFO "added one device on AMD8131 "
  257. "vendor %x, device %x, devfn %x, name %s\n",
  258. PCI_VENDOR_ID_AMD, amd8131_chipset.err_dev,
  259. dev_info->devfn, dev_info->ctl_name);
  260. return 0;
  261. }
  262. static void amd8131_remove(struct pci_dev *dev)
  263. {
  264. struct amd8131_dev_info *dev_info;
  265. for (dev_info = amd8131_chipset.devices; dev_info->inst != NO_BRIDGE;
  266. dev_info++)
  267. if (dev_info->devfn == dev->devfn)
  268. break;
  269. if (dev_info->inst == NO_BRIDGE) /* should never happen */
  270. return;
  271. if (dev_info->edac_dev) {
  272. edac_pci_del_device(dev_info->edac_dev->dev);
  273. edac_pci_free_ctl_info(dev_info->edac_dev);
  274. }
  275. if (amd8131_chipset.exit)
  276. amd8131_chipset.exit(dev_info);
  277. pci_dev_put(dev_info->dev);
  278. }
  279. static const struct pci_device_id amd8131_edac_pci_tbl[] = {
  280. {
  281. PCI_VEND_DEV(AMD, 8131_BRIDGE),
  282. .subvendor = PCI_ANY_ID,
  283. .subdevice = PCI_ANY_ID,
  284. .class = 0,
  285. .class_mask = 0,
  286. .driver_data = 0,
  287. },
  288. {
  289. 0,
  290. } /* table is NULL-terminated */
  291. };
  292. MODULE_DEVICE_TABLE(pci, amd8131_edac_pci_tbl);
  293. static struct pci_driver amd8131_edac_driver = {
  294. .name = AMD8131_EDAC_MOD_STR,
  295. .probe = amd8131_probe,
  296. .remove = amd8131_remove,
  297. .id_table = amd8131_edac_pci_tbl,
  298. };
  299. static int __init amd8131_edac_init(void)
  300. {
  301. printk(KERN_INFO "AMD8131 EDAC driver " AMD8131_EDAC_REVISION "\n");
  302. printk(KERN_INFO "\t(c) 2008 Wind River Systems, Inc.\n");
  303. /* Only POLL mode supported so far */
  304. edac_op_state = EDAC_OPSTATE_POLL;
  305. return pci_register_driver(&amd8131_edac_driver);
  306. }
  307. static void __exit amd8131_edac_exit(void)
  308. {
  309. pci_unregister_driver(&amd8131_edac_driver);
  310. }
  311. module_init(amd8131_edac_init);
  312. module_exit(amd8131_edac_exit);
  313. MODULE_LICENSE("GPL");
  314. MODULE_AUTHOR("Cao Qingtao <qingtao.cao@windriver.com>\n");
  315. MODULE_DESCRIPTION("AMD8131 HyperTransport PCI-X Tunnel EDAC kernel module");