Douglas Thompson | 20bcb7a | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 1 | /* |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 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 | |
Douglas Thompson | 20bcb7a | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 13 | #include "edac_core.h" |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 14 | #include "edac_module.h" |
| 15 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_PCI |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 17 | |
| 18 | #define EDAC_PCI_SYMLINK "device" |
| 19 | |
| 20 | static int check_pci_errors = 0; /* default YES check PCI parity */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 21 | static int edac_pci_panic_on_pe = 0; /* default no panic on PCI Parity */ |
| 22 | static int edac_pci_log_pe = 1; /* log PCI parity errors */ |
| 23 | static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 24 | static atomic_t pci_parity_count = ATOMIC_INIT(0); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 25 | static atomic_t pci_nonparity_count = ATOMIC_INIT(0); |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 26 | static int edac_pci_poll_msec = 1000; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 27 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 28 | static struct kobject edac_pci_kobj; /* /sys/devices/system/edac/pci */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 29 | static struct completion edac_pci_kobj_complete; |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 30 | static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 31 | |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 32 | int edac_pci_get_check_errors(void) |
| 33 | { |
| 34 | return check_pci_errors; |
| 35 | } |
| 36 | |
| 37 | int edac_pci_get_log_pe(void) |
| 38 | { |
| 39 | return edac_pci_log_pe; |
| 40 | } |
| 41 | |
| 42 | int edac_pci_get_log_npe(void) |
| 43 | { |
| 44 | return edac_pci_log_npe; |
| 45 | } |
| 46 | |
| 47 | int edac_pci_get_panic_on_pe(void) |
| 48 | { |
| 49 | return edac_pci_panic_on_pe; |
| 50 | } |
| 51 | |
| 52 | int edac_pci_get_poll_msec(void) |
| 53 | { |
| 54 | return edac_pci_poll_msec; |
| 55 | } |
| 56 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 57 | /**************************** EDAC PCI sysfs instance *******************/ |
| 58 | static ssize_t instance_pe_count_show(struct edac_pci_ctl_info *pci, char *data) |
| 59 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 60 | return sprintf(data, "%u\n", atomic_read(&pci->counters.pe_count)); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static ssize_t instance_npe_count_show(struct edac_pci_ctl_info *pci, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 64 | char *data) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 65 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 66 | return sprintf(data, "%u\n", atomic_read(&pci->counters.npe_count)); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | #define to_instance(k) container_of(k, struct edac_pci_ctl_info, kobj) |
| 70 | #define to_instance_attr(a) container_of(a, struct instance_attribute, attr) |
| 71 | |
| 72 | /* DEVICE instance kobject release() function */ |
| 73 | static void edac_pci_instance_release(struct kobject *kobj) |
| 74 | { |
| 75 | struct edac_pci_ctl_info *pci; |
| 76 | |
| 77 | debugf1("%s()\n", __func__); |
| 78 | |
| 79 | pci = to_instance(kobj); |
| 80 | complete(&pci->kobj_complete); |
| 81 | } |
| 82 | |
| 83 | /* instance specific attribute structure */ |
| 84 | struct instance_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 85 | struct attribute attr; |
| 86 | ssize_t(*show) (struct edac_pci_ctl_info *, char *); |
| 87 | ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* Function to 'show' fields from the edac_pci 'instance' structure */ |
| 91 | static ssize_t edac_pci_instance_show(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 92 | struct attribute *attr, char *buffer) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 93 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 94 | struct edac_pci_ctl_info *pci = to_instance(kobj); |
| 95 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 96 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 97 | if (instance_attr->show) |
| 98 | return instance_attr->show(pci, buffer); |
| 99 | return -EIO; |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 102 | /* Function to 'store' fields into the edac_pci 'instance' structure */ |
| 103 | static ssize_t edac_pci_instance_store(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 104 | struct attribute *attr, |
| 105 | const char *buffer, size_t count) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 106 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 107 | struct edac_pci_ctl_info *pci = to_instance(kobj); |
| 108 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 109 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 110 | if (instance_attr->store) |
| 111 | return instance_attr->store(pci, buffer, count); |
| 112 | return -EIO; |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static struct sysfs_ops pci_instance_ops = { |
| 116 | .show = edac_pci_instance_show, |
| 117 | .store = edac_pci_instance_store |
| 118 | }; |
| 119 | |
| 120 | #define INSTANCE_ATTR(_name, _mode, _show, _store) \ |
| 121 | static struct instance_attribute attr_instance_##_name = { \ |
| 122 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 123 | .show = _show, \ |
| 124 | .store = _store, \ |
| 125 | }; |
| 126 | |
| 127 | INSTANCE_ATTR(pe_count, S_IRUGO, instance_pe_count_show, NULL); |
| 128 | INSTANCE_ATTR(npe_count, S_IRUGO, instance_npe_count_show, NULL); |
| 129 | |
| 130 | /* pci instance attributes */ |
| 131 | static struct instance_attribute *pci_instance_attr[] = { |
| 132 | &attr_instance_pe_count, |
| 133 | &attr_instance_npe_count, |
| 134 | NULL |
| 135 | }; |
| 136 | |
| 137 | /* the ktype for pci instance */ |
| 138 | static struct kobj_type ktype_pci_instance = { |
| 139 | .release = edac_pci_instance_release, |
| 140 | .sysfs_ops = &pci_instance_ops, |
| 141 | .default_attrs = (struct attribute **)pci_instance_attr, |
| 142 | }; |
| 143 | |
| 144 | static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx) |
| 145 | { |
| 146 | int err; |
| 147 | |
| 148 | pci->kobj.parent = &edac_pci_kobj; |
| 149 | pci->kobj.ktype = &ktype_pci_instance; |
| 150 | |
| 151 | err = kobject_set_name(&pci->kobj, "pci%d", idx); |
| 152 | if (err) |
| 153 | return err; |
| 154 | |
| 155 | err = kobject_register(&pci->kobj); |
| 156 | if (err != 0) { |
| 157 | debugf2("%s() failed to register instance pci%d\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 158 | __func__, idx); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 159 | return err; |
| 160 | } |
| 161 | |
| 162 | debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | edac_pci_delete_instance_kobj(struct edac_pci_ctl_info *pci, int idx) |
| 169 | { |
| 170 | init_completion(&pci->kobj_complete); |
| 171 | kobject_unregister(&pci->kobj); |
| 172 | wait_for_completion(&pci->kobj_complete); |
| 173 | } |
| 174 | |
| 175 | /***************************** EDAC PCI sysfs root **********************/ |
| 176 | #define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj) |
| 177 | #define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 178 | |
| 179 | static ssize_t edac_pci_int_show(void *ptr, char *buffer) |
| 180 | { |
| 181 | int *value = ptr; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 182 | return sprintf(buffer, "%d\n", *value); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count) |
| 186 | { |
| 187 | int *value = ptr; |
| 188 | |
| 189 | if (isdigit(*buffer)) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 190 | *value = simple_strtoul(buffer, NULL, 0); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 191 | |
| 192 | return count; |
| 193 | } |
| 194 | |
| 195 | struct edac_pci_dev_attribute { |
| 196 | struct attribute attr; |
| 197 | void *value; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 198 | ssize_t(*show) (void *, char *); |
| 199 | ssize_t(*store) (void *, const char *, size_t); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | /* Set of show/store abstract level functions for PCI Parity object */ |
| 203 | static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 204 | char *buffer) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 205 | { |
| 206 | struct edac_pci_dev_attribute *edac_pci_dev; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 207 | edac_pci_dev = (struct edac_pci_dev_attribute *)attr; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 208 | |
| 209 | if (edac_pci_dev->show) |
| 210 | return edac_pci_dev->show(edac_pci_dev->value, buffer); |
| 211 | return -EIO; |
| 212 | } |
| 213 | |
| 214 | static ssize_t edac_pci_dev_store(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 215 | struct attribute *attr, const char *buffer, |
| 216 | size_t count) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 217 | { |
| 218 | struct edac_pci_dev_attribute *edac_pci_dev; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 219 | edac_pci_dev = (struct edac_pci_dev_attribute *)attr; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 220 | |
| 221 | if (edac_pci_dev->show) |
| 222 | return edac_pci_dev->store(edac_pci_dev->value, buffer, count); |
| 223 | return -EIO; |
| 224 | } |
| 225 | |
| 226 | static struct sysfs_ops edac_pci_sysfs_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 227 | .show = edac_pci_dev_show, |
| 228 | .store = edac_pci_dev_store |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \ |
| 232 | static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \ |
| 233 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 234 | .value = &_name, \ |
| 235 | .show = _show, \ |
| 236 | .store = _store, \ |
| 237 | }; |
| 238 | |
| 239 | #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \ |
| 240 | static struct edac_pci_dev_attribute edac_pci_attr_##_name = { \ |
| 241 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 242 | .value = _data, \ |
| 243 | .show = _show, \ |
| 244 | .store = _store, \ |
| 245 | }; |
| 246 | |
| 247 | /* PCI Parity control files */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 248 | EDAC_PCI_ATTR(check_pci_errors, S_IRUGO | S_IWUSR, edac_pci_int_show, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 249 | edac_pci_int_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 250 | EDAC_PCI_ATTR(edac_pci_log_pe, S_IRUGO | S_IWUSR, edac_pci_int_show, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 251 | edac_pci_int_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 252 | EDAC_PCI_ATTR(edac_pci_log_npe, S_IRUGO | S_IWUSR, edac_pci_int_show, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 253 | edac_pci_int_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 254 | EDAC_PCI_ATTR(edac_pci_panic_on_pe, S_IRUGO | S_IWUSR, edac_pci_int_show, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 255 | edac_pci_int_store); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 256 | EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 257 | EDAC_PCI_ATTR(pci_nonparity_count, S_IRUGO, edac_pci_int_show, NULL); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 258 | |
| 259 | /* Base Attributes of the memory ECC object */ |
| 260 | static struct edac_pci_dev_attribute *edac_pci_attr[] = { |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 261 | &edac_pci_attr_check_pci_errors, |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 262 | &edac_pci_attr_edac_pci_log_pe, |
| 263 | &edac_pci_attr_edac_pci_log_npe, |
| 264 | &edac_pci_attr_edac_pci_panic_on_pe, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 265 | &edac_pci_attr_pci_parity_count, |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 266 | &edac_pci_attr_pci_nonparity_count, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 267 | NULL, |
| 268 | }; |
| 269 | |
| 270 | /* No memory to release */ |
| 271 | static void edac_pci_release(struct kobject *kobj) |
| 272 | { |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 273 | struct edac_pci_ctl_info *pci; |
| 274 | |
| 275 | pci = to_edacpci(kobj); |
| 276 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 277 | debugf1("%s()\n", __func__); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 278 | complete(&pci->kobj_complete); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static struct kobj_type ktype_edac_pci = { |
| 282 | .release = edac_pci_release, |
| 283 | .sysfs_ops = &edac_pci_sysfs_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 284 | .default_attrs = (struct attribute **)edac_pci_attr, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | /** |
| 288 | * edac_sysfs_pci_setup() |
| 289 | * |
| 290 | * setup the sysfs for EDAC PCI attributes |
| 291 | * assumes edac_class has already been initialized |
| 292 | */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 293 | int edac_pci_register_main_kobj(void) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 294 | { |
| 295 | int err; |
| 296 | struct sysdev_class *edac_class; |
| 297 | |
| 298 | debugf1("%s()\n", __func__); |
| 299 | |
| 300 | edac_class = edac_get_edac_class(); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 301 | if (edac_class == NULL) { |
| 302 | debugf1("%s() no edac_class\n", __func__); |
| 303 | return -ENODEV; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 306 | edac_pci_kobj.ktype = &ktype_edac_pci; |
| 307 | |
| 308 | edac_pci_kobj.parent = &edac_class->kset.kobj; |
| 309 | |
| 310 | err = kobject_set_name(&edac_pci_kobj, "pci"); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 311 | if (err) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 312 | return err; |
| 313 | |
| 314 | /* Instanstiate the pci object */ |
| 315 | /* FIXME: maybe new sysdev_create_subdir() */ |
| 316 | err = kobject_register(&edac_pci_kobj); |
| 317 | |
| 318 | if (err) { |
| 319 | debugf1("Failed to register '.../edac/pci'\n"); |
| 320 | return err; |
| 321 | } |
| 322 | |
| 323 | debugf1("Registered '.../edac/pci' kobject\n"); |
| 324 | |
| 325 | return 0; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 329 | * edac_pci_unregister_main_kobj() |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 330 | * |
| 331 | * perform the sysfs teardown for the PCI attributes |
| 332 | */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 333 | void edac_pci_unregister_main_kobj(void) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 334 | { |
| 335 | debugf0("%s()\n", __func__); |
| 336 | init_completion(&edac_pci_kobj_complete); |
| 337 | kobject_unregister(&edac_pci_kobj); |
| 338 | wait_for_completion(&edac_pci_kobj_complete); |
| 339 | } |
| 340 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 341 | int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci) |
| 342 | { |
| 343 | int err; |
| 344 | struct kobject *edac_kobj = &pci->kobj; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 345 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 346 | if (atomic_inc_return(&edac_pci_sysfs_refcount) == 1) { |
| 347 | err = edac_pci_register_main_kobj(); |
| 348 | if (err) { |
| 349 | atomic_dec(&edac_pci_sysfs_refcount); |
| 350 | return err; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | err = edac_pci_create_instance_kobj(pci, pci->pci_idx); |
| 355 | if (err) { |
| 356 | if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) |
| 357 | edac_pci_unregister_main_kobj(); |
| 358 | } |
| 359 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 360 | debugf0("%s() idx=%d\n", __func__, pci->pci_idx); |
| 361 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 362 | err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 363 | if (err) { |
| 364 | debugf0("%s() sysfs_create_link() returned err= %d\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 365 | __func__, err); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 366 | return err; |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci) |
| 373 | { |
| 374 | debugf0("%s()\n", __func__); |
| 375 | |
| 376 | edac_pci_delete_instance_kobj(pci, pci->pci_idx); |
| 377 | |
| 378 | sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK); |
| 379 | |
| 380 | if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) |
| 381 | edac_pci_unregister_main_kobj(); |
| 382 | } |
| 383 | |
| 384 | /************************ PCI error handling *************************/ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 385 | static u16 get_pci_parity_status(struct pci_dev *dev, int secondary) |
| 386 | { |
| 387 | int where; |
| 388 | u16 status; |
| 389 | |
| 390 | where = secondary ? PCI_SEC_STATUS : PCI_STATUS; |
| 391 | pci_read_config_word(dev, where, &status); |
| 392 | |
| 393 | /* If we get back 0xFFFF then we must suspect that the card has been |
| 394 | * pulled but the Linux PCI layer has not yet finished cleaning up. |
| 395 | * We don't want to report on such devices |
| 396 | */ |
| 397 | |
| 398 | if (status == 0xFFFF) { |
| 399 | u32 sanity; |
| 400 | |
| 401 | pci_read_config_dword(dev, 0, &sanity); |
| 402 | |
| 403 | if (sanity == 0xFFFFFFFF) |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 408 | PCI_STATUS_PARITY; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 409 | |
| 410 | if (status) |
| 411 | /* reset only the bits we are interested in */ |
| 412 | pci_write_config_word(dev, where, status); |
| 413 | |
| 414 | return status; |
| 415 | } |
| 416 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 417 | typedef void (*pci_parity_check_fn_t) (struct pci_dev * dev); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 418 | |
| 419 | /* Clear any PCI parity errors logged by this device. */ |
| 420 | static void edac_pci_dev_parity_clear(struct pci_dev *dev) |
| 421 | { |
| 422 | u8 header_type; |
| 423 | |
| 424 | get_pci_parity_status(dev, 0); |
| 425 | |
| 426 | /* read the device TYPE, looking for bridges */ |
| 427 | pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type); |
| 428 | |
| 429 | if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) |
| 430 | get_pci_parity_status(dev, 1); |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * PCI Parity polling |
| 435 | * |
| 436 | */ |
| 437 | static void edac_pci_dev_parity_test(struct pci_dev *dev) |
| 438 | { |
| 439 | u16 status; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 440 | u8 header_type; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 441 | |
| 442 | /* read the STATUS register on this device |
| 443 | */ |
| 444 | status = get_pci_parity_status(dev, 0); |
| 445 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 446 | debugf2("PCI STATUS= 0x%04x %s\n", status, dev->dev.bus_id); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 447 | |
| 448 | /* check the status reg for errors */ |
| 449 | if (status) { |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 450 | if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 451 | edac_printk(KERN_CRIT, EDAC_PCI, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 452 | "Signaled System Error on %s\n", |
| 453 | pci_name(dev)); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 454 | atomic_inc(&pci_nonparity_count); |
| 455 | } |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 456 | |
| 457 | if (status & (PCI_STATUS_PARITY)) { |
| 458 | edac_printk(KERN_CRIT, EDAC_PCI, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 459 | "Master Data Parity Error on %s\n", |
| 460 | pci_name(dev)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 461 | |
| 462 | atomic_inc(&pci_parity_count); |
| 463 | } |
| 464 | |
| 465 | if (status & (PCI_STATUS_DETECTED_PARITY)) { |
| 466 | edac_printk(KERN_CRIT, EDAC_PCI, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 467 | "Detected Parity Error on %s\n", |
| 468 | pci_name(dev)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 469 | |
| 470 | atomic_inc(&pci_parity_count); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /* read the device TYPE, looking for bridges */ |
| 475 | pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type); |
| 476 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 477 | debugf2("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev->dev.bus_id); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 478 | |
| 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 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 483 | debugf2("PCI SEC_STATUS= 0x%04x %s\n", status, dev->dev.bus_id); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 484 | |
| 485 | /* check the secondary status reg for errors */ |
| 486 | if (status) { |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 487 | if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 488 | edac_printk(KERN_CRIT, EDAC_PCI, "Bridge " |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 489 | "Signaled System Error on %s\n", |
| 490 | pci_name(dev)); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 491 | atomic_inc(&pci_nonparity_count); |
| 492 | } |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 493 | |
| 494 | if (status & (PCI_STATUS_PARITY)) { |
| 495 | edac_printk(KERN_CRIT, EDAC_PCI, "Bridge " |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 496 | "Master Data Parity Error on " |
| 497 | "%s\n", pci_name(dev)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 498 | |
| 499 | atomic_inc(&pci_parity_count); |
| 500 | } |
| 501 | |
| 502 | if (status & (PCI_STATUS_DETECTED_PARITY)) { |
| 503 | edac_printk(KERN_CRIT, EDAC_PCI, "Bridge " |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame^] | 504 | "Detected Parity Error on %s\n", |
| 505 | pci_name(dev)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 506 | |
| 507 | atomic_inc(&pci_parity_count); |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | /* |
| 514 | * pci_dev parity list iterator |
| 515 | * Scan the PCI device list for one iteration, looking for SERRORs |
| 516 | * Master Parity ERRORS or Parity ERRORs on primary or secondary devices |
| 517 | */ |
| 518 | static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn) |
| 519 | { |
| 520 | struct pci_dev *dev = NULL; |
| 521 | |
| 522 | /* request for kernel access to the next PCI device, if any, |
| 523 | * and while we are looking at it have its reference count |
| 524 | * bumped until we are done with it |
| 525 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 526 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 527 | fn(dev); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * edac_pci_do_parity_check |
| 533 | * |
| 534 | * performs the actual PCI parity check operation |
| 535 | */ |
| 536 | void edac_pci_do_parity_check(void) |
| 537 | { |
| 538 | unsigned long flags; |
| 539 | int before_count; |
| 540 | |
| 541 | debugf3("%s()\n", __func__); |
| 542 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 543 | if (!check_pci_errors) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 544 | return; |
| 545 | |
| 546 | before_count = atomic_read(&pci_parity_count); |
| 547 | |
| 548 | /* scan all PCI devices looking for a Parity Error on devices and |
| 549 | * bridges |
| 550 | */ |
| 551 | local_irq_save(flags); |
| 552 | edac_pci_dev_parity_iterator(edac_pci_dev_parity_test); |
| 553 | local_irq_restore(flags); |
| 554 | |
| 555 | /* Only if operator has selected panic on PCI Error */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 556 | if (edac_pci_get_panic_on_pe()) { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 557 | /* If the count is different 'after' from 'before' */ |
| 558 | if (before_count != atomic_read(&pci_parity_count)) |
| 559 | panic("EDAC: PCI Parity Error"); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void edac_pci_clear_parity_errors(void) |
| 564 | { |
| 565 | /* Clear any PCI bus parity errors that devices initially have logged |
| 566 | * in their registers. |
| 567 | */ |
| 568 | edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear); |
| 569 | } |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 570 | void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg) |
| 571 | { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 572 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 573 | /* global PE counter incremented by edac_pci_do_parity_check() */ |
| 574 | atomic_inc(&pci->counters.pe_count); |
| 575 | |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 576 | if (edac_pci_get_log_pe()) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 577 | edac_pci_printk(pci, KERN_WARNING, |
| 578 | "Parity Error ctl: %s %d: %s\n", |
| 579 | pci->ctl_name, pci->pci_idx, msg); |
| 580 | |
| 581 | /* |
| 582 | * poke all PCI devices and see which one is the troublemaker |
| 583 | * panic() is called if set |
| 584 | */ |
| 585 | edac_pci_do_parity_check(); |
| 586 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 587 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 588 | EXPORT_SYMBOL_GPL(edac_pci_handle_pe); |
| 589 | |
| 590 | void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg) |
| 591 | { |
| 592 | |
| 593 | /* global NPE counter incremented by edac_pci_do_parity_check() */ |
| 594 | atomic_inc(&pci->counters.npe_count); |
| 595 | |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 596 | if (edac_pci_get_log_npe()) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 597 | edac_pci_printk(pci, KERN_WARNING, |
| 598 | "Non-Parity Error ctl: %s %d: %s\n", |
| 599 | pci->ctl_name, pci->pci_idx, msg); |
| 600 | |
| 601 | /* |
| 602 | * poke all PCI devices and see which one is the troublemaker |
| 603 | * panic() is called if set |
| 604 | */ |
| 605 | edac_pci_do_parity_check(); |
| 606 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 607 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 608 | EXPORT_SYMBOL_GPL(edac_pci_handle_npe); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 609 | |
| 610 | /* |
| 611 | * Define the PCI parameter to the module |
| 612 | */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 613 | module_param(check_pci_errors, int, 0644); |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 614 | MODULE_PARM_DESC(check_pci_errors, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 615 | "Check for PCI bus parity errors: 0=off 1=on"); |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 616 | module_param(edac_pci_panic_on_pe, int, 0644); |
| 617 | MODULE_PARM_DESC(edac_pci_panic_on_pe, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 618 | "Panic on PCI Bus Parity error: 0=off 1=on"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 619 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 620 | #endif /* CONFIG_PCI */ |