Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * edac_device.c |
| 4 | * (C) 2007 www.douglaskthompson.com |
| 5 | * |
| 6 | * This file may be distributed under the terms of the |
| 7 | * GNU General Public License. |
| 8 | * |
| 9 | * Written by Doug Thompson <norsk5@xmission.com> |
| 10 | * |
| 11 | * edac_device API implementation |
| 12 | * 19 Jan 2007 |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/smp.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/sysctl.h> |
| 20 | #include <linux/highmem.h> |
| 21 | #include <linux/timer.h> |
| 22 | #include <linux/slab.h> |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 23 | #include <linux/jiffies.h> |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/sysdev.h> |
| 27 | #include <linux/ctype.h> |
| 28 | #include <linux/workqueue.h> |
| 29 | #include <asm/uaccess.h> |
| 30 | #include <asm/page.h> |
| 31 | |
| 32 | #include "edac_core.h" |
| 33 | #include "edac_module.h" |
| 34 | |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 35 | /* lock to memory controller's control array 'edac_device_list' */ |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 36 | static DEFINE_MUTEX(device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 37 | static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list); |
| 38 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 39 | #ifdef CONFIG_EDAC_DEBUG |
| 40 | static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev) |
| 41 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 42 | debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 43 | debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check); |
| 44 | debugf3("\tdev = %p\n", edac_dev->dev); |
| 45 | debugf3("\tmod_name:ctl_name = %s:%s\n", |
| 46 | edac_dev->mod_name, edac_dev->ctl_name); |
| 47 | debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info); |
| 48 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 49 | #endif /* CONFIG_EDAC_DEBUG */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 50 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 51 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 52 | /* |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 53 | * edac_device_alloc_ctl_info() |
| 54 | * Allocate a new edac device control info structure |
| 55 | * |
| 56 | * The control structure is allocated in complete chunk |
| 57 | * from the OS. It is in turn sub allocated to the |
| 58 | * various objects that compose the struture |
| 59 | * |
| 60 | * The structure has a 'nr_instance' array within itself. |
| 61 | * Each instance represents a major component |
| 62 | * Example: L1 cache and L2 cache are 2 instance components |
| 63 | * |
| 64 | * Within each instance is an array of 'nr_blocks' blockoffsets |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | struct edac_device_ctl_info *edac_device_alloc_ctl_info( |
| 67 | unsigned sz_private, |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 68 | char *edac_device_name, unsigned nr_instances, |
| 69 | char *edac_block_name, unsigned nr_blocks, |
| 70 | unsigned offset_value, /* zero, 1, or other based offset */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 71 | struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib, |
| 72 | int device_index) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 73 | { |
| 74 | struct edac_device_ctl_info *dev_ctl; |
| 75 | struct edac_device_instance *dev_inst, *inst; |
| 76 | struct edac_device_block *dev_blk, *blk_p, *blk; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 77 | struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 78 | unsigned total_size; |
| 79 | unsigned count; |
| 80 | unsigned instance, block, attr; |
| 81 | void *pvt; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 82 | int err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 83 | |
| 84 | debugf1("%s() instances=%d blocks=%d\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 85 | __func__, nr_instances, nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 86 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 87 | /* Calculate the size of memory we need to allocate AND |
| 88 | * determine the offsets of the various item arrays |
| 89 | * (instance,block,attrib) from the start of an allocated structure. |
| 90 | * We want the alignment of each item (instance,block,attrib) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 91 | * to be at least as stringent as what the compiler would |
| 92 | * provide if we could simply hardcode everything into a single struct. |
| 93 | */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 94 | dev_ctl = (struct edac_device_ctl_info *)NULL; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 95 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 96 | /* Calc the 'end' offset past end of ONE ctl_info structure |
| 97 | * which will become the start of the 'instance' array |
| 98 | */ |
Douglas Thompson | 7391c6d | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 99 | dev_inst = edac_align_ptr(&dev_ctl[1], sizeof(*dev_inst)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 100 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 101 | /* Calc the 'end' offset past the instance array within the ctl_info |
| 102 | * which will become the start of the block array |
| 103 | */ |
Douglas Thompson | 7391c6d | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 104 | dev_blk = edac_align_ptr(&dev_inst[nr_instances], sizeof(*dev_blk)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 105 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 106 | /* Calc the 'end' offset past the dev_blk array |
| 107 | * which will become the start of the attrib array, if any. |
| 108 | */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 109 | count = nr_instances * nr_blocks; |
Douglas Thompson | 7391c6d | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 110 | dev_attrib = edac_align_ptr(&dev_blk[count], sizeof(*dev_attrib)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 111 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 112 | /* Check for case of when an attribute array is specified */ |
| 113 | if (nr_attrib > 0) { |
| 114 | /* calc how many nr_attrib we need */ |
| 115 | count *= nr_attrib; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 116 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 117 | /* Calc the 'end' offset past the attributes array */ |
| 118 | pvt = edac_align_ptr(&dev_attrib[count], sz_private); |
| 119 | } else { |
| 120 | /* no attribute array specificed */ |
| 121 | pvt = edac_align_ptr(dev_attrib, sz_private); |
| 122 | } |
| 123 | |
| 124 | /* 'pvt' now points to where the private data area is. |
| 125 | * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib) |
| 126 | * is baselined at ZERO |
| 127 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 128 | total_size = ((unsigned long)pvt) + sz_private; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* Allocate the amount of memory for the set of control structures */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 131 | dev_ctl = kzalloc(total_size, GFP_KERNEL); |
| 132 | if (dev_ctl == NULL) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 133 | return NULL; |
| 134 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 135 | /* Adjust pointers so they point within the actual memory we |
| 136 | * just allocated rather than an imaginary chunk of memory |
| 137 | * located at address 0. |
| 138 | * 'dev_ctl' points to REAL memory, while the others are |
| 139 | * ZERO based and thus need to be adjusted to point within |
| 140 | * the allocated memory. |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 141 | */ |
| 142 | dev_inst = (struct edac_device_instance *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 143 | (((char *)dev_ctl) + ((unsigned long)dev_inst)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 144 | dev_blk = (struct edac_device_block *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 145 | (((char *)dev_ctl) + ((unsigned long)dev_blk)); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 146 | dev_attrib = (struct edac_dev_sysfs_block_attribute *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 147 | (((char *)dev_ctl) + ((unsigned long)dev_attrib)); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 148 | pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 149 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 150 | /* Begin storing the information into the control info structure */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 151 | dev_ctl->dev_idx = device_index; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 152 | dev_ctl->nr_instances = nr_instances; |
| 153 | dev_ctl->instances = dev_inst; |
| 154 | dev_ctl->pvt_info = pvt; |
| 155 | |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 156 | /* Name of this edac device */ |
| 157 | snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 158 | |
| 159 | /* Initialize every Instance */ |
| 160 | for (instance = 0; instance < nr_instances; instance++) { |
| 161 | inst = &dev_inst[instance]; |
| 162 | inst->ctl = dev_ctl; |
| 163 | inst->nr_blocks = nr_blocks; |
| 164 | blk_p = &dev_blk[instance * nr_blocks]; |
| 165 | inst->blocks = blk_p; |
| 166 | |
| 167 | /* name of this instance */ |
| 168 | snprintf(inst->name, sizeof(inst->name), |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 169 | "%s%u", edac_device_name, instance); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* Initialize every block in each instance */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 172 | for (block = 0; block < nr_blocks; block++) { |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 173 | blk = &blk_p[block]; |
| 174 | blk->instance = inst; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 175 | snprintf(blk->name, sizeof(blk->name), |
Douglas Thompson | d391a7b | 2007-07-19 01:50:11 -0700 | [diff] [blame] | 176 | "%s%d", edac_block_name, block+offset_value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 177 | |
| 178 | debugf1("%s() instance=%d block=%d name=%s\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 179 | __func__, instance, block, blk->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 180 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 181 | /* if there are NO attributes OR no attribute pointer |
| 182 | * then continue on to next block iteration |
| 183 | */ |
| 184 | if ((nr_attrib == 0) || (attrib_spec == NULL)) |
| 185 | continue; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 186 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 187 | /* setup the attribute array for this block */ |
| 188 | blk->nr_attribs = nr_attrib; |
| 189 | attrib_p = &dev_attrib[block*nr_instances*nr_attrib]; |
| 190 | blk->block_attributes = attrib_p; |
| 191 | |
| 192 | /* Initialize every user specified attribute in this |
| 193 | * block with the data the caller passed in |
| 194 | */ |
| 195 | for (attr = 0; attr < nr_attrib; attr++) { |
| 196 | attrib = &attrib_p[attr]; |
| 197 | attrib->attr = attrib_spec->attr; |
| 198 | attrib->show = attrib_spec->show; |
| 199 | attrib->store = attrib_spec->store; |
| 200 | |
| 201 | /* up reference this block */ |
| 202 | attrib->block = blk; |
| 203 | |
| 204 | /* bump the attrib_spec */ |
| 205 | attrib_spec++; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* Mark this instance as merely ALLOCATED */ |
| 211 | dev_ctl->op_state = OP_ALLOC; |
| 212 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 213 | /* |
| 214 | * Initialize the 'root' kobj for the edac_device controller |
| 215 | */ |
| 216 | err = edac_device_register_sysfs_main_kobj(dev_ctl); |
| 217 | if (err) { |
| 218 | kfree(dev_ctl); |
| 219 | return NULL; |
| 220 | } |
| 221 | |
| 222 | /* at this point, the root kobj is valid, and in order to |
| 223 | * 'free' the object, then the function: |
| 224 | * edac_device_unregister_sysfs_main_kobj() must be called |
| 225 | * which will perform kobj unregistration and the actual free |
| 226 | * will occur during the kobject callback operation |
| 227 | */ |
| 228 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 229 | return dev_ctl; |
| 230 | } |
| 231 | EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info); |
| 232 | |
| 233 | /* |
| 234 | * edac_device_free_ctl_info() |
| 235 | * frees the memory allocated by the edac_device_alloc_ctl_info() |
| 236 | * function |
| 237 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 238 | void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info) |
| 239 | { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 240 | edac_device_unregister_sysfs_main_kobj(ctl_info); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 241 | } |
| 242 | EXPORT_SYMBOL_GPL(edac_device_free_ctl_info); |
| 243 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 244 | /* |
| 245 | * find_edac_device_by_dev |
| 246 | * scans the edac_device list for a specific 'struct device *' |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 247 | * |
| 248 | * lock to be held prior to call: device_ctls_mutex |
| 249 | * |
| 250 | * Return: |
| 251 | * pointer to control structure managing 'dev' |
| 252 | * NULL if not found on list |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 253 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 254 | static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 255 | { |
| 256 | struct edac_device_ctl_info *edac_dev; |
| 257 | struct list_head *item; |
| 258 | |
| 259 | debugf3("%s()\n", __func__); |
| 260 | |
| 261 | list_for_each(item, &edac_device_list) { |
| 262 | edac_dev = list_entry(item, struct edac_device_ctl_info, link); |
| 263 | |
| 264 | if (edac_dev->dev == dev) |
| 265 | return edac_dev; |
| 266 | } |
| 267 | |
| 268 | return NULL; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * add_edac_dev_to_global_list |
| 273 | * Before calling this function, caller must |
| 274 | * assign a unique value to edac_dev->dev_idx. |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 275 | * |
| 276 | * lock to be held prior to call: device_ctls_mutex |
| 277 | * |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 278 | * Return: |
| 279 | * 0 on success |
| 280 | * 1 on failure. |
| 281 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 282 | static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct list_head *item, *insert_before; |
| 285 | struct edac_device_ctl_info *rover; |
| 286 | |
| 287 | insert_before = &edac_device_list; |
| 288 | |
| 289 | /* Determine if already on the list */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 290 | rover = find_edac_device_by_dev(edac_dev->dev); |
| 291 | if (unlikely(rover != NULL)) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 292 | goto fail0; |
| 293 | |
| 294 | /* Insert in ascending order by 'dev_idx', so find position */ |
| 295 | list_for_each(item, &edac_device_list) { |
| 296 | rover = list_entry(item, struct edac_device_ctl_info, link); |
| 297 | |
| 298 | if (rover->dev_idx >= edac_dev->dev_idx) { |
| 299 | if (unlikely(rover->dev_idx == edac_dev->dev_idx)) |
| 300 | goto fail1; |
| 301 | |
| 302 | insert_before = item; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | list_add_tail_rcu(&edac_dev->link, insert_before); |
| 308 | return 0; |
| 309 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 310 | fail0: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 311 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 312 | "%s (%s) %s %s already assigned %d\n", |
| 313 | rover->dev->bus_id, dev_name(rover), |
| 314 | rover->mod_name, rover->ctl_name, rover->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 315 | return 1; |
| 316 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 317 | fail1: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 318 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 319 | "bug in low-level driver: attempt to assign\n" |
| 320 | " duplicate dev_idx %d in %s()\n", rover->dev_idx, |
| 321 | __func__); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 322 | return 1; |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | * complete_edac_device_list_del |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 327 | * |
| 328 | * callback function when reference count is zero |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 329 | */ |
| 330 | static void complete_edac_device_list_del(struct rcu_head *head) |
| 331 | { |
| 332 | struct edac_device_ctl_info *edac_dev; |
| 333 | |
| 334 | edac_dev = container_of(head, struct edac_device_ctl_info, rcu); |
| 335 | INIT_LIST_HEAD(&edac_dev->link); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 336 | complete(&edac_dev->removal_complete); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* |
| 340 | * del_edac_device_from_global_list |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 341 | * |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 342 | * remove the RCU, setup for a callback call, |
| 343 | * then wait for the callback to occur |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 344 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 345 | static void del_edac_device_from_global_list(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 346 | *edac_device) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 347 | { |
| 348 | list_del_rcu(&edac_device->link); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 349 | |
| 350 | init_completion(&edac_device->removal_complete); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 351 | call_rcu(&edac_device->rcu, complete_edac_device_list_del); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 352 | wait_for_completion(&edac_device->removal_complete); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
| 356 | * edac_device_find |
| 357 | * Search for a edac_device_ctl_info structure whose index is 'idx'. |
| 358 | * |
| 359 | * If found, return a pointer to the structure. |
| 360 | * Else return NULL. |
| 361 | * |
| 362 | * Caller must hold device_ctls_mutex. |
| 363 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 364 | struct edac_device_ctl_info *edac_device_find(int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 365 | { |
| 366 | struct list_head *item; |
| 367 | struct edac_device_ctl_info *edac_dev; |
| 368 | |
| 369 | /* Iterate over list, looking for exact match of ID */ |
| 370 | list_for_each(item, &edac_device_list) { |
| 371 | edac_dev = list_entry(item, struct edac_device_ctl_info, link); |
| 372 | |
| 373 | if (edac_dev->dev_idx >= idx) { |
| 374 | if (edac_dev->dev_idx == idx) |
| 375 | return edac_dev; |
| 376 | |
| 377 | /* not on list, so terminate early */ |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return NULL; |
| 383 | } |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 384 | EXPORT_SYMBOL_GPL(edac_device_find); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 387 | * edac_device_workq_function |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 388 | * performs the operation scheduled by a workq request |
| 389 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 390 | static void edac_device_workq_function(struct work_struct *work_req) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 391 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 392 | struct delayed_work *d_work = (struct delayed_work *)work_req; |
| 393 | struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 394 | |
| 395 | //debugf0("%s() here and running\n", __func__); |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 396 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 397 | |
| 398 | /* Only poll controllers that are running polled and have a check */ |
| 399 | if ((edac_dev->op_state == OP_RUNNING_POLL) && |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 400 | (edac_dev->edac_check != NULL)) { |
| 401 | edac_dev->edac_check(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 404 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 405 | |
| 406 | /* Reschedule */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 407 | queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 411 | * edac_device_workq_setup |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 412 | * initialize a workq item for this edac_device instance |
| 413 | * passing in the new delay period in msec |
| 414 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 415 | void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 416 | unsigned msec) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 417 | { |
| 418 | debugf0("%s()\n", __func__); |
| 419 | |
| 420 | edac_dev->poll_msec = msec; |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 421 | edac_dev->delay = msecs_to_jiffies(msec); /* Calc delay jiffies */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 422 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 423 | INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 424 | queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 428 | * edac_device_workq_teardown |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 429 | * stop the workq processing on this edac_dev |
| 430 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 431 | void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 432 | { |
| 433 | int status; |
| 434 | |
| 435 | status = cancel_delayed_work(&edac_dev->work); |
| 436 | if (status == 0) { |
| 437 | /* workq instance might be running, wait for it */ |
| 438 | flush_workqueue(edac_workqueue); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * edac_device_reset_delay_period |
| 444 | */ |
| 445 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 446 | void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 447 | unsigned long value) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 448 | { |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 449 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 450 | |
| 451 | /* cancel the current workq request */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 452 | edac_device_workq_teardown(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 453 | |
| 454 | /* restart the workq request, with new delay value */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 455 | edac_device_workq_setup(edac_dev, value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 456 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 457 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 460 | /** |
| 461 | * edac_device_add_device: Insert the 'edac_dev' structure into the |
| 462 | * edac_device global list and create sysfs entries associated with |
| 463 | * edac_device structure. |
| 464 | * @edac_device: pointer to the edac_device structure to be added to the list |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 465 | * 'edac_device' structure. |
| 466 | * |
| 467 | * Return: |
| 468 | * 0 Success |
| 469 | * !0 Failure |
| 470 | */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 471 | int edac_device_add_device(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 472 | { |
| 473 | debugf0("%s()\n", __func__); |
| 474 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 475 | #ifdef CONFIG_EDAC_DEBUG |
| 476 | if (edac_debug_level >= 3) |
| 477 | edac_device_dump_device(edac_dev); |
| 478 | #endif |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 479 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 480 | |
| 481 | if (add_edac_dev_to_global_list(edac_dev)) |
| 482 | goto fail0; |
| 483 | |
| 484 | /* set load time so that error rate can be tracked */ |
| 485 | edac_dev->start_time = jiffies; |
| 486 | |
| 487 | /* create this instance's sysfs entries */ |
| 488 | if (edac_device_create_sysfs(edac_dev)) { |
| 489 | edac_device_printk(edac_dev, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 490 | "failed to create sysfs device\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 491 | goto fail1; |
| 492 | } |
| 493 | |
| 494 | /* If there IS a check routine, then we are running POLLED */ |
| 495 | if (edac_dev->edac_check != NULL) { |
| 496 | /* This instance is NOW RUNNING */ |
| 497 | edac_dev->op_state = OP_RUNNING_POLL; |
| 498 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 499 | /* |
| 500 | * enable workq processing on this instance, |
| 501 | * default = 1000 msec |
| 502 | */ |
| 503 | edac_device_workq_setup(edac_dev, 1000); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 504 | } else { |
| 505 | edac_dev->op_state = OP_RUNNING_INTERRUPT; |
| 506 | } |
| 507 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 508 | /* Report action taken */ |
| 509 | edac_device_printk(edac_dev, KERN_INFO, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 510 | "Giving out device to module '%s' controller " |
| 511 | "'%s': DEV '%s' (%s)\n", |
| 512 | edac_dev->mod_name, |
| 513 | edac_dev->ctl_name, |
| 514 | dev_name(edac_dev), |
Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 515 | edac_op_state_to_string(edac_dev->op_state)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 516 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 517 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 518 | return 0; |
| 519 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 520 | fail1: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 521 | /* Some error, so remove the entry from the lsit */ |
| 522 | del_edac_device_from_global_list(edac_dev); |
| 523 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 524 | fail0: |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 525 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 526 | return 1; |
| 527 | } |
| 528 | EXPORT_SYMBOL_GPL(edac_device_add_device); |
| 529 | |
| 530 | /** |
| 531 | * edac_device_del_device: |
| 532 | * Remove sysfs entries for specified edac_device structure and |
| 533 | * then remove edac_device structure from global list |
| 534 | * |
| 535 | * @pdev: |
| 536 | * Pointer to 'struct device' representing edac_device |
| 537 | * structure to remove. |
| 538 | * |
| 539 | * Return: |
| 540 | * Pointer to removed edac_device structure, |
| 541 | * OR NULL if device not found. |
| 542 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 543 | struct edac_device_ctl_info *edac_device_del_device(struct device *dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 544 | { |
| 545 | struct edac_device_ctl_info *edac_dev; |
| 546 | |
| 547 | debugf0("MC: %s()\n", __func__); |
| 548 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 549 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 550 | |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 551 | /* Find the structure on the list, if not there, then leave */ |
| 552 | edac_dev = find_edac_device_by_dev(dev); |
| 553 | if (edac_dev == NULL) { |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 554 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 555 | return NULL; |
| 556 | } |
| 557 | |
| 558 | /* mark this instance as OFFLINE */ |
| 559 | edac_dev->op_state = OP_OFFLINE; |
| 560 | |
| 561 | /* clear workq processing on this instance */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 562 | edac_device_workq_teardown(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 563 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 564 | /* deregister from global list */ |
| 565 | del_edac_device_from_global_list(edac_dev); |
| 566 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 567 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 568 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame^] | 569 | /* Tear down the sysfs entries for this instance */ |
| 570 | edac_device_remove_sysfs(edac_dev); |
| 571 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 572 | edac_printk(KERN_INFO, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 573 | "Removed device %d for %s %s: DEV %s\n", |
| 574 | edac_dev->dev_idx, |
| 575 | edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 576 | |
| 577 | return edac_dev; |
| 578 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 579 | EXPORT_SYMBOL_GPL(edac_device_del_device); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 580 | |
| 581 | static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev) |
| 582 | { |
| 583 | return edac_dev->log_ce; |
| 584 | } |
| 585 | |
| 586 | static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev) |
| 587 | { |
| 588 | return edac_dev->log_ue; |
| 589 | } |
| 590 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 591 | static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 592 | *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 593 | { |
| 594 | return edac_dev->panic_on_ue; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * edac_device_handle_ce |
| 599 | * perform a common output and handling of an 'edac_dev' CE event |
| 600 | */ |
| 601 | void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 602 | int inst_nr, int block_nr, const char *msg) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 603 | { |
| 604 | struct edac_device_instance *instance; |
| 605 | struct edac_device_block *block = NULL; |
| 606 | |
| 607 | if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { |
| 608 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 609 | "INTERNAL ERROR: 'instance' out of range " |
| 610 | "(%d >= %d)\n", inst_nr, |
| 611 | edac_dev->nr_instances); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 612 | return; |
| 613 | } |
| 614 | |
| 615 | instance = edac_dev->instances + inst_nr; |
| 616 | |
| 617 | if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { |
| 618 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 619 | "INTERNAL ERROR: instance %d 'block' " |
| 620 | "out of range (%d >= %d)\n", |
| 621 | inst_nr, block_nr, |
| 622 | instance->nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 623 | return; |
| 624 | } |
| 625 | |
| 626 | if (instance->nr_blocks > 0) { |
| 627 | block = instance->blocks + block_nr; |
| 628 | block->counters.ce_count++; |
| 629 | } |
| 630 | |
| 631 | /* Propogate the count up the 'totals' tree */ |
| 632 | instance->counters.ce_count++; |
| 633 | edac_dev->counters.ce_count++; |
| 634 | |
| 635 | if (edac_device_get_log_ce(edac_dev)) |
| 636 | edac_device_printk(edac_dev, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 637 | "CE: %s instance: %s block: %s '%s'\n", |
| 638 | edac_dev->ctl_name, instance->name, |
| 639 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 640 | } |
| 641 | EXPORT_SYMBOL_GPL(edac_device_handle_ce); |
| 642 | |
| 643 | /* |
| 644 | * edac_device_handle_ue |
| 645 | * perform a common output and handling of an 'edac_dev' UE event |
| 646 | */ |
| 647 | void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 648 | int inst_nr, int block_nr, const char *msg) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 649 | { |
| 650 | struct edac_device_instance *instance; |
| 651 | struct edac_device_block *block = NULL; |
| 652 | |
| 653 | if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { |
| 654 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 655 | "INTERNAL ERROR: 'instance' out of range " |
| 656 | "(%d >= %d)\n", inst_nr, |
| 657 | edac_dev->nr_instances); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 658 | return; |
| 659 | } |
| 660 | |
| 661 | instance = edac_dev->instances + inst_nr; |
| 662 | |
| 663 | if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { |
| 664 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 665 | "INTERNAL ERROR: instance %d 'block' " |
| 666 | "out of range (%d >= %d)\n", |
| 667 | inst_nr, block_nr, |
| 668 | instance->nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 669 | return; |
| 670 | } |
| 671 | |
| 672 | if (instance->nr_blocks > 0) { |
| 673 | block = instance->blocks + block_nr; |
| 674 | block->counters.ue_count++; |
| 675 | } |
| 676 | |
| 677 | /* Propogate the count up the 'totals' tree */ |
| 678 | instance->counters.ue_count++; |
| 679 | edac_dev->counters.ue_count++; |
| 680 | |
| 681 | if (edac_device_get_log_ue(edac_dev)) |
| 682 | edac_device_printk(edac_dev, KERN_EMERG, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 683 | "UE: %s instance: %s block: %s '%s'\n", |
| 684 | edac_dev->ctl_name, instance->name, |
| 685 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 686 | |
| 687 | if (edac_device_get_panic_on_ue(edac_dev)) |
Douglas Thompson | d391a7b | 2007-07-19 01:50:11 -0700 | [diff] [blame] | 688 | panic("EDAC %s: UE instance: %s block %s '%s'\n", |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 689 | edac_dev->ctl_name, instance->name, |
| 690 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 691 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 692 | EXPORT_SYMBOL_GPL(edac_device_handle_ue); |