edac_pci_sysfs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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/edac.h>
  11. #include <linux/slab.h>
  12. #include <linux/ctype.h>
  13. #include "edac_core.h"
  14. #include "edac_module.h"
  15. #define EDAC_PCI_SYMLINK "device"
  16. /* data variables exported via sysfs */
  17. static int check_pci_errors; /* default NO check PCI parity */
  18. static int edac_pci_panic_on_pe; /* default NO panic on PCI Parity */
  19. static int edac_pci_log_pe = 1; /* log PCI parity errors */
  20. static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
  21. static int edac_pci_poll_msec = 1000; /* one second workq period */
  22. static atomic_t pci_parity_count = ATOMIC_INIT(0);
  23. static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
  24. static struct kobject *edac_pci_top_main_kobj;
  25. static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
  26. /* getter functions for the data variables */
  27. int edac_pci_get_check_errors(void)
  28. {
  29. return check_pci_errors;
  30. }
  31. static int edac_pci_get_log_pe(void)
  32. {
  33. return edac_pci_log_pe;
  34. }
  35. static int edac_pci_get_log_npe(void)
  36. {
  37. return edac_pci_log_npe;
  38. }
  39. static int edac_pci_get_panic_on_pe(void)
  40. {
  41. return edac_pci_panic_on_pe;
  42. }
  43. int edac_pci_get_poll_msec(void)
  44. {
  45. return edac_pci_poll_msec;
  46. }
  47. /**************************** EDAC PCI sysfs instance *******************/
  48. static ssize_t instance_pe_count_show(struct edac_pci_ctl_info *pci, char *data)
  49. {
  50. return sprintf(data, "%u\n", atomic_read(&pci->counters.pe_count));
  51. }
  52. static ssize_t instance_npe_count_show(struct edac_pci_ctl_info *pci,
  53. char *data)
  54. {
  55. return sprintf(data, "%u\n", atomic_read(&pci->counters.npe_count));
  56. }
  57. #define to_instance(k) container_of(k, struct edac_pci_ctl_info, kobj)
  58. #define to_instance_attr(a) container_of(a, struct instance_attribute, attr)
  59. /* DEVICE instance kobject release() function */
  60. static void edac_pci_instance_release(struct kobject *kobj)
  61. {
  62. struct edac_pci_ctl_info *pci;
  63. edac_dbg(0, "\n");
  64. /* Form pointer to containing struct, the pci control struct */
  65. pci = to_instance(kobj);
  66. /* decrement reference count on top main kobj */
  67. kobject_put(edac_pci_top_main_kobj);
  68. kfree(pci); /* Free the control struct */
  69. }
  70. /* instance specific attribute structure */
  71. struct instance_attribute {
  72. struct attribute attr;
  73. ssize_t(*show) (struct edac_pci_ctl_info *, char *);
  74. ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t);
  75. };
  76. /* Function to 'show' fields from the edac_pci 'instance' structure */
  77. static ssize_t edac_pci_instance_show(struct kobject *kobj,
  78. struct attribute *attr, char *buffer)
  79. {
  80. struct edac_pci_ctl_info *pci = to_instance(kobj);
  81. struct instance_attribute *instance_attr = to_instance_attr(attr);
  82. if (instance_attr->show)
  83. return instance_attr->show(pci, buffer);
  84. return -EIO;
  85. }
  86. /* Function to 'store' fields into the edac_pci 'instance' structure */
  87. static ssize_t edac_pci_instance_store(struct kobject *kobj,
  88. struct attribute *attr,
  89. const char *buffer, size_t count)
  90. {
  91. struct edac_pci_ctl_info *pci = to_instance(kobj);
  92. struct instance_attribute *instance_attr = to_instance_attr(attr);
  93. if (instance_attr->store)
  94. return instance_attr->store(pci, buffer, count);
  95. return -EIO;
  96. }
  97. /* fs_ops table */
  98. static const struct sysfs_ops pci_instance_ops = {
  99. .show = edac_pci_instance_show,
  100. .store = edac_pci_instance_store
  101. };
  102. #define INSTANCE_ATTR(_name, _mode, _show, _store) \
  103. static struct instance_attribute attr_instance_##_name = { \
  104. .attr = {.name = __stringify(_name), .mode = _mode }, \
  105. .show = _show, \
  106. .store = _store, \
  107. };
  108. INSTANCE_ATTR(pe_count, S_IRUGO, instance_pe_count_show, NULL);
  109. INSTANCE_ATTR(npe_count, S_IRUGO, instance_npe_count_show, NULL);
  110. /* pci instance attributes */
  111. static struct instance_attribute *pci_instance_attr[] = {
  112. &attr_instance_pe_count,
  113. &attr_instance_npe_count,
  114. NULL
  115. };
  116. /* the ktype for a pci instance */
  117. static struct kobj_type ktype_pci_instance = {
  118. .release = edac_pci_instance_release,
  119. .sysfs_ops = &pci_instance_ops,
  120. .default_attrs = (struct attribute **)pci_instance_attr,
  121. };
  122. /*
  123. * edac_pci_create_instance_kobj
  124. *
  125. * construct one EDAC PCI instance's kobject for use
  126. */
  127. static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
  128. {
  129. struct kobject *main_kobj;
  130. int err;
  131. edac_dbg(0, "\n");
  132. /* First bump the ref count on the top main kobj, which will
  133. * track the number of PCI instances we have, and thus nest
  134. * properly on keeping the module loaded
  135. */
  136. main_kobj = kobject_get(edac_pci_top_main_kobj);
  137. if (!main_kobj) {
  138. err = -ENODEV;
  139. goto error_out;
  140. }
  141. /* And now register this new kobject under the main kobj */
  142. err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
  143. edac_pci_top_main_kobj, "pci%d", idx);
  144. if (err != 0) {
  145. edac_dbg(2, "failed to register instance pci%d\n", idx);
  146. kobject_put(edac_pci_top_main_kobj);
  147. goto error_out;
  148. }
  149. kobject_uevent(&pci->kobj, KOBJ_ADD);
  150. edac_dbg(1, "Register instance 'pci%d' kobject\n", idx);
  151. return 0;
  152. /* Error unwind statck */
  153. error_out:
  154. return err;
  155. }
  156. /*
  157. * edac_pci_unregister_sysfs_instance_kobj
  158. *
  159. * unregister the kobj for the EDAC PCI instance
  160. */
  161. static void edac_pci_unregister_sysfs_instance_kobj(
  162. struct edac_pci_ctl_info *pci)
  163. {
  164. edac_dbg(0, "\n");
  165. /* Unregister the instance kobject and allow its release
  166. * function release the main reference count and then
  167. * kfree the memory
  168. */
  169. kobject_put(&pci->kobj);
  170. }
  171. /***************************** EDAC PCI sysfs root **********************/
  172. #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
  173. #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
  174. /* simple show/store functions for attributes */
  175. static ssize_t edac_pci_int_show(void *ptr, char *buffer)
  176. {
  177. int *value = ptr;
  178. return sprintf(buffer, "%d\n", *value);
  179. }
  180. static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
  181. {
  182. int *value = ptr;
  183. if (isdigit(*buffer))
  184. *value = simple_strtoul(buffer, NULL, 0);
  185. return count;
  186. }
  187. struct edac_pci_dev_attribute {
  188. struct attribute attr;
  189. void *value;
  190. ssize_t(*show) (void *, char *);
  191. ssize_t(*store) (void *, const char *, size_t);
  192. };
  193. /* Set of show/store abstract level functions for PCI Parity object */
  194. static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
  195. char *buffer)
  196. {
  197. struct edac_pci_dev_attribute *edac_pci_dev;
  198. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  199. if (edac_pci_dev->show)
  200. return edac_pci_dev->show(edac_pci_dev->value, buffer);
  201. return -EIO;
  202. }
  203. static ssize_t edac_pci_dev_store(struct kobject *kobj,
  204. struct attribute *attr, const char *buffer,
  205. size_t count)
  206. {
  207. struct edac_pci_dev_attribute *edac_pci_dev;
  208. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  209. if (edac_pci_dev->store)
  210. return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
  211. return -EIO;
  212. }
  213. static const struct sysfs_ops edac_pci_sysfs_ops = {
  214. .show = edac_pci_dev_show,
  215. .store = edac_pci_dev_store
  216. };
  217. #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
  218. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  219. .attr = {.name = __stringify(_name), .mode = _mode }, \
  220. .value = &_name, \
  221. .show = _show, \
  222. .store = _store, \
  223. };
  224. #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \
  225. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  226. .attr = {.name = __stringify(_name), .mode = _mode }, \
  227. .value = _data, \
  228. .show = _show, \
  229. .store = _store, \
  230. };
  231. /* PCI Parity control files */
  232. EDAC_PCI_ATTR(check_pci_errors, S_IRUGO | S_IWUSR, edac_pci_int_show,
  233. edac_pci_int_store);
  234. EDAC_PCI_ATTR(edac_pci_log_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  235. edac_pci_int_store);
  236. EDAC_PCI_ATTR(edac_pci_log_npe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  237. edac_pci_int_store);
  238. EDAC_PCI_ATTR(edac_pci_panic_on_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  239. edac_pci_int_store);
  240. EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
  241. EDAC_PCI_ATTR(pci_nonparity_count, S_IRUGO, edac_pci_int_show, NULL);
  242. /* Base Attributes of the memory ECC object */
  243. static struct edac_pci_dev_attribute *edac_pci_attr[] = {
  244. &edac_pci_attr_check_pci_errors,
  245. &edac_pci_attr_edac_pci_log_pe,
  246. &edac_pci_attr_edac_pci_log_npe,
  247. &edac_pci_attr_edac_pci_panic_on_pe,
  248. &edac_pci_attr_pci_parity_count,
  249. &edac_pci_attr_pci_nonparity_count,
  250. NULL,
  251. };
  252. /*
  253. * edac_pci_release_main_kobj
  254. *
  255. * This release function is called when the reference count to the
  256. * passed kobj goes to zero.
  257. *
  258. * This kobj is the 'main' kobject that EDAC PCI instances
  259. * link to, and thus provide for proper nesting counts
  260. */
  261. static void edac_pci_release_main_kobj(struct kobject *kobj)
  262. {
  263. edac_dbg(0, "here to module_put(THIS_MODULE)\n");
  264. kfree(kobj);
  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: Setup the sysfs for EDAC PCI attributes.
  278. */
  279. static int edac_pci_main_kobj_setup(void)
  280. {
  281. int err;
  282. struct bus_type *edac_subsys;
  283. edac_dbg(0, "\n");
  284. /* check and count if we have already created the main kobject */
  285. if (atomic_inc_return(&edac_pci_sysfs_refcount) != 1)
  286. return 0;
  287. /* First time, so create the main kobject and its
  288. * controls and attributes
  289. */
  290. edac_subsys = edac_get_sysfs_subsys();
  291. /* Bump the reference count on this module to ensure the
  292. * modules isn't unloaded until we deconstruct the top
  293. * level main kobj for EDAC PCI
  294. */
  295. if (!try_module_get(THIS_MODULE)) {
  296. edac_dbg(1, "try_module_get() failed\n");
  297. err = -ENODEV;
  298. goto decrement_count_fail;
  299. }
  300. edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
  301. if (!edac_pci_top_main_kobj) {
  302. edac_dbg(1, "Failed to allocate\n");
  303. err = -ENOMEM;
  304. goto kzalloc_fail;
  305. }
  306. /* Instanstiate the pci object */
  307. err = kobject_init_and_add(edac_pci_top_main_kobj,
  308. &ktype_edac_pci_main_kobj,
  309. &edac_subsys->dev_root->kobj, "pci");
  310. if (err) {
  311. edac_dbg(1, "Failed to register '.../edac/pci'\n");
  312. goto kobject_init_and_add_fail;
  313. }
  314. /* At this point, to 'release' the top level kobject
  315. * for EDAC PCI, then edac_pci_main_kobj_teardown()
  316. * must be used, for resources to be cleaned up properly
  317. */
  318. kobject_uevent(edac_pci_top_main_kobj, KOBJ_ADD);
  319. edac_dbg(1, "Registered '.../edac/pci' kobject\n");
  320. return 0;
  321. /* Error unwind statck */
  322. kobject_init_and_add_fail:
  323. kfree(edac_pci_top_main_kobj);
  324. kzalloc_fail:
  325. module_put(THIS_MODULE);
  326. decrement_count_fail:
  327. /* if are on this error exit, nothing to tear down */
  328. atomic_dec(&edac_pci_sysfs_refcount);
  329. return err;
  330. }
  331. /*
  332. * edac_pci_main_kobj_teardown()
  333. *
  334. * if no longer linked (needed) remove the top level EDAC PCI
  335. * kobject with its controls and attributes
  336. */
  337. static void edac_pci_main_kobj_teardown(void)
  338. {
  339. edac_dbg(0, "\n");
  340. /* Decrement the count and only if no more controller instances
  341. * are connected perform the unregisteration of the top level
  342. * main kobj
  343. */
  344. if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
  345. edac_dbg(0, "called kobject_put on main kobj\n");
  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. edac_dbg(0, "idx=%d\n", 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. edac_dbg(0, "sysfs_create_link() returned err= %d\n", err);
  371. goto symlink_fail;
  372. }
  373. return 0;
  374. /* Error unwind stack */
  375. symlink_fail:
  376. edac_pci_unregister_sysfs_instance_kobj(pci);
  377. unregister_cleanup:
  378. edac_pci_main_kobj_teardown();
  379. return err;
  380. }
  381. /*
  382. * edac_pci_remove_sysfs
  383. *
  384. * remove the controls and attributes for this EDAC PCI device
  385. */
  386. void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci)
  387. {
  388. edac_dbg(0, "index=%d\n", pci->pci_idx);
  389. /* Remove the symlink */
  390. sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK);
  391. /* remove this PCI instance's sysfs entries */
  392. edac_pci_unregister_sysfs_instance_kobj(pci);
  393. /* Call the main unregister function, which will determine
  394. * if this 'pci' is the last instance.
  395. * If it is, the main kobject will be unregistered as a result
  396. */
  397. edac_dbg(0, "calling edac_pci_main_kobj_teardown()\n");
  398. edac_pci_main_kobj_teardown();
  399. }
  400. /************************ PCI error handling *************************/
  401. static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
  402. {
  403. int where;
  404. u16 status;
  405. where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
  406. pci_read_config_word(dev, where, &status);
  407. /* If we get back 0xFFFF then we must suspect that the card has been
  408. * pulled but the Linux PCI layer has not yet finished cleaning up.
  409. * We don't want to report on such devices
  410. */
  411. if (status == 0xFFFF) {
  412. u32 sanity;
  413. pci_read_config_dword(dev, 0, &sanity);
  414. if (sanity == 0xFFFFFFFF)
  415. return 0;
  416. }
  417. status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
  418. PCI_STATUS_PARITY;
  419. if (status)
  420. /* reset only the bits we are interested in */
  421. pci_write_config_word(dev, where, status);
  422. return status;
  423. }
  424. /* Clear any PCI parity errors logged by this device. */
  425. static void edac_pci_dev_parity_clear(struct pci_dev *dev)
  426. {
  427. u8 header_type;
  428. get_pci_parity_status(dev, 0);
  429. /* read the device TYPE, looking for bridges */
  430. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  431. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE)
  432. get_pci_parity_status(dev, 1);
  433. }
  434. /*
  435. * PCI Parity polling
  436. *
  437. * Function to retrieve the current parity status
  438. * and decode it
  439. *
  440. */
  441. static void edac_pci_dev_parity_test(struct pci_dev *dev)
  442. {
  443. unsigned long flags;
  444. u16 status;
  445. u8 header_type;
  446. /* stop any interrupts until we can acquire the status */
  447. local_irq_save(flags);
  448. /* read the STATUS register on this device */
  449. status = get_pci_parity_status(dev, 0);
  450. /* read the device TYPE, looking for bridges */
  451. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  452. local_irq_restore(flags);
  453. edac_dbg(4, "PCI STATUS= 0x%04x %s\n", status, dev_name(&dev->dev));
  454. /* check the status reg for errors on boards NOT marked as broken
  455. * if broken, we cannot trust any of the status bits
  456. */
  457. if (status && !dev->broken_parity_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. edac_dbg(4, "PCI HEADER TYPE= 0x%02x %s\n",
  478. header_type, dev_name(&dev->dev));
  479. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  480. /* On bridges, need to examine secondary status register */
  481. status = get_pci_parity_status(dev, 1);
  482. edac_dbg(4, "PCI SEC_STATUS= 0x%04x %s\n",
  483. status, dev_name(&dev->dev));
  484. /* check the secondary status reg for errors,
  485. * on NOT broken boards
  486. */
  487. if (status && !dev->broken_parity_status) {
  488. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
  489. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  490. "Signaled System Error on %s\n",
  491. pci_name(dev));
  492. atomic_inc(&pci_nonparity_count);
  493. }
  494. if (status & (PCI_STATUS_PARITY)) {
  495. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  496. "Master Data Parity Error on "
  497. "%s\n", pci_name(dev));
  498. atomic_inc(&pci_parity_count);
  499. }
  500. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  501. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  502. "Detected Parity Error on %s\n",
  503. pci_name(dev));
  504. atomic_inc(&pci_parity_count);
  505. }
  506. }
  507. }
  508. }
  509. /* reduce some complexity in definition of the iterator */
  510. typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
  511. /*
  512. * pci_dev parity list iterator
  513. *
  514. * Scan the PCI device list looking for SERRORs, Master Parity ERRORS or
  515. * Parity ERRORs on primary or secondary devices.
  516. */
  517. static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
  518. {
  519. struct pci_dev *dev = NULL;
  520. for_each_pci_dev(dev)
  521. fn(dev);
  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. edac_dbg(3, "\n");
  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");