edac_pci_sysfs.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. static int edac_pci_get_log_pe(void)
  33. {
  34. return edac_pci_log_pe;
  35. }
  36. static int edac_pci_get_log_npe(void)
  37. {
  38. return edac_pci_log_npe;
  39. }
  40. static 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. static void edac_pci_unregister_sysfs_instance_kobj(
  164. struct edac_pci_ctl_info *pci)
  165. {
  166. debugf0("%s()\n", __func__);
  167. /* Unregister the instance kobject and allow its release
  168. * function release the main reference count and then
  169. * kfree the memory
  170. */
  171. kobject_put(&pci->kobj);
  172. }
  173. /***************************** EDAC PCI sysfs root **********************/
  174. #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
  175. #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
  176. /* simple show/store functions for attributes */
  177. static ssize_t edac_pci_int_show(void *ptr, char *buffer)
  178. {
  179. int *value = ptr;
  180. return sprintf(buffer, "%d\n", *value);
  181. }
  182. static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
  183. {
  184. int *value = ptr;
  185. if (isdigit(*buffer))
  186. *value = simple_strtoul(buffer, NULL, 0);
  187. return count;
  188. }
  189. struct edac_pci_dev_attribute {
  190. struct attribute attr;
  191. void *value;
  192. ssize_t(*show) (void *, char *);
  193. ssize_t(*store) (void *, const char *, size_t);
  194. };
  195. /* Set of show/store abstract level functions for PCI Parity object */
  196. static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
  197. char *buffer)
  198. {
  199. struct edac_pci_dev_attribute *edac_pci_dev;
  200. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  201. if (edac_pci_dev->show)
  202. return edac_pci_dev->show(edac_pci_dev->value, buffer);
  203. return -EIO;
  204. }
  205. static ssize_t edac_pci_dev_store(struct kobject *kobj,
  206. struct attribute *attr, const char *buffer,
  207. size_t count)
  208. {
  209. struct edac_pci_dev_attribute *edac_pci_dev;
  210. edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
  211. if (edac_pci_dev->show)
  212. return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
  213. return -EIO;
  214. }
  215. static struct sysfs_ops edac_pci_sysfs_ops = {
  216. .show = edac_pci_dev_show,
  217. .store = edac_pci_dev_store
  218. };
  219. #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
  220. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  221. .attr = {.name = __stringify(_name), .mode = _mode }, \
  222. .value = &_name, \
  223. .show = _show, \
  224. .store = _store, \
  225. };
  226. #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \
  227. static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  228. .attr = {.name = __stringify(_name), .mode = _mode }, \
  229. .value = _data, \
  230. .show = _show, \
  231. .store = _store, \
  232. };
  233. /* PCI Parity control files */
  234. EDAC_PCI_ATTR(check_pci_errors, S_IRUGO | S_IWUSR, edac_pci_int_show,
  235. edac_pci_int_store);
  236. EDAC_PCI_ATTR(edac_pci_log_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  237. edac_pci_int_store);
  238. EDAC_PCI_ATTR(edac_pci_log_npe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  239. edac_pci_int_store);
  240. EDAC_PCI_ATTR(edac_pci_panic_on_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
  241. edac_pci_int_store);
  242. EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
  243. EDAC_PCI_ATTR(pci_nonparity_count, S_IRUGO, edac_pci_int_show, NULL);
  244. /* Base Attributes of the memory ECC object */
  245. static struct edac_pci_dev_attribute *edac_pci_attr[] = {
  246. &edac_pci_attr_check_pci_errors,
  247. &edac_pci_attr_edac_pci_log_pe,
  248. &edac_pci_attr_edac_pci_log_npe,
  249. &edac_pci_attr_edac_pci_panic_on_pe,
  250. &edac_pci_attr_pci_parity_count,
  251. &edac_pci_attr_pci_nonparity_count,
  252. NULL,
  253. };
  254. /*
  255. * edac_pci_release_main_kobj
  256. *
  257. * This release function is called when the reference count to the
  258. * passed kobj goes to zero.
  259. *
  260. * This kobj is the 'main' kobject that EDAC PCI instances
  261. * link to, and thus provide for proper nesting counts
  262. */
  263. static void edac_pci_release_main_kobj(struct kobject *kobj)
  264. {
  265. debugf0("%s() here to module_put(THIS_MODULE)\n", __func__);
  266. kfree(kobj);
  267. /* last reference to top EDAC PCI kobject has been removed,
  268. * NOW release our ref count on the core module
  269. */
  270. module_put(THIS_MODULE);
  271. }
  272. /* ktype struct for the EDAC PCI main kobj */
  273. static struct kobj_type ktype_edac_pci_main_kobj = {
  274. .release = edac_pci_release_main_kobj,
  275. .sysfs_ops = &edac_pci_sysfs_ops,
  276. .default_attrs = (struct attribute **)edac_pci_attr,
  277. };
  278. /**
  279. * edac_pci_main_kobj_setup()
  280. *
  281. * setup the sysfs for EDAC PCI attributes
  282. * assumes edac_class has already been initialized
  283. */
  284. static int edac_pci_main_kobj_setup(void)
  285. {
  286. int err;
  287. struct sysdev_class *edac_class;
  288. debugf0("%s()\n", __func__);
  289. /* check and count if we have already created the main kobject */
  290. if (atomic_inc_return(&edac_pci_sysfs_refcount) != 1)
  291. return 0;
  292. /* First time, so create the main kobject and its
  293. * controls and atributes
  294. */
  295. edac_class = edac_get_edac_class();
  296. if (edac_class == NULL) {
  297. debugf1("%s() no edac_class\n", __func__);
  298. err = -ENODEV;
  299. goto decrement_count_fail;
  300. }
  301. /* Bump the reference count on this module to ensure the
  302. * modules isn't unloaded until we deconstruct the top
  303. * level main kobj for EDAC PCI
  304. */
  305. if (!try_module_get(THIS_MODULE)) {
  306. debugf1("%s() try_module_get() failed\n", __func__);
  307. err = -ENODEV;
  308. goto decrement_count_fail;
  309. }
  310. edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
  311. if (!edac_pci_top_main_kobj) {
  312. debugf1("Failed to allocate\n");
  313. err = -ENOMEM;
  314. goto kzalloc_fail;
  315. }
  316. /* Instanstiate the pci object */
  317. err = kobject_init_and_add(edac_pci_top_main_kobj,
  318. &ktype_edac_pci_main_kobj,
  319. &edac_class->kset.kobj, "pci");
  320. if (err) {
  321. debugf1("Failed to register '.../edac/pci'\n");
  322. goto kobject_init_and_add_fail;
  323. }
  324. /* At this point, to 'release' the top level kobject
  325. * for EDAC PCI, then edac_pci_main_kobj_teardown()
  326. * must be used, for resources to be cleaned up properly
  327. */
  328. kobject_uevent(edac_pci_top_main_kobj, KOBJ_ADD);
  329. debugf1("Registered '.../edac/pci' kobject\n");
  330. return 0;
  331. /* Error unwind statck */
  332. kobject_init_and_add_fail:
  333. kfree(edac_pci_top_main_kobj);
  334. kzalloc_fail:
  335. module_put(THIS_MODULE);
  336. decrement_count_fail:
  337. /* if are on this error exit, nothing to tear down */
  338. atomic_dec(&edac_pci_sysfs_refcount);
  339. return err;
  340. }
  341. /*
  342. * edac_pci_main_kobj_teardown()
  343. *
  344. * if no longer linked (needed) remove the top level EDAC PCI
  345. * kobject with its controls and attributes
  346. */
  347. static void edac_pci_main_kobj_teardown(void)
  348. {
  349. debugf0("%s()\n", __func__);
  350. /* Decrement the count and only if no more controller instances
  351. * are connected perform the unregisteration of the top level
  352. * main kobj
  353. */
  354. if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
  355. debugf0("%s() called kobject_put on main kobj\n",
  356. __func__);
  357. kobject_put(edac_pci_top_main_kobj);
  358. }
  359. }
  360. /*
  361. *
  362. * edac_pci_create_sysfs
  363. *
  364. * Create the controls/attributes for the specified EDAC PCI device
  365. */
  366. int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci)
  367. {
  368. int err;
  369. struct kobject *edac_kobj = &pci->kobj;
  370. debugf0("%s() idx=%d\n", __func__, pci->pci_idx);
  371. /* create the top main EDAC PCI kobject, IF needed */
  372. err = edac_pci_main_kobj_setup();
  373. if (err)
  374. return err;
  375. /* Create this instance's kobject under the MAIN kobject */
  376. err = edac_pci_create_instance_kobj(pci, pci->pci_idx);
  377. if (err)
  378. goto unregister_cleanup;
  379. err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK);
  380. if (err) {
  381. debugf0("%s() sysfs_create_link() returned err= %d\n",
  382. __func__, err);
  383. goto symlink_fail;
  384. }
  385. return 0;
  386. /* Error unwind stack */
  387. symlink_fail:
  388. edac_pci_unregister_sysfs_instance_kobj(pci);
  389. unregister_cleanup:
  390. edac_pci_main_kobj_teardown();
  391. return err;
  392. }
  393. /*
  394. * edac_pci_remove_sysfs
  395. *
  396. * remove the controls and attributes for this EDAC PCI device
  397. */
  398. void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci)
  399. {
  400. debugf0("%s() index=%d\n", __func__, pci->pci_idx);
  401. /* Remove the symlink */
  402. sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK);
  403. /* remove this PCI instance's sysfs entries */
  404. edac_pci_unregister_sysfs_instance_kobj(pci);
  405. /* Call the main unregister function, which will determine
  406. * if this 'pci' is the last instance.
  407. * If it is, the main kobject will be unregistered as a result
  408. */
  409. debugf0("%s() calling edac_pci_main_kobj_teardown()\n", __func__);
  410. edac_pci_main_kobj_teardown();
  411. }
  412. /************************ PCI error handling *************************/
  413. static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
  414. {
  415. int where;
  416. u16 status;
  417. where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
  418. pci_read_config_word(dev, where, &status);
  419. /* If we get back 0xFFFF then we must suspect that the card has been
  420. * pulled but the Linux PCI layer has not yet finished cleaning up.
  421. * We don't want to report on such devices
  422. */
  423. if (status == 0xFFFF) {
  424. u32 sanity;
  425. pci_read_config_dword(dev, 0, &sanity);
  426. if (sanity == 0xFFFFFFFF)
  427. return 0;
  428. }
  429. status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
  430. PCI_STATUS_PARITY;
  431. if (status)
  432. /* reset only the bits we are interested in */
  433. pci_write_config_word(dev, where, status);
  434. return status;
  435. }
  436. /* Clear any PCI parity errors logged by this device. */
  437. static void edac_pci_dev_parity_clear(struct pci_dev *dev)
  438. {
  439. u8 header_type;
  440. debugf0("%s()\n", __func__);
  441. get_pci_parity_status(dev, 0);
  442. /* read the device TYPE, looking for bridges */
  443. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  444. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE)
  445. get_pci_parity_status(dev, 1);
  446. }
  447. /*
  448. * PCI Parity polling
  449. *
  450. * Fucntion to retrieve the current parity status
  451. * and decode it
  452. *
  453. */
  454. static void edac_pci_dev_parity_test(struct pci_dev *dev)
  455. {
  456. unsigned long flags;
  457. u16 status;
  458. u8 header_type;
  459. /* stop any interrupts until we can acquire the status */
  460. local_irq_save(flags);
  461. /* read the STATUS register on this device */
  462. status = get_pci_parity_status(dev, 0);
  463. /* read the device TYPE, looking for bridges */
  464. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  465. local_irq_restore(flags);
  466. debugf4("PCI STATUS= 0x%04x %s\n", status, dev_name(&dev->dev));
  467. /* check the status reg for errors on boards NOT marked as broken
  468. * if broken, we cannot trust any of the status bits
  469. */
  470. if (status && !dev->broken_parity_status) {
  471. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
  472. edac_printk(KERN_CRIT, EDAC_PCI,
  473. "Signaled System Error on %s\n",
  474. pci_name(dev));
  475. atomic_inc(&pci_nonparity_count);
  476. }
  477. if (status & (PCI_STATUS_PARITY)) {
  478. edac_printk(KERN_CRIT, EDAC_PCI,
  479. "Master Data Parity Error on %s\n",
  480. pci_name(dev));
  481. atomic_inc(&pci_parity_count);
  482. }
  483. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  484. edac_printk(KERN_CRIT, EDAC_PCI,
  485. "Detected Parity Error on %s\n",
  486. pci_name(dev));
  487. atomic_inc(&pci_parity_count);
  488. }
  489. }
  490. debugf4("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev_name(&dev->dev));
  491. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  492. /* On bridges, need to examine secondary status register */
  493. status = get_pci_parity_status(dev, 1);
  494. debugf4("PCI SEC_STATUS= 0x%04x %s\n", status, dev_name(&dev->dev));
  495. /* check the secondary status reg for errors,
  496. * on NOT broken boards
  497. */
  498. if (status && !dev->broken_parity_status) {
  499. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
  500. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  501. "Signaled System Error on %s\n",
  502. pci_name(dev));
  503. atomic_inc(&pci_nonparity_count);
  504. }
  505. if (status & (PCI_STATUS_PARITY)) {
  506. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  507. "Master Data Parity Error on "
  508. "%s\n", pci_name(dev));
  509. atomic_inc(&pci_parity_count);
  510. }
  511. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  512. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  513. "Detected Parity Error on %s\n",
  514. pci_name(dev));
  515. atomic_inc(&pci_parity_count);
  516. }
  517. }
  518. }
  519. }
  520. /* reduce some complexity in definition of the iterator */
  521. typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
  522. /*
  523. * pci_dev parity list iterator
  524. * Scan the PCI device list for one pass, looking for SERRORs
  525. * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
  526. */
  527. static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
  528. {
  529. struct pci_dev *dev = NULL;
  530. /* request for kernel access to the next PCI device, if any,
  531. * and while we are looking at it have its reference count
  532. * bumped until we are done with it
  533. */
  534. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  535. fn(dev);
  536. }
  537. }
  538. /*
  539. * edac_pci_do_parity_check
  540. *
  541. * performs the actual PCI parity check operation
  542. */
  543. void edac_pci_do_parity_check(void)
  544. {
  545. int before_count;
  546. debugf3("%s()\n", __func__);
  547. /* if policy has PCI check off, leave now */
  548. if (!check_pci_errors)
  549. return;
  550. before_count = atomic_read(&pci_parity_count);
  551. /* scan all PCI devices looking for a Parity Error on devices and
  552. * bridges.
  553. * The iterator calls pci_get_device() which might sleep, thus
  554. * we cannot disable interrupts in this scan.
  555. */
  556. edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
  557. /* Only if operator has selected panic on PCI Error */
  558. if (edac_pci_get_panic_on_pe()) {
  559. /* If the count is different 'after' from 'before' */
  560. if (before_count != atomic_read(&pci_parity_count))
  561. panic("EDAC: PCI Parity Error");
  562. }
  563. }
  564. /*
  565. * edac_pci_clear_parity_errors
  566. *
  567. * function to perform an iteration over the PCI devices
  568. * and clearn their current status
  569. */
  570. void edac_pci_clear_parity_errors(void)
  571. {
  572. /* Clear any PCI bus parity errors that devices initially have logged
  573. * in their registers.
  574. */
  575. edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
  576. }
  577. /*
  578. * edac_pci_handle_pe
  579. *
  580. * Called to handle a PARITY ERROR event
  581. */
  582. void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg)
  583. {
  584. /* global PE counter incremented by edac_pci_do_parity_check() */
  585. atomic_inc(&pci->counters.pe_count);
  586. if (edac_pci_get_log_pe())
  587. edac_pci_printk(pci, KERN_WARNING,
  588. "Parity Error ctl: %s %d: %s\n",
  589. pci->ctl_name, pci->pci_idx, msg);
  590. /*
  591. * poke all PCI devices and see which one is the troublemaker
  592. * panic() is called if set
  593. */
  594. edac_pci_do_parity_check();
  595. }
  596. EXPORT_SYMBOL_GPL(edac_pci_handle_pe);
  597. /*
  598. * edac_pci_handle_npe
  599. *
  600. * Called to handle a NON-PARITY ERROR event
  601. */
  602. void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg)
  603. {
  604. /* global NPE counter incremented by edac_pci_do_parity_check() */
  605. atomic_inc(&pci->counters.npe_count);
  606. if (edac_pci_get_log_npe())
  607. edac_pci_printk(pci, KERN_WARNING,
  608. "Non-Parity Error ctl: %s %d: %s\n",
  609. pci->ctl_name, pci->pci_idx, msg);
  610. /*
  611. * poke all PCI devices and see which one is the troublemaker
  612. * panic() is called if set
  613. */
  614. edac_pci_do_parity_check();
  615. }
  616. EXPORT_SYMBOL_GPL(edac_pci_handle_npe);
  617. /*
  618. * Define the PCI parameter to the module
  619. */
  620. module_param(check_pci_errors, int, 0644);
  621. MODULE_PARM_DESC(check_pci_errors,
  622. "Check for PCI bus parity errors: 0=off 1=on");
  623. module_param(edac_pci_panic_on_pe, int, 0644);
  624. MODULE_PARM_DESC(edac_pci_panic_on_pe,
  625. "Panic on PCI Bus Parity error: 0=off 1=on");
  626. #endif /* CONFIG_PCI */