9 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/ctype.h>
20 #define EDAC_PCI_SYMLINK "device"
23 static int check_pci_errors;
24 static int edac_pci_panic_on_pe;
25 static int edac_pci_log_pe = 1;
26 static int edac_pci_log_npe = 1;
27 static int edac_pci_poll_msec = 1000;
32 static struct kobject *edac_pci_top_main_kobj;
38 return check_pci_errors;
41 static int edac_pci_get_log_pe(
void)
43 return edac_pci_log_pe;
46 static int edac_pci_get_log_npe(
void)
48 return edac_pci_log_npe;
51 static int edac_pci_get_panic_on_pe(
void)
53 return edac_pci_panic_on_pe;
58 return edac_pci_poll_msec;
62 static ssize_t instance_pe_count_show(
struct edac_pci_ctl_info *pci,
char *
data)
67 static ssize_t instance_npe_count_show(
struct edac_pci_ctl_info *pci,
73 #define to_instance(k) container_of(k, struct edac_pci_ctl_info, kobj)
74 #define to_instance_attr(a) container_of(a, struct instance_attribute, attr)
77 static void edac_pci_instance_release(
struct kobject *kobj)
79 struct edac_pci_ctl_info *pci;
95 ssize_t(*
show) (
struct edac_pci_ctl_info *,
char *);
106 if (instance_attr->
show)
107 return instance_attr->
show(pci, buffer);
114 const char *buffer,
size_t count)
119 if (instance_attr->
store)
120 return instance_attr->
store(pci, buffer, count);
125 static const struct sysfs_ops pci_instance_ops = {
126 .
show = edac_pci_instance_show,
127 .store = edac_pci_instance_store
130 #define INSTANCE_ATTR(_name, _mode, _show, _store) \
131 static struct instance_attribute attr_instance_##_name = { \
132 .attr = {.name = __stringify(_name), .mode = _mode }, \
142 &attr_instance_pe_count,
143 &attr_instance_npe_count,
148 static struct kobj_type ktype_pci_instance = {
149 .
release = edac_pci_instance_release,
150 .sysfs_ops = &pci_instance_ops,
151 .default_attrs = (
struct attribute **)pci_instance_attr,
159 static int edac_pci_create_instance_kobj(
struct edac_pci_ctl_info *pci,
int idx)
178 edac_pci_top_main_kobj,
"pci%d", idx);
180 edac_dbg(2,
"failed to register instance pci%d\n", idx);
186 edac_dbg(1,
"Register instance 'pci%d' kobject\n", idx);
200 static void edac_pci_unregister_sysfs_instance_kobj(
201 struct edac_pci_ctl_info *pci)
213 #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
214 #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
217 static ssize_t edac_pci_int_show(
void *
ptr,
char *buffer)
220 return sprintf(buffer,
"%d\n", *value);
223 static ssize_t edac_pci_int_store(
void *
ptr,
const char *buffer,
size_t count)
233 struct edac_pci_dev_attribute {
236 ssize_t(*show) (
void *,
char *);
244 struct edac_pci_dev_attribute *edac_pci_dev;
245 edac_pci_dev = (
struct edac_pci_dev_attribute *)attr;
247 if (edac_pci_dev->show)
248 return edac_pci_dev->show(edac_pci_dev->value, buffer);
253 struct attribute *attr,
const char *buffer,
256 struct edac_pci_dev_attribute *edac_pci_dev;
257 edac_pci_dev = (
struct edac_pci_dev_attribute *)attr;
259 if (edac_pci_dev->show)
260 return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
264 static const struct sysfs_ops edac_pci_sysfs_ops = {
265 .
show = edac_pci_dev_show,
266 .store = edac_pci_dev_store
269 #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
270 static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
271 .attr = {.name = __stringify(_name), .mode = _mode }, \
277 #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \
278 static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
279 .attr = {.name = __stringify(_name), .mode = _mode }, \
286 EDAC_PCI_ATTR(check_pci_errors,
S_IRUGO |
S_IWUSR, edac_pci_int_show,
288 EDAC_PCI_ATTR(edac_pci_log_pe,
S_IRUGO |
S_IWUSR, edac_pci_int_show,
290 EDAC_PCI_ATTR(edac_pci_log_npe,
S_IRUGO |
S_IWUSR, edac_pci_int_show,
292 EDAC_PCI_ATTR(edac_pci_panic_on_pe,
S_IRUGO |
S_IWUSR, edac_pci_int_show,
294 EDAC_PCI_ATTR(pci_parity_count,
S_IRUGO, edac_pci_int_show,
NULL);
295 EDAC_PCI_ATTR(pci_nonparity_count,
S_IRUGO, edac_pci_int_show,
NULL);
298 static struct edac_pci_dev_attribute *edac_pci_attr[] = {
299 &edac_pci_attr_check_pci_errors,
300 &edac_pci_attr_edac_pci_log_pe,
301 &edac_pci_attr_edac_pci_log_npe,
302 &edac_pci_attr_edac_pci_panic_on_pe,
303 &edac_pci_attr_pci_parity_count,
304 &edac_pci_attr_pci_nonparity_count,
317 static void edac_pci_release_main_kobj(
struct kobject *kobj)
319 edac_dbg(0,
"here to module_put(THIS_MODULE)\n");
330 static struct kobj_type ktype_edac_pci_main_kobj = {
331 .
release = edac_pci_release_main_kobj,
332 .sysfs_ops = &edac_pci_sysfs_ops,
333 .default_attrs = (
struct attribute **)edac_pci_attr,
342 static int edac_pci_main_kobj_setup(
void)
357 if (edac_subsys ==
NULL) {
360 goto decrement_count_fail;
368 edac_dbg(1,
"try_module_get() failed\n");
374 if (!edac_pci_top_main_kobj) {
375 edac_dbg(1,
"Failed to allocate\n");
382 &ktype_edac_pci_main_kobj,
383 &edac_subsys->
dev_root->kobj,
"pci");
385 edac_dbg(1,
"Failed to register '.../edac/pci'\n");
386 goto kobject_init_and_add_fail;
394 edac_dbg(1,
"Registered '.../edac/pci' kobject\n");
399 kobject_init_and_add_fail:
400 kfree(edac_pci_top_main_kobj);
408 decrement_count_fail:
421 static void edac_pci_main_kobj_teardown(
void)
430 edac_dbg(0,
"called kobject_put on main kobj\n");
445 struct kobject *edac_kobj = &pci->kobj;
447 edac_dbg(0,
"idx=%d\n", pci->pci_idx);
450 err = edac_pci_main_kobj_setup();
455 err = edac_pci_create_instance_kobj(pci, pci->pci_idx);
457 goto unregister_cleanup;
461 edac_dbg(0,
"sysfs_create_link() returned err= %d\n", err);
469 edac_pci_unregister_sysfs_instance_kobj(pci);
472 edac_pci_main_kobj_teardown();
484 edac_dbg(0,
"index=%d\n", pci->pci_idx);
490 edac_pci_unregister_sysfs_instance_kobj(pci);
496 edac_dbg(0,
"calling edac_pci_main_kobj_teardown()\n");
497 edac_pci_main_kobj_teardown();
501 static u16 get_pci_parity_status(
struct pci_dev *
dev,
int secondary)
507 pci_read_config_word(dev, where, &status);
514 if (status == 0xFFFF) {
517 pci_read_config_dword(dev, 0, &sanity);
519 if (sanity == 0xFFFFFFFF)
528 pci_write_config_word(dev, where, status);
535 static void edac_pci_dev_parity_clear(
struct pci_dev *dev)
539 get_pci_parity_status(dev, 0);
545 get_pci_parity_status(dev, 1);
555 static void edac_pci_dev_parity_test(
struct pci_dev *dev)
565 status = get_pci_parity_status(dev, 0);
572 edac_dbg(4,
"PCI STATUS= 0x%04x %s\n", status, dev_name(&dev->
dev));
580 "Signaled System Error on %s\n",
587 "Master Data Parity Error on %s\n",
595 "Detected Parity Error on %s\n",
603 edac_dbg(4,
"PCI HEADER TYPE= 0x%02x %s\n",
604 header_type, dev_name(&dev->
dev));
608 status = get_pci_parity_status(dev, 1);
610 edac_dbg(4,
"PCI SEC_STATUS= 0x%04x %s\n",
611 status, dev_name(&dev->
dev));
619 "Signaled System Error on %s\n",
626 "Master Data Parity Error on "
627 "%s\n", pci_name(dev));
634 "Detected Parity Error on %s\n",
651 static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t
fn)
676 if (!check_pci_errors)
686 edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
689 if (edac_pci_get_panic_on_pe()) {
691 if (before_count !=
atomic_read(&pci_parity_count))
692 panic(
"EDAC: PCI Parity Error");
707 edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
721 if (edac_pci_get_log_pe())
723 "Parity Error ctl: %s %d: %s\n",
724 pci->ctl_name, pci->pci_idx, msg);
746 if (edac_pci_get_log_npe())
748 "Non-Parity Error ctl: %s %d: %s\n",
749 pci->ctl_name, pci->pci_idx, msg);
764 "Check for PCI bus parity errors: 0=off 1=on");
767 "Panic on PCI Bus Parity error: 0=off 1=on");