Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * (C) 2005, 2006 Linux Networx (http://lnxi.com)
0003  * This file may be distributed under the terms of the
0004  * GNU General Public License.
0005  *
0006  * Written Doug Thompson <norsk5@xmission.com>
0007  *
0008  */
0009 #include <linux/module.h>
0010 #include <linux/edac.h>
0011 #include <linux/slab.h>
0012 #include <linux/ctype.h>
0013 
0014 #include "edac_pci.h"
0015 #include "edac_module.h"
0016 
0017 #define EDAC_PCI_SYMLINK    "device"
0018 
0019 /* data variables exported via sysfs */
0020 static int check_pci_errors;        /* default NO check PCI parity */
0021 static int edac_pci_panic_on_pe;    /* default NO panic on PCI Parity */
0022 static int edac_pci_log_pe = 1;     /* log PCI parity errors */
0023 static int edac_pci_log_npe = 1;    /* log PCI non-parity error errors */
0024 static int edac_pci_poll_msec = 1000;   /* one second workq period */
0025 
0026 static atomic_t pci_parity_count = ATOMIC_INIT(0);
0027 static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
0028 
0029 static struct kobject *edac_pci_top_main_kobj;
0030 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
0031 
0032 /* getter functions for the data variables */
0033 int edac_pci_get_check_errors(void)
0034 {
0035     return check_pci_errors;
0036 }
0037 
0038 static int edac_pci_get_log_pe(void)
0039 {
0040     return edac_pci_log_pe;
0041 }
0042 
0043 static int edac_pci_get_log_npe(void)
0044 {
0045     return edac_pci_log_npe;
0046 }
0047 
0048 static int edac_pci_get_panic_on_pe(void)
0049 {
0050     return edac_pci_panic_on_pe;
0051 }
0052 
0053 int edac_pci_get_poll_msec(void)
0054 {
0055     return edac_pci_poll_msec;
0056 }
0057 
0058 /**************************** EDAC PCI sysfs instance *******************/
0059 static ssize_t instance_pe_count_show(struct edac_pci_ctl_info *pci, char *data)
0060 {
0061     return sprintf(data, "%u\n", atomic_read(&pci->counters.pe_count));
0062 }
0063 
0064 static ssize_t instance_npe_count_show(struct edac_pci_ctl_info *pci,
0065                 char *data)
0066 {
0067     return sprintf(data, "%u\n", atomic_read(&pci->counters.npe_count));
0068 }
0069 
0070 #define to_instance(k) container_of(k, struct edac_pci_ctl_info, kobj)
0071 #define to_instance_attr(a) container_of(a, struct instance_attribute, attr)
0072 
0073 /* DEVICE instance kobject release() function */
0074 static void edac_pci_instance_release(struct kobject *kobj)
0075 {
0076     struct edac_pci_ctl_info *pci;
0077 
0078     edac_dbg(0, "\n");
0079 
0080     /* Form pointer to containing struct, the pci control struct */
0081     pci = to_instance(kobj);
0082 
0083     /* decrement reference count on top main kobj */
0084     kobject_put(edac_pci_top_main_kobj);
0085 
0086     kfree(pci); /* Free the control struct */
0087 }
0088 
0089 /* instance specific attribute structure */
0090 struct instance_attribute {
0091     struct attribute attr;
0092     ssize_t(*show) (struct edac_pci_ctl_info *, char *);
0093     ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t);
0094 };
0095 
0096 /* Function to 'show' fields from the edac_pci 'instance' structure */
0097 static ssize_t edac_pci_instance_show(struct kobject *kobj,
0098                 struct attribute *attr, char *buffer)
0099 {
0100     struct edac_pci_ctl_info *pci = to_instance(kobj);
0101     struct instance_attribute *instance_attr = to_instance_attr(attr);
0102 
0103     if (instance_attr->show)
0104         return instance_attr->show(pci, buffer);
0105     return -EIO;
0106 }
0107 
0108 /* Function to 'store' fields into the edac_pci 'instance' structure */
0109 static ssize_t edac_pci_instance_store(struct kobject *kobj,
0110                 struct attribute *attr,
0111                 const char *buffer, size_t count)
0112 {
0113     struct edac_pci_ctl_info *pci = to_instance(kobj);
0114     struct instance_attribute *instance_attr = to_instance_attr(attr);
0115 
0116     if (instance_attr->store)
0117         return instance_attr->store(pci, buffer, count);
0118     return -EIO;
0119 }
0120 
0121 /* fs_ops table */
0122 static const struct sysfs_ops pci_instance_ops = {
0123     .show = edac_pci_instance_show,
0124     .store = edac_pci_instance_store
0125 };
0126 
0127 #define INSTANCE_ATTR(_name, _mode, _show, _store)  \
0128 static struct instance_attribute attr_instance_##_name = {  \
0129     .attr   = {.name = __stringify(_name), .mode = _mode }, \
0130     .show   = _show,                    \
0131     .store  = _store,                   \
0132 };
0133 
0134 INSTANCE_ATTR(pe_count, S_IRUGO, instance_pe_count_show, NULL);
0135 INSTANCE_ATTR(npe_count, S_IRUGO, instance_npe_count_show, NULL);
0136 
0137 /* pci instance attributes */
0138 static struct attribute *pci_instance_attrs[] = {
0139     &attr_instance_pe_count.attr,
0140     &attr_instance_npe_count.attr,
0141     NULL
0142 };
0143 ATTRIBUTE_GROUPS(pci_instance);
0144 
0145 /* the ktype for a pci instance */
0146 static struct kobj_type ktype_pci_instance = {
0147     .release = edac_pci_instance_release,
0148     .sysfs_ops = &pci_instance_ops,
0149     .default_groups = pci_instance_groups,
0150 };
0151 
0152 /*
0153  * edac_pci_create_instance_kobj
0154  *
0155  *  construct one EDAC PCI instance's kobject for use
0156  */
0157 static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
0158 {
0159     struct kobject *main_kobj;
0160     int err;
0161 
0162     edac_dbg(0, "\n");
0163 
0164     /* First bump the ref count on the top main kobj, which will
0165      * track the number of PCI instances we have, and thus nest
0166      * properly on keeping the module loaded
0167      */
0168     main_kobj = kobject_get(edac_pci_top_main_kobj);
0169     if (!main_kobj) {
0170         err = -ENODEV;
0171         goto error_out;
0172     }
0173 
0174     /* And now register this new kobject under the main kobj */
0175     err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
0176                    edac_pci_top_main_kobj, "pci%d", idx);
0177     if (err != 0) {
0178         edac_dbg(2, "failed to register instance pci%d\n", idx);
0179         kobject_put(edac_pci_top_main_kobj);
0180         goto error_out;
0181     }
0182 
0183     kobject_uevent(&pci->kobj, KOBJ_ADD);
0184     edac_dbg(1, "Register instance 'pci%d' kobject\n", idx);
0185 
0186     return 0;
0187 
0188     /* Error unwind statck */
0189 error_out:
0190     return err;
0191 }
0192 
0193 /*
0194  * edac_pci_unregister_sysfs_instance_kobj
0195  *
0196  *  unregister the kobj for the EDAC PCI instance
0197  */
0198 static void edac_pci_unregister_sysfs_instance_kobj(
0199             struct edac_pci_ctl_info *pci)
0200 {
0201     edac_dbg(0, "\n");
0202 
0203     /* Unregister the instance kobject and allow its release
0204      * function release the main reference count and then
0205      * kfree the memory
0206      */
0207     kobject_put(&pci->kobj);
0208 }
0209 
0210 /***************************** EDAC PCI sysfs root **********************/
0211 #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
0212 #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
0213 
0214 /* simple show/store functions for attributes */
0215 static ssize_t edac_pci_int_show(void *ptr, char *buffer)
0216 {
0217     int *value = ptr;
0218     return sprintf(buffer, "%d\n", *value);
0219 }
0220 
0221 static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
0222 {
0223     int *value = ptr;
0224 
0225     if (isdigit(*buffer))
0226         *value = simple_strtoul(buffer, NULL, 0);
0227 
0228     return count;
0229 }
0230 
0231 struct edac_pci_dev_attribute {
0232     struct attribute attr;
0233     void *value;
0234      ssize_t(*show) (void *, char *);
0235      ssize_t(*store) (void *, const char *, size_t);
0236 };
0237 
0238 /* Set of show/store abstract level functions for PCI Parity object */
0239 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
0240                  char *buffer)
0241 {
0242     struct edac_pci_dev_attribute *edac_pci_dev;
0243     edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
0244 
0245     if (edac_pci_dev->show)
0246         return edac_pci_dev->show(edac_pci_dev->value, buffer);
0247     return -EIO;
0248 }
0249 
0250 static ssize_t edac_pci_dev_store(struct kobject *kobj,
0251                 struct attribute *attr, const char *buffer,
0252                 size_t count)
0253 {
0254     struct edac_pci_dev_attribute *edac_pci_dev;
0255     edac_pci_dev = (struct edac_pci_dev_attribute *)attr;
0256 
0257     if (edac_pci_dev->store)
0258         return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
0259     return -EIO;
0260 }
0261 
0262 static const struct sysfs_ops edac_pci_sysfs_ops = {
0263     .show = edac_pci_dev_show,
0264     .store = edac_pci_dev_store
0265 };
0266 
0267 #define EDAC_PCI_ATTR(_name,_mode,_show,_store)         \
0268 static struct edac_pci_dev_attribute edac_pci_attr_##_name = {      \
0269     .attr = {.name = __stringify(_name), .mode = _mode },   \
0270     .value  = &_name,                   \
0271     .show   = _show,                    \
0272     .store  = _store,                   \
0273 };
0274 
0275 #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store)    \
0276 static struct edac_pci_dev_attribute edac_pci_attr_##_name = {      \
0277     .attr = {.name = __stringify(_name), .mode = _mode },   \
0278     .value  = _data,                    \
0279     .show   = _show,                    \
0280     .store  = _store,                   \
0281 };
0282 
0283 /* PCI Parity control files */
0284 EDAC_PCI_ATTR(check_pci_errors, S_IRUGO | S_IWUSR, edac_pci_int_show,
0285     edac_pci_int_store);
0286 EDAC_PCI_ATTR(edac_pci_log_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
0287     edac_pci_int_store);
0288 EDAC_PCI_ATTR(edac_pci_log_npe, S_IRUGO | S_IWUSR, edac_pci_int_show,
0289     edac_pci_int_store);
0290 EDAC_PCI_ATTR(edac_pci_panic_on_pe, S_IRUGO | S_IWUSR, edac_pci_int_show,
0291     edac_pci_int_store);
0292 EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
0293 EDAC_PCI_ATTR(pci_nonparity_count, S_IRUGO, edac_pci_int_show, NULL);
0294 
0295 /* Base Attributes of the memory ECC object */
0296 static struct attribute *edac_pci_attrs[] = {
0297     &edac_pci_attr_check_pci_errors.attr,
0298     &edac_pci_attr_edac_pci_log_pe.attr,
0299     &edac_pci_attr_edac_pci_log_npe.attr,
0300     &edac_pci_attr_edac_pci_panic_on_pe.attr,
0301     &edac_pci_attr_pci_parity_count.attr,
0302     &edac_pci_attr_pci_nonparity_count.attr,
0303     NULL,
0304 };
0305 ATTRIBUTE_GROUPS(edac_pci);
0306 
0307 /*
0308  * edac_pci_release_main_kobj
0309  *
0310  *  This release function is called when the reference count to the
0311  *  passed kobj goes to zero.
0312  *
0313  *  This kobj is the 'main' kobject that EDAC PCI instances
0314  *  link to, and thus provide for proper nesting counts
0315  */
0316 static void edac_pci_release_main_kobj(struct kobject *kobj)
0317 {
0318     edac_dbg(0, "here to module_put(THIS_MODULE)\n");
0319 
0320     kfree(kobj);
0321 
0322     /* last reference to top EDAC PCI kobject has been removed,
0323      * NOW release our ref count on the core module
0324      */
0325     module_put(THIS_MODULE);
0326 }
0327 
0328 /* ktype struct for the EDAC PCI main kobj */
0329 static struct kobj_type ktype_edac_pci_main_kobj = {
0330     .release = edac_pci_release_main_kobj,
0331     .sysfs_ops = &edac_pci_sysfs_ops,
0332     .default_groups = edac_pci_groups,
0333 };
0334 
0335 /**
0336  * edac_pci_main_kobj_setup: Setup the sysfs for EDAC PCI attributes.
0337  */
0338 static int edac_pci_main_kobj_setup(void)
0339 {
0340     int err;
0341     struct bus_type *edac_subsys;
0342 
0343     edac_dbg(0, "\n");
0344 
0345     /* check and count if we have already created the main kobject */
0346     if (atomic_inc_return(&edac_pci_sysfs_refcount) != 1)
0347         return 0;
0348 
0349     /* First time, so create the main kobject and its
0350      * controls and attributes
0351      */
0352     edac_subsys = edac_get_sysfs_subsys();
0353 
0354     /* Bump the reference count on this module to ensure the
0355      * modules isn't unloaded until we deconstruct the top
0356      * level main kobj for EDAC PCI
0357      */
0358     if (!try_module_get(THIS_MODULE)) {
0359         edac_dbg(1, "try_module_get() failed\n");
0360         err = -ENODEV;
0361         goto decrement_count_fail;
0362     }
0363 
0364     edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
0365     if (!edac_pci_top_main_kobj) {
0366         edac_dbg(1, "Failed to allocate\n");
0367         err = -ENOMEM;
0368         goto kzalloc_fail;
0369     }
0370 
0371     /* Instanstiate the pci object */
0372     err = kobject_init_and_add(edac_pci_top_main_kobj,
0373                    &ktype_edac_pci_main_kobj,
0374                    &edac_subsys->dev_root->kobj, "pci");
0375     if (err) {
0376         edac_dbg(1, "Failed to register '.../edac/pci'\n");
0377         goto kobject_init_and_add_fail;
0378     }
0379 
0380     /* At this point, to 'release' the top level kobject
0381      * for EDAC PCI, then edac_pci_main_kobj_teardown()
0382      * must be used, for resources to be cleaned up properly
0383      */
0384     kobject_uevent(edac_pci_top_main_kobj, KOBJ_ADD);
0385     edac_dbg(1, "Registered '.../edac/pci' kobject\n");
0386 
0387     return 0;
0388 
0389     /* Error unwind statck */
0390 kobject_init_and_add_fail:
0391     kobject_put(edac_pci_top_main_kobj);
0392 
0393 kzalloc_fail:
0394     module_put(THIS_MODULE);
0395 
0396 decrement_count_fail:
0397     /* if are on this error exit, nothing to tear down */
0398     atomic_dec(&edac_pci_sysfs_refcount);
0399 
0400     return err;
0401 }
0402 
0403 /*
0404  * edac_pci_main_kobj_teardown()
0405  *
0406  *  if no longer linked (needed) remove the top level EDAC PCI
0407  *  kobject with its controls and attributes
0408  */
0409 static void edac_pci_main_kobj_teardown(void)
0410 {
0411     edac_dbg(0, "\n");
0412 
0413     /* Decrement the count and only if no more controller instances
0414      * are connected perform the unregisteration of the top level
0415      * main kobj
0416      */
0417     if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
0418         edac_dbg(0, "called kobject_put on main kobj\n");
0419         kobject_put(edac_pci_top_main_kobj);
0420     }
0421 }
0422 
0423 int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci)
0424 {
0425     int err;
0426     struct kobject *edac_kobj = &pci->kobj;
0427 
0428     edac_dbg(0, "idx=%d\n", pci->pci_idx);
0429 
0430     /* create the top main EDAC PCI kobject, IF needed */
0431     err = edac_pci_main_kobj_setup();
0432     if (err)
0433         return err;
0434 
0435     /* Create this instance's kobject under the MAIN kobject */
0436     err = edac_pci_create_instance_kobj(pci, pci->pci_idx);
0437     if (err)
0438         goto unregister_cleanup;
0439 
0440     err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK);
0441     if (err) {
0442         edac_dbg(0, "sysfs_create_link() returned err= %d\n", err);
0443         goto symlink_fail;
0444     }
0445 
0446     return 0;
0447 
0448     /* Error unwind stack */
0449 symlink_fail:
0450     edac_pci_unregister_sysfs_instance_kobj(pci);
0451 
0452 unregister_cleanup:
0453     edac_pci_main_kobj_teardown();
0454 
0455     return err;
0456 }
0457 
0458 void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci)
0459 {
0460     edac_dbg(0, "index=%d\n", pci->pci_idx);
0461 
0462     /* Remove the symlink */
0463     sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK);
0464 
0465     /* remove this PCI instance's sysfs entries */
0466     edac_pci_unregister_sysfs_instance_kobj(pci);
0467 
0468     /* Call the main unregister function, which will determine
0469      * if this 'pci' is the last instance.
0470      * If it is, the main kobject will be unregistered as a result
0471      */
0472     edac_dbg(0, "calling edac_pci_main_kobj_teardown()\n");
0473     edac_pci_main_kobj_teardown();
0474 }
0475 
0476 /************************ PCI error handling *************************/
0477 static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
0478 {
0479     int where;
0480     u16 status;
0481 
0482     where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
0483     pci_read_config_word(dev, where, &status);
0484 
0485     /* If we get back 0xFFFF then we must suspect that the card has been
0486      * pulled but the Linux PCI layer has not yet finished cleaning up.
0487      * We don't want to report on such devices
0488      */
0489 
0490     if (status == 0xFFFF) {
0491         u32 sanity;
0492 
0493         pci_read_config_dword(dev, 0, &sanity);
0494 
0495         if (sanity == 0xFFFFFFFF)
0496             return 0;
0497     }
0498 
0499     status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
0500         PCI_STATUS_PARITY;
0501 
0502     if (status)
0503         /* reset only the bits we are interested in */
0504         pci_write_config_word(dev, where, status);
0505 
0506     return status;
0507 }
0508 
0509 
0510 /* Clear any PCI parity errors logged by this device. */
0511 static void edac_pci_dev_parity_clear(struct pci_dev *dev)
0512 {
0513     u8 header_type;
0514 
0515     get_pci_parity_status(dev, 0);
0516 
0517     /* read the device TYPE, looking for bridges */
0518     pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
0519 
0520     if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE)
0521         get_pci_parity_status(dev, 1);
0522 }
0523 
0524 /*
0525  *  PCI Parity polling
0526  *
0527  *  Function to retrieve the current parity status
0528  *  and decode it
0529  *
0530  */
0531 static void edac_pci_dev_parity_test(struct pci_dev *dev)
0532 {
0533     unsigned long flags;
0534     u16 status;
0535     u8 header_type;
0536 
0537     /* stop any interrupts until we can acquire the status */
0538     local_irq_save(flags);
0539 
0540     /* read the STATUS register on this device */
0541     status = get_pci_parity_status(dev, 0);
0542 
0543     /* read the device TYPE, looking for bridges */
0544     pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
0545 
0546     local_irq_restore(flags);
0547 
0548     edac_dbg(4, "PCI STATUS= 0x%04x %s\n", status, dev_name(&dev->dev));
0549 
0550     /* check the status reg for errors on boards NOT marked as broken
0551      * if broken, we cannot trust any of the status bits
0552      */
0553     if (status && !dev->broken_parity_status) {
0554         if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
0555             edac_printk(KERN_CRIT, EDAC_PCI,
0556                 "Signaled System Error on %s\n",
0557                 pci_name(dev));
0558             atomic_inc(&pci_nonparity_count);
0559         }
0560 
0561         if (status & (PCI_STATUS_PARITY)) {
0562             edac_printk(KERN_CRIT, EDAC_PCI,
0563                 "Master Data Parity Error on %s\n",
0564                 pci_name(dev));
0565 
0566             atomic_inc(&pci_parity_count);
0567         }
0568 
0569         if (status & (PCI_STATUS_DETECTED_PARITY)) {
0570             edac_printk(KERN_CRIT, EDAC_PCI,
0571                 "Detected Parity Error on %s\n",
0572                 pci_name(dev));
0573 
0574             atomic_inc(&pci_parity_count);
0575         }
0576     }
0577 
0578 
0579     edac_dbg(4, "PCI HEADER TYPE= 0x%02x %s\n",
0580          header_type, dev_name(&dev->dev));
0581 
0582     if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
0583         /* On bridges, need to examine secondary status register  */
0584         status = get_pci_parity_status(dev, 1);
0585 
0586         edac_dbg(4, "PCI SEC_STATUS= 0x%04x %s\n",
0587              status, dev_name(&dev->dev));
0588 
0589         /* check the secondary status reg for errors,
0590          * on NOT broken boards
0591          */
0592         if (status && !dev->broken_parity_status) {
0593             if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) {
0594                 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
0595                     "Signaled System Error on %s\n",
0596                     pci_name(dev));
0597                 atomic_inc(&pci_nonparity_count);
0598             }
0599 
0600             if (status & (PCI_STATUS_PARITY)) {
0601                 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
0602                     "Master Data Parity Error on "
0603                     "%s\n", pci_name(dev));
0604 
0605                 atomic_inc(&pci_parity_count);
0606             }
0607 
0608             if (status & (PCI_STATUS_DETECTED_PARITY)) {
0609                 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
0610                     "Detected Parity Error on %s\n",
0611                     pci_name(dev));
0612 
0613                 atomic_inc(&pci_parity_count);
0614             }
0615         }
0616     }
0617 }
0618 
0619 /* reduce some complexity in definition of the iterator */
0620 typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
0621 
0622 /*
0623  * pci_dev parity list iterator
0624  *
0625  *  Scan the PCI device list looking for SERRORs, Master Parity ERRORS or
0626  *  Parity ERRORs on primary or secondary devices.
0627  */
0628 static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
0629 {
0630     struct pci_dev *dev = NULL;
0631 
0632     for_each_pci_dev(dev)
0633         fn(dev);
0634 }
0635 
0636 /*
0637  * edac_pci_do_parity_check
0638  *
0639  *  performs the actual PCI parity check operation
0640  */
0641 void edac_pci_do_parity_check(void)
0642 {
0643     int before_count;
0644 
0645     edac_dbg(3, "\n");
0646 
0647     /* if policy has PCI check off, leave now */
0648     if (!check_pci_errors)
0649         return;
0650 
0651     before_count = atomic_read(&pci_parity_count);
0652 
0653     /* scan all PCI devices looking for a Parity Error on devices and
0654      * bridges.
0655      * The iterator calls pci_get_device() which might sleep, thus
0656      * we cannot disable interrupts in this scan.
0657      */
0658     edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
0659 
0660     /* Only if operator has selected panic on PCI Error */
0661     if (edac_pci_get_panic_on_pe()) {
0662         /* If the count is different 'after' from 'before' */
0663         if (before_count != atomic_read(&pci_parity_count))
0664             panic("EDAC: PCI Parity Error");
0665     }
0666 }
0667 
0668 /*
0669  * edac_pci_clear_parity_errors
0670  *
0671  *  function to perform an iteration over the PCI devices
0672  *  and clearn their current status
0673  */
0674 void edac_pci_clear_parity_errors(void)
0675 {
0676     /* Clear any PCI bus parity errors that devices initially have logged
0677      * in their registers.
0678      */
0679     edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
0680 }
0681 
0682 /*
0683  * edac_pci_handle_pe
0684  *
0685  *  Called to handle a PARITY ERROR event
0686  */
0687 void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg)
0688 {
0689 
0690     /* global PE counter incremented by edac_pci_do_parity_check() */
0691     atomic_inc(&pci->counters.pe_count);
0692 
0693     if (edac_pci_get_log_pe())
0694         edac_pci_printk(pci, KERN_WARNING,
0695                 "Parity Error ctl: %s %d: %s\n",
0696                 pci->ctl_name, pci->pci_idx, msg);
0697 
0698     /*
0699      * poke all PCI devices and see which one is the troublemaker
0700      * panic() is called if set
0701      */
0702     edac_pci_do_parity_check();
0703 }
0704 EXPORT_SYMBOL_GPL(edac_pci_handle_pe);
0705 
0706 
0707 /*
0708  * edac_pci_handle_npe
0709  *
0710  *  Called to handle a NON-PARITY ERROR event
0711  */
0712 void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg)
0713 {
0714 
0715     /* global NPE counter incremented by edac_pci_do_parity_check() */
0716     atomic_inc(&pci->counters.npe_count);
0717 
0718     if (edac_pci_get_log_npe())
0719         edac_pci_printk(pci, KERN_WARNING,
0720                 "Non-Parity Error ctl: %s %d: %s\n",
0721                 pci->ctl_name, pci->pci_idx, msg);
0722 
0723     /*
0724      * poke all PCI devices and see which one is the troublemaker
0725      * panic() is called if set
0726      */
0727     edac_pci_do_parity_check();
0728 }
0729 EXPORT_SYMBOL_GPL(edac_pci_handle_npe);
0730 
0731 /*
0732  * Define the PCI parameter to the module
0733  */
0734 module_param(check_pci_errors, int, 0644);
0735 MODULE_PARM_DESC(check_pci_errors,
0736          "Check for PCI bus parity errors: 0=off 1=on");
0737 module_param(edac_pci_panic_on_pe, int, 0644);
0738 MODULE_PARM_DESC(edac_pci_panic_on_pe,
0739          "Panic on PCI Bus Parity error: 0=off 1=on");