edac_pci_sysfs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * (C) 2005, 2006 Linux Networx (http://lnxi.com)
  3. * This file may be distributed under the terms of the
  4. * GNU General Public License.
  5. *
  6. * Written Doug Thompson <norsk5@xmission.com>
  7. *
  8. */
  9. #include <linux/module.h>
  10. #include <linux/sysdev.h>
  11. #include <linux/ctype.h>
  12. #include "edac_core.h"
  13. #include "edac_module.h"
  14. /* Turn off this whole feature if PCI is not configured */
  15. #ifdef CONFIG_PCI
  16. #define EDAC_PCI_SYMLINK "device"
  17. /* data variables exported via sysfs */
  18. static int check_pci_errors; /* default NO check PCI parity */
  19. static int edac_pci_panic_on_pe; /* default NO panic on PCI Parity */
  20. static int edac_pci_log_pe = 1; /* log PCI parity errors */
  21. static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
  22. static int edac_pci_poll_msec = 1000; /* one second workq period */
  23. static atomic_t pci_parity_count = ATOMIC_INIT(0);
  24. static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
  25. static struct kobject edac_pci_top_main_kobj;
  26. static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
  27. /* getter functions for the data variables */
  28. int edac_pci_get_check_errors(void)
  29. {
  30. return check_pci_errors;
  31. }
  32. int edac_pci_get_log_pe(void)
  33. {
  34. return edac_pci_log_pe;
  35. }
  36. int edac_pci_get_log_npe(void)
  37. {
  38. return edac_pci_log_npe;
  39. }
  40. int edac_pci_get_panic_on_pe(void)
  41. {
  42. return edac_pci_panic_on_pe;
  43. }
  44. int edac_pci_get_poll_msec(void)
  45. {
  46. return edac_pci_poll_msec;
  47. }
  48. /**************************** EDAC PCI sysfs instance *******************/
  49. static ssize_t instance_pe_count_show(struct edac_pci_ctl_info *pci, char *data)
  50. {
  51. return sprintf(data, "%u\n", atomic_read(&pci->counters.pe_count));
  52. }
  53. static ssize_t instance_npe_count_show(struct edac_pci_ctl_info *pci,
  54. char *data)
  55. {
  56. return sprintf(data, "%u\n", atomic_read(&pci->counters.npe_count));
  57. }
  58. #define to_instance(k) container_of(k, struct edac_pci_ctl_info, kobj)
  59. #define to_instance_attr(a) container_of(a, struct instance_attribute, attr)
  60. /* DEVICE instance kobject release() function */
  61. static void edac_pci_instance_release(struct kobject *kobj)
  62. {
  63. struct edac_pci_ctl_info *pci;
  64. debugf0("%s()\n", __func__);
  65. /* Form pointer to containing struct, the pci control struct */
  66. pci = to_instance(kobj);
  67. /* decrement reference count on top main kobj */
  68. kobject_put(&edac_pci_top_main_kobj);
  69. kfree(pci); /* Free the control struct */
  70. }
  71. /* instance specific attribute structure */
  72. struct instance_attribute {
  73. struct attribute attr;
  74. ssize_t(*show) (struct edac_pci_ctl_info *, char *);
  75. ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t);
  76. };
  77. /* Function to 'show' fields from the edac_pci 'instance' structure */
  78. static ssize_t edac_pci_instance_show(struct kobject *kobj,
  79. struct attribute *attr, char *buffer)
  80. {
  81. struct edac_pci_ctl_info *pci = to_instance(kobj);
  82. struct instance_attribute *instance_attr = to_instance_attr(attr);
  83. if (instance_attr->show)
  84. return instance_attr->show(pci, buffer);
  85. return -EIO;
  86. }
  87. /* Function to 'store' fields into the edac_pci 'instance' structure */
  88. static ssize_t edac_pci_instance_store(struct kobject *kobj,
  89. struct attribute *attr,
  90. const char *buffer, size_t count)
  91. {
  92. struct edac_pci_ctl_info *pci = to_instance(kobj);
  93. struct instance_attribute *instance_attr = to_instance_attr(attr);
  94. if (instance_attr->store)
  95. return instance_attr->store(pci, buffer, count);
  96. return -EIO;
  97. }
  98. /* fs_ops table */
  99. static struct sysfs_ops pci_instance_ops = {
  100. .show = edac_pci_instance_show,
  101. .store = edac_pci_instance_store
  102. };
  103. #define INSTANCE_ATTR(_name, _mode, _show, _store) \
  104. static struct instance_attribute attr_instance_##_name = { \
  105. .attr = {.name = __stringify(_name), .mode = _mode }, \
  106. .show = _show, \
  107. .store = _store, \
  108. };
  109. INSTANCE_ATTR(pe_count, S_IRUGO, instance_pe_count_show, NULL);
  110. INSTANCE_ATTR(npe_count, S_IRUGO, instance_npe_count_show, NULL);
  111. /* pci instance attributes */
  112. static struct instance_attribute *pci_instance_attr[] = {
  113. &attr_instance_pe_count,
  114. &attr_instance_npe_count,
  115. NULL
  116. };
  117. /* the ktype for a pci instance */
  118. static struct kobj_type ktype_pci_instance = {
  119. .release = edac_pci_instance_release,
  120. .sysfs_ops = &pci_instance_ops,
  121. .default_attrs = (struct attribute **)pci_instance_attr,
  122. };
  123. /*
  124. * edac_pci_create_instance_kobj
  125. *
  126. * construct one EDAC PCI instance's kobject for use
  127. */
  128. static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
  129. {
  130. struct kobject *main_kobj;
  131. int err;
  132. debugf0("%s()\n", __func__);
  133. /* First bump the ref count on the top main kobj, which will
  134. * track the number of PCI instances we have, and thus nest
  135. * properly on keeping the module loaded
  136. */
  137. main_kobj = kobject_get(&edac_pci_top_main_kobj);
  138. if (!main_kobj) {
  139. err = -ENODEV;
  140. goto error_out;
  141. }
  142. /* And now register this new kobject under the main kobj */
  143. err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
  144. &edac_pci_top_main_kobj, "pci%d", idx);
  145. if (err != 0) {
  146. debugf2("%s() failed to register instance pci%d\n",
  147. __func__, idx);
  148. kobject_put(&edac_pci_top_main_kobj);
  149. goto error_out;
  150. }
  151. kobject_uevent(&pci->kobj, KOBJ_ADD);
  152. debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx);
  153. return 0;
  154. /* Error unwind statck */
  155. error_out:
  156. return err;
  157. }
  158. /*
  159. * edac_pci_unregister_sysfs_instance_kobj
  160. *
  161. * unregister the kobj for the EDAC PCI instance
  162. */
  163. void edac_pci_unregister_sysfs_instance_kobj(struct edac_pci_ctl_info *pci)
  164. {
  165. debugf0("%s()\n", __func__);
  166. /* Unregister the instance kobject and allow its release
  167. * function release the main reference count and then
  168. * kfree the memory
  169. */
  170. kobject_put(&pci->kobj);
  171. }
  172. /***************************** EDAC PCI sysfs root **********************/
  173. #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
  174. #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
  175. /* simple show/store functions for attributes */
  176. static ssize_t edac_pci_int_show(void *ptr, char *buffer)
  177. {
  178. int *value = ptr;
  179. return sprintf(buffer, "%d\n", *value);
  180. }
  181. static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
  182. {
  183. int *value = ptr;
  184. if (isdigit(*buffer))
  185. *value = simple_strtoul(buffer, NULL, 0);
  186. return count;
  187. }
  188. struct edac_pci_dev_attribute {
  189. struct attribute attr;
  190. void *value;
  191. ssize_t(*show) (void *, char *);
  192. ssize_t(*store) (void *, const char *, size_t);
  193. };
  194. /* Set of show/store abstract level functions for PCI Parity object */
  195. static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
  196. char *buffer)
  197. {
  198. struct edac_pci_dev_attribute *edac_pci_dev;
  199. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  200. if (edac_pci_dev->show)
  201. return edac_pci_dev->show(edac_pci_dev->value, buffer);
  202. return -EIO;
  203. }
  204. static ssize_t edac_pci_dev_store(struct kobject *kobj,
  205. struct attribute *attr, const char *buffer,
  206. size_t count)
  207. {
  208. struct edac_pci_dev_attribute *edac_pci_dev;
  209. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  210. if (edac_pci_dev->show)
  211. return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
  212. return -EIO;
  213. }
  214. static struct sysfs_ops edac_pci_sysfs_ops = {
  215. .show = edac_pci_dev_show,
  216. .store = edac_pci_dev_store
  217. };
  218. #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
  219. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  220. .attr = {.name = __stringify(_name), .mode = _mode }, \
  221. .value = &_name, \
  222. .show = _show, \
  223. .store = _store, \
  224. };
  225. #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \
  226. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  227. .attr = {.name = __stringify(_name), .mode = _mode }, \
  228. .value = _data, \
  229. .show = _show, \
  230. .store = _store, \
  231. };
  232. /* PCI Parity control files */
  233. EDAC_PCI_ATTR(check_pci_errors, S_IRUGO | S_IWUSR, edac_pci_int_show,
  234. edac_pci_int_store);
  235. EDAC_PCI_ATTR(edac_pci_log_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  236. edac_pci_int_store);
  237. EDAC_PCI_ATTR(edac_pci_log_npe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  238. edac_pci_int_store);
  239. EDAC_PCI_ATTR(edac_pci_panic_on_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  240. edac_pci_int_store);
  241. EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
  242. EDAC_PCI_ATTR(pci_nonparity_count, S_IRUGO, edac_pci_int_show, NULL);
  243. /* Base Attributes of the memory ECC object */
  244. static struct edac_pci_dev_attribute *edac_pci_attr[] = {
  245. &edac_pci_attr_check_pci_errors,
  246. &edac_pci_attr_edac_pci_log_pe,
  247. &edac_pci_attr_edac_pci_log_npe,
  248. &edac_pci_attr_edac_pci_panic_on_pe,
  249. &edac_pci_attr_pci_parity_count,
  250. &edac_pci_attr_pci_nonparity_count,
  251. NULL,
  252. };
  253. /*
  254. * edac_pci_release_main_kobj
  255. *
  256. * This release function is called when the reference count to the
  257. * passed kobj goes to zero.
  258. *
  259. * This kobj is the 'main' kobject that EDAC PCI instances
  260. * link to, and thus provide for proper nesting counts
  261. */
  262. static void edac_pci_release_main_kobj(struct kobject *kobj)
  263. {
  264. debugf0("%s() here to module_put(THIS_MODULE)\n", __func__);
  265. /* last reference to top EDAC PCI kobject has been removed,
  266. * NOW release our ref count on the core module
  267. */
  268. module_put(THIS_MODULE);
  269. }
  270. /* ktype struct for the EDAC PCI main kobj */
  271. static struct kobj_type ktype_edac_pci_main_kobj = {
  272. .release = edac_pci_release_main_kobj,
  273. .sysfs_ops = &edac_pci_sysfs_ops,
  274. .default_attrs = (struct attribute **)edac_pci_attr,
  275. };
  276. /**
  277. * edac_pci_main_kobj_setup()
  278. *
  279. * setup the sysfs for EDAC PCI attributes
  280. * assumes edac_class has already been initialized
  281. */
  282. int edac_pci_main_kobj_setup(void)
  283. {
  284. int err;
  285. struct sysdev_class *edac_class;
  286. debugf0("%s()\n", __func__);
  287. /* check and count if we have already created the main kobject */
  288. if (atomic_inc_return(&edac_pci_sysfs_refcount) != 1)
  289. return 0;
  290. /* First time, so create the main kobject and its
  291. * controls and atributes
  292. */
  293. edac_class = edac_get_edac_class();
  294. if (edac_class == NULL) {
  295. debugf1("%s() no edac_class\n", __func__);
  296. err = -ENODEV;
  297. goto decrement_count_fail;
  298. }
  299. /* Bump the reference count on this module to ensure the
  300. * modules isn't unloaded until we deconstruct the top
  301. * level main kobj for EDAC PCI
  302. */
  303. if (!try_module_get(THIS_MODULE)) {
  304. debugf1("%s() try_module_get() failed\n", __func__);
  305. err = -ENODEV;
  306. goto decrement_count_fail;
  307. }
  308. /* Instanstiate the pci object */
  309. err = kobject_init_and_add(&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj,
  310. &edac_class->kset.kobj, "pci");
  311. if (err) {
  312. debugf1("Failed to register '.../edac/pci'\n");
  313. goto kobject_init_and_add_fail;
  314. }
  315. /* At this point, to 'release' the top level kobject
  316. * for EDAC PCI, then edac_pci_main_kobj_teardown()
  317. * must be used, for resources to be cleaned up properly
  318. */
  319. kobject_uevent(&edac_pci_top_main_kobj, KOBJ_ADD);
  320. debugf1("Registered '.../edac/pci' kobject\n");
  321. return 0;
  322. /* Error unwind statck */
  323. kobject_init_and_add_fail:
  324. module_put(THIS_MODULE);
  325. decrement_count_fail:
  326. /* if are on this error exit, nothing to tear down */
  327. atomic_dec(&edac_pci_sysfs_refcount);
  328. return err;
  329. }
  330. /*
  331. * edac_pci_main_kobj_teardown()
  332. *
  333. * if no longer linked (needed) remove the top level EDAC PCI
  334. * kobject with its controls and attributes
  335. */
  336. static void edac_pci_main_kobj_teardown(void)
  337. {
  338. debugf0("%s()\n", __func__);
  339. /* Decrement the count and only if no more controller instances
  340. * are connected perform the unregisteration of the top level
  341. * main kobj
  342. */
  343. if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
  344. debugf0("%s() called kobject_put on main kobj\n",
  345. __func__);
  346. kobject_put(&edac_pci_top_main_kobj);
  347. }
  348. }
  349. /*
  350. *
  351. * edac_pci_create_sysfs
  352. *
  353. * Create the controls/attributes for the specified EDAC PCI device
  354. */
  355. int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci)
  356. {
  357. int err;
  358. struct kobject *edac_kobj = &pci->kobj;
  359. debugf0("%s() idx=%d\n", __func__, pci->pci_idx);
  360. /* create the top main EDAC PCI kobject, IF needed */
  361. err = edac_pci_main_kobj_setup();
  362. if (err)
  363. return err;
  364. /* Create this instance's kobject under the MAIN kobject */
  365. err = edac_pci_create_instance_kobj(pci, pci->pci_idx);
  366. if (err)
  367. goto unregister_cleanup;
  368. err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK);
  369. if (err) {
  370. debugf0("%s() sysfs_create_link() returned err= %d\n",
  371. __func__, err);
  372. goto symlink_fail;
  373. }
  374. return 0;
  375. /* Error unwind stack */
  376. symlink_fail:
  377. edac_pci_unregister_sysfs_instance_kobj(pci);
  378. unregister_cleanup:
  379. edac_pci_main_kobj_teardown();
  380. return err;
  381. }
  382. /*
  383. * edac_pci_remove_sysfs
  384. *
  385. * remove the controls and attributes for this EDAC PCI device
  386. */
  387. void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci)
  388. {
  389. debugf0("%s() index=%d\n", __func__, pci->pci_idx);
  390. /* Remove the symlink */
  391. sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK);
  392. /* remove this PCI instance's sysfs entries */
  393. edac_pci_unregister_sysfs_instance_kobj(pci);
  394. /* Call the main unregister function, which will determine
  395. * if this 'pci' is the last instance.
  396. * If it is, the main kobject will be unregistered as a result
  397. */
  398. debugf0("%s() calling edac_pci_main_kobj_teardown()\n", __func__);
  399. edac_pci_main_kobj_teardown();
  400. }
  401. /************************ PCI error handling *************************/
  402. static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
  403. {
  404. int where;
  405. u16 status;
  406. where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
  407. pci_read_config_word(dev, where, &status);
  408. /* If we get back 0xFFFF then we must suspect that the card has been
  409. * pulled but the Linux PCI layer has not yet finished cleaning up.
  410. * We don't want to report on such devices
  411. */
  412. if (status == 0xFFFF) {
  413. u32 sanity;
  414. pci_read_config_dword(dev, 0, &sanity);
  415. if (sanity == 0xFFFFFFFF)
  416. return 0;
  417. }
  418. status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
  419. PCI_STATUS_PARITY;
  420. if (status)
  421. /* reset only the bits we are interested in */
  422. pci_write_config_word(dev, where, status);
  423. return status;
  424. }
  425. /* Clear any PCI parity errors logged by this device. */
  426. static void edac_pci_dev_parity_clear(struct pci_dev *dev)
  427. {
  428. u8 header_type;
  429. debugf0("%s()\n", __func__);
  430. get_pci_parity_status(dev, 0);
  431. /* read the device TYPE, looking for bridges */
  432. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  433. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE)
  434. get_pci_parity_status(dev, 1);
  435. }
  436. /*
  437. * PCI Parity polling
  438. *
  439. * Fucntion to retrieve the current parity status
  440. * and decode it
  441. *
  442. */
  443. static void edac_pci_dev_parity_test(struct pci_dev *dev)
  444. {
  445. unsigned long flags;
  446. u16 status;
  447. u8 header_type;
  448. /* stop any interrupts until we can acquire the status */
  449. local_irq_save(flags);
  450. /* read the STATUS register on this device */
  451. status = get_pci_parity_status(dev, 0);
  452. /* read the device TYPE, looking for bridges */
  453. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  454. local_irq_restore(flags);
  455. debugf4("PCI STATUS= 0x%04x %s\n", status, dev->dev.bus_id);
  456. /* check the status reg for errors */
  457. if (status) {
  458. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
  459. edac_printk(KERN_CRIT, EDAC_PCI,
  460. "Signaled System Error on %s\n",
  461. pci_name(dev));
  462. atomic_inc(&pci_nonparity_count);
  463. }
  464. if (status & (PCI_STATUS_PARITY)) {
  465. edac_printk(KERN_CRIT, EDAC_PCI,
  466. "Master Data Parity Error on %s\n",
  467. pci_name(dev));
  468. atomic_inc(&pci_parity_count);
  469. }
  470. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  471. edac_printk(KERN_CRIT, EDAC_PCI,
  472. "Detected Parity Error on %s\n",
  473. pci_name(dev));
  474. atomic_inc(&pci_parity_count);
  475. }
  476. }
  477. debugf4("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev->dev.bus_id);
  478. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  479. /* On bridges, need to examine secondary status register */
  480. status = get_pci_parity_status(dev, 1);
  481. debugf4("PCI SEC_STATUS= 0x%04x %s\n", status, dev->dev.bus_id);
  482. /* check the secondary status reg for errors */
  483. if (status) {
  484. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
  485. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  486. "Signaled System Error on %s\n",
  487. pci_name(dev));
  488. atomic_inc(&pci_nonparity_count);
  489. }
  490. if (status & (PCI_STATUS_PARITY)) {
  491. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  492. "Master Data Parity Error on "
  493. "%s\n", pci_name(dev));
  494. atomic_inc(&pci_parity_count);
  495. }
  496. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  497. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  498. "Detected Parity Error on %s\n",
  499. pci_name(dev));
  500. atomic_inc(&pci_parity_count);
  501. }
  502. }
  503. }
  504. }
  505. /* reduce some complexity in definition of the iterator */
  506. typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
  507. /*
  508. * pci_dev parity list iterator
  509. * Scan the PCI device list for one pass, looking for SERRORs
  510. * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
  511. */
  512. static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
  513. {
  514. struct pci_dev *dev = NULL;
  515. /* request for kernel access to the next PCI device, if any,
  516. * and while we are looking at it have its reference count
  517. * bumped until we are done with it
  518. */
  519. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  520. fn(dev);
  521. }
  522. }
  523. /*
  524. * edac_pci_do_parity_check
  525. *
  526. * performs the actual PCI parity check operation
  527. */
  528. void edac_pci_do_parity_check(void)
  529. {
  530. int before_count;
  531. debugf3("%s()\n", __func__);
  532. /* if policy has PCI check off, leave now */
  533. if (!check_pci_errors)
  534. return;
  535. before_count = atomic_read(&pci_parity_count);
  536. /* scan all PCI devices looking for a Parity Error on devices and
  537. * bridges.
  538. * The iterator calls pci_get_device() which might sleep, thus
  539. * we cannot disable interrupts in this scan.
  540. */
  541. edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
  542. /* Only if operator has selected panic on PCI Error */
  543. if (edac_pci_get_panic_on_pe()) {
  544. /* If the count is different 'after' from 'before' */
  545. if (before_count != atomic_read(&pci_parity_count))
  546. panic("EDAC: PCI Parity Error");
  547. }
  548. }
  549. /*
  550. * edac_pci_clear_parity_errors
  551. *
  552. * function to perform an iteration over the PCI devices
  553. * and clearn their current status
  554. */
  555. void edac_pci_clear_parity_errors(void)
  556. {
  557. /* Clear any PCI bus parity errors that devices initially have logged
  558. * in their registers.
  559. */
  560. edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
  561. }
  562. /*
  563. * edac_pci_handle_pe
  564. *
  565. * Called to handle a PARITY ERROR event
  566. */
  567. void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg)
  568. {
  569. /* global PE counter incremented by edac_pci_do_parity_check() */
  570. atomic_inc(&pci->counters.pe_count);
  571. if (edac_pci_get_log_pe())
  572. edac_pci_printk(pci, KERN_WARNING,
  573. "Parity Error ctl: %s %d: %s\n",
  574. pci->ctl_name, pci->pci_idx, msg);
  575. /*
  576. * poke all PCI devices and see which one is the troublemaker
  577. * panic() is called if set
  578. */
  579. edac_pci_do_parity_check();
  580. }
  581. EXPORT_SYMBOL_GPL(edac_pci_handle_pe);
  582. /*
  583. * edac_pci_handle_npe
  584. *
  585. * Called to handle a NON-PARITY ERROR event
  586. */
  587. void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg)
  588. {
  589. /* global NPE counter incremented by edac_pci_do_parity_check() */
  590. atomic_inc(&pci->counters.npe_count);
  591. if (edac_pci_get_log_npe())
  592. edac_pci_printk(pci, KERN_WARNING,
  593. "Non-Parity Error ctl: %s %d: %s\n",
  594. pci->ctl_name, pci->pci_idx, msg);
  595. /*
  596. * poke all PCI devices and see which one is the troublemaker
  597. * panic() is called if set
  598. */
  599. edac_pci_do_parity_check();
  600. }
  601. EXPORT_SYMBOL_GPL(edac_pci_handle_npe);
  602. /*
  603. * Define the PCI parameter to the module
  604. */
  605. module_param(check_pci_errors, int, 0644);
  606. MODULE_PARM_DESC(check_pci_errors,
  607. "Check for PCI bus parity errors: 0=off 1=on");
  608. module_param(edac_pci_panic_on_pe, int, 0644);
  609. MODULE_PARM_DESC(edac_pci_panic_on_pe,
  610. "Panic on PCI Bus Parity error: 0=off 1=on");
  611. #endif /* CONFIG_PCI */