1e27e3dacSDouglas Thompson 2e27e3dacSDouglas Thompson /* 3e27e3dacSDouglas Thompson * edac_device.c 4e27e3dacSDouglas Thompson * (C) 2007 www.douglaskthompson.com 5e27e3dacSDouglas Thompson * 6e27e3dacSDouglas Thompson * This file may be distributed under the terms of the 7e27e3dacSDouglas Thompson * GNU General Public License. 8e27e3dacSDouglas Thompson * 9e27e3dacSDouglas Thompson * Written by Doug Thompson <norsk5@xmission.com> 10e27e3dacSDouglas Thompson * 11e27e3dacSDouglas Thompson * edac_device API implementation 12e27e3dacSDouglas Thompson * 19 Jan 2007 13e27e3dacSDouglas Thompson */ 14e27e3dacSDouglas Thompson 15e27e3dacSDouglas Thompson #include <linux/module.h> 16e27e3dacSDouglas Thompson #include <linux/types.h> 17e27e3dacSDouglas Thompson #include <linux/smp.h> 18e27e3dacSDouglas Thompson #include <linux/init.h> 19e27e3dacSDouglas Thompson #include <linux/sysctl.h> 20e27e3dacSDouglas Thompson #include <linux/highmem.h> 21e27e3dacSDouglas Thompson #include <linux/timer.h> 22e27e3dacSDouglas Thompson #include <linux/slab.h> 2352490c8dSDouglas Thompson #include <linux/jiffies.h> 24e27e3dacSDouglas Thompson #include <linux/spinlock.h> 25e27e3dacSDouglas Thompson #include <linux/list.h> 26e27e3dacSDouglas Thompson #include <linux/sysdev.h> 27e27e3dacSDouglas Thompson #include <linux/ctype.h> 28e27e3dacSDouglas Thompson #include <linux/workqueue.h> 29e27e3dacSDouglas Thompson #include <asm/uaccess.h> 30e27e3dacSDouglas Thompson #include <asm/page.h> 31e27e3dacSDouglas Thompson 32e27e3dacSDouglas Thompson #include "edac_core.h" 33e27e3dacSDouglas Thompson #include "edac_module.h" 34e27e3dacSDouglas Thompson 35bf52fa4aSDoug Thompson /* lock for the list: 'edac_device_list', manipulation of this list 36bf52fa4aSDoug Thompson * is protected by the 'device_ctls_mutex' lock 37bf52fa4aSDoug Thompson */ 380ca84761SDoug Thompson static DEFINE_MUTEX(device_ctls_mutex); 39e27e3dacSDouglas Thompson static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list); 40e27e3dacSDouglas Thompson 41e27e3dacSDouglas Thompson #ifdef CONFIG_EDAC_DEBUG 42e27e3dacSDouglas Thompson static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev) 43e27e3dacSDouglas Thompson { 44e27e3dacSDouglas Thompson debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx); 45e27e3dacSDouglas Thompson debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check); 46e27e3dacSDouglas Thompson debugf3("\tdev = %p\n", edac_dev->dev); 47e27e3dacSDouglas Thompson debugf3("\tmod_name:ctl_name = %s:%s\n", 48e27e3dacSDouglas Thompson edac_dev->mod_name, edac_dev->ctl_name); 49e27e3dacSDouglas Thompson debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info); 50e27e3dacSDouglas Thompson } 51e27e3dacSDouglas Thompson #endif /* CONFIG_EDAC_DEBUG */ 52e27e3dacSDouglas Thompson 531c3631ffSDouglas Thompson 54e27e3dacSDouglas Thompson /* 5552490c8dSDouglas Thompson * edac_device_alloc_ctl_info() 5652490c8dSDouglas Thompson * Allocate a new edac device control info structure 5752490c8dSDouglas Thompson * 5852490c8dSDouglas Thompson * The control structure is allocated in complete chunk 5952490c8dSDouglas Thompson * from the OS. It is in turn sub allocated to the 6052490c8dSDouglas Thompson * various objects that compose the struture 6152490c8dSDouglas Thompson * 6252490c8dSDouglas Thompson * The structure has a 'nr_instance' array within itself. 6352490c8dSDouglas Thompson * Each instance represents a major component 6452490c8dSDouglas Thompson * Example: L1 cache and L2 cache are 2 instance components 6552490c8dSDouglas Thompson * 6652490c8dSDouglas Thompson * Within each instance is an array of 'nr_blocks' blockoffsets 67e27e3dacSDouglas Thompson */ 68e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_device_alloc_ctl_info( 69e27e3dacSDouglas Thompson unsigned sz_private, 7052490c8dSDouglas Thompson char *edac_device_name, unsigned nr_instances, 7152490c8dSDouglas Thompson char *edac_block_name, unsigned nr_blocks, 7252490c8dSDouglas Thompson unsigned offset_value, /* zero, 1, or other based offset */ 73d45e7823SDoug Thompson struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib, 74d45e7823SDoug Thompson int device_index) 75e27e3dacSDouglas Thompson { 76e27e3dacSDouglas Thompson struct edac_device_ctl_info *dev_ctl; 77e27e3dacSDouglas Thompson struct edac_device_instance *dev_inst, *inst; 78e27e3dacSDouglas Thompson struct edac_device_block *dev_blk, *blk_p, *blk; 79fd309a9dSDouglas Thompson struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib; 80e27e3dacSDouglas Thompson unsigned total_size; 81e27e3dacSDouglas Thompson unsigned count; 82e27e3dacSDouglas Thompson unsigned instance, block, attr; 83e27e3dacSDouglas Thompson void *pvt; 841c3631ffSDouglas Thompson int err; 85e27e3dacSDouglas Thompson 86b2a4ac0cSDoug Thompson debugf4("%s() instances=%d blocks=%d\n", 87e27e3dacSDouglas Thompson __func__, nr_instances, nr_blocks); 88e27e3dacSDouglas Thompson 89fd309a9dSDouglas Thompson /* Calculate the size of memory we need to allocate AND 90fd309a9dSDouglas Thompson * determine the offsets of the various item arrays 91fd309a9dSDouglas Thompson * (instance,block,attrib) from the start of an allocated structure. 92fd309a9dSDouglas Thompson * We want the alignment of each item (instance,block,attrib) 93e27e3dacSDouglas Thompson * to be at least as stringent as what the compiler would 94e27e3dacSDouglas Thompson * provide if we could simply hardcode everything into a single struct. 95e27e3dacSDouglas Thompson */ 9652490c8dSDouglas Thompson dev_ctl = (struct edac_device_ctl_info *)NULL; 97e27e3dacSDouglas Thompson 98fd309a9dSDouglas Thompson /* Calc the 'end' offset past end of ONE ctl_info structure 99fd309a9dSDouglas Thompson * which will become the start of the 'instance' array 100fd309a9dSDouglas Thompson */ 1017391c6dcSDouglas Thompson dev_inst = edac_align_ptr(&dev_ctl[1], sizeof(*dev_inst)); 102e27e3dacSDouglas Thompson 103fd309a9dSDouglas Thompson /* Calc the 'end' offset past the instance array within the ctl_info 104fd309a9dSDouglas Thompson * which will become the start of the block array 105fd309a9dSDouglas Thompson */ 1067391c6dcSDouglas Thompson dev_blk = edac_align_ptr(&dev_inst[nr_instances], sizeof(*dev_blk)); 107e27e3dacSDouglas Thompson 108fd309a9dSDouglas Thompson /* Calc the 'end' offset past the dev_blk array 109fd309a9dSDouglas Thompson * which will become the start of the attrib array, if any. 110fd309a9dSDouglas Thompson */ 111e27e3dacSDouglas Thompson count = nr_instances * nr_blocks; 1127391c6dcSDouglas Thompson dev_attrib = edac_align_ptr(&dev_blk[count], sizeof(*dev_attrib)); 113e27e3dacSDouglas Thompson 114fd309a9dSDouglas Thompson /* Check for case of when an attribute array is specified */ 115fd309a9dSDouglas Thompson if (nr_attrib > 0) { 116fd309a9dSDouglas Thompson /* calc how many nr_attrib we need */ 117fd309a9dSDouglas Thompson count *= nr_attrib; 118e27e3dacSDouglas Thompson 119e27e3dacSDouglas Thompson /* Calc the 'end' offset past the attributes array */ 120e27e3dacSDouglas Thompson pvt = edac_align_ptr(&dev_attrib[count], sz_private); 121fd309a9dSDouglas Thompson } else { 122fd309a9dSDouglas Thompson /* no attribute array specificed */ 123fd309a9dSDouglas Thompson pvt = edac_align_ptr(dev_attrib, sz_private); 124fd309a9dSDouglas Thompson } 125fd309a9dSDouglas Thompson 126fd309a9dSDouglas Thompson /* 'pvt' now points to where the private data area is. 127fd309a9dSDouglas Thompson * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib) 128fd309a9dSDouglas Thompson * is baselined at ZERO 129fd309a9dSDouglas Thompson */ 130e27e3dacSDouglas Thompson total_size = ((unsigned long)pvt) + sz_private; 131e27e3dacSDouglas Thompson 132e27e3dacSDouglas Thompson /* Allocate the amount of memory for the set of control structures */ 13352490c8dSDouglas Thompson dev_ctl = kzalloc(total_size, GFP_KERNEL); 13452490c8dSDouglas Thompson if (dev_ctl == NULL) 135e27e3dacSDouglas Thompson return NULL; 136e27e3dacSDouglas Thompson 137fd309a9dSDouglas Thompson /* Adjust pointers so they point within the actual memory we 138fd309a9dSDouglas Thompson * just allocated rather than an imaginary chunk of memory 139fd309a9dSDouglas Thompson * located at address 0. 140fd309a9dSDouglas Thompson * 'dev_ctl' points to REAL memory, while the others are 141fd309a9dSDouglas Thompson * ZERO based and thus need to be adjusted to point within 142fd309a9dSDouglas Thompson * the allocated memory. 143e27e3dacSDouglas Thompson */ 144e27e3dacSDouglas Thompson dev_inst = (struct edac_device_instance *) 145e27e3dacSDouglas Thompson (((char *)dev_ctl) + ((unsigned long)dev_inst)); 146e27e3dacSDouglas Thompson dev_blk = (struct edac_device_block *) 147e27e3dacSDouglas Thompson (((char *)dev_ctl) + ((unsigned long)dev_blk)); 148fd309a9dSDouglas Thompson dev_attrib = (struct edac_dev_sysfs_block_attribute *) 149e27e3dacSDouglas Thompson (((char *)dev_ctl) + ((unsigned long)dev_attrib)); 150079708b9SDouglas Thompson pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL; 151e27e3dacSDouglas Thompson 152fd309a9dSDouglas Thompson /* Begin storing the information into the control info structure */ 153d45e7823SDoug Thompson dev_ctl->dev_idx = device_index; 154e27e3dacSDouglas Thompson dev_ctl->nr_instances = nr_instances; 155e27e3dacSDouglas Thompson dev_ctl->instances = dev_inst; 156e27e3dacSDouglas Thompson dev_ctl->pvt_info = pvt; 157e27e3dacSDouglas Thompson 15856e61a9cSDoug Thompson /* Default logging of CEs and UEs */ 15956e61a9cSDoug Thompson dev_ctl->log_ce = 1; 16056e61a9cSDoug Thompson dev_ctl->log_ue = 1; 16156e61a9cSDoug Thompson 16252490c8dSDouglas Thompson /* Name of this edac device */ 163e27e3dacSDouglas Thompson snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name); 164e27e3dacSDouglas Thompson 165b2a4ac0cSDoug Thompson debugf4("%s() edac_dev=%p next after end=%p\n", 166b2a4ac0cSDoug Thompson __func__, dev_ctl, pvt + sz_private ); 167b2a4ac0cSDoug Thompson 168e27e3dacSDouglas Thompson /* Initialize every Instance */ 169e27e3dacSDouglas Thompson for (instance = 0; instance < nr_instances; instance++) { 170e27e3dacSDouglas Thompson inst = &dev_inst[instance]; 171e27e3dacSDouglas Thompson inst->ctl = dev_ctl; 172e27e3dacSDouglas Thompson inst->nr_blocks = nr_blocks; 173e27e3dacSDouglas Thompson blk_p = &dev_blk[instance * nr_blocks]; 174e27e3dacSDouglas Thompson inst->blocks = blk_p; 175e27e3dacSDouglas Thompson 176e27e3dacSDouglas Thompson /* name of this instance */ 177e27e3dacSDouglas Thompson snprintf(inst->name, sizeof(inst->name), 178e27e3dacSDouglas Thompson "%s%u", edac_device_name, instance); 179e27e3dacSDouglas Thompson 180e27e3dacSDouglas Thompson /* Initialize every block in each instance */ 181079708b9SDouglas Thompson for (block = 0; block < nr_blocks; block++) { 182e27e3dacSDouglas Thompson blk = &blk_p[block]; 183e27e3dacSDouglas Thompson blk->instance = inst; 184e27e3dacSDouglas Thompson snprintf(blk->name, sizeof(blk->name), 185d391a7b8SDouglas Thompson "%s%d", edac_block_name, block+offset_value); 186e27e3dacSDouglas Thompson 187b2a4ac0cSDoug Thompson debugf4("%s() instance=%d inst_p=%p block=#%d " 188b2a4ac0cSDoug Thompson "block_p=%p name='%s'\n", 189b2a4ac0cSDoug Thompson __func__, instance, inst, block, 190b2a4ac0cSDoug Thompson blk, blk->name); 191e27e3dacSDouglas Thompson 192fd309a9dSDouglas Thompson /* if there are NO attributes OR no attribute pointer 193fd309a9dSDouglas Thompson * then continue on to next block iteration 194e27e3dacSDouglas Thompson */ 195fd309a9dSDouglas Thompson if ((nr_attrib == 0) || (attrib_spec == NULL)) 196fd309a9dSDouglas Thompson continue; 197fd309a9dSDouglas Thompson 198fd309a9dSDouglas Thompson /* setup the attribute array for this block */ 199fd309a9dSDouglas Thompson blk->nr_attribs = nr_attrib; 200fd309a9dSDouglas Thompson attrib_p = &dev_attrib[block*nr_instances*nr_attrib]; 201fd309a9dSDouglas Thompson blk->block_attributes = attrib_p; 202fd309a9dSDouglas Thompson 203b2a4ac0cSDoug Thompson debugf4("%s() THIS BLOCK_ATTRIB=%p\n", 204b2a4ac0cSDoug Thompson __func__, blk->block_attributes); 205b2a4ac0cSDoug Thompson 206fd309a9dSDouglas Thompson /* Initialize every user specified attribute in this 207fd309a9dSDouglas Thompson * block with the data the caller passed in 208b2a4ac0cSDoug Thompson * Each block gets its own copy of pointers, 209b2a4ac0cSDoug Thompson * and its unique 'value' 210fd309a9dSDouglas Thompson */ 211fd309a9dSDouglas Thompson for (attr = 0; attr < nr_attrib; attr++) { 212e27e3dacSDouglas Thompson attrib = &attrib_p[attr]; 213fd309a9dSDouglas Thompson 214b2a4ac0cSDoug Thompson /* populate the unique per attrib 215b2a4ac0cSDoug Thompson * with the code pointers and info 216b2a4ac0cSDoug Thompson */ 217b2a4ac0cSDoug Thompson attrib->attr = attrib_spec[attr].attr; 218b2a4ac0cSDoug Thompson attrib->show = attrib_spec[attr].show; 219b2a4ac0cSDoug Thompson attrib->store = attrib_spec[attr].store; 220e27e3dacSDouglas Thompson 221b2a4ac0cSDoug Thompson attrib->block = blk; /* up link */ 222b2a4ac0cSDoug Thompson 223b2a4ac0cSDoug Thompson debugf4("%s() alloc-attrib=%p attrib_name='%s' " 224b2a4ac0cSDoug Thompson "attrib-spec=%p spec-name=%s\n", 225b2a4ac0cSDoug Thompson __func__, attrib, attrib->attr.name, 226b2a4ac0cSDoug Thompson &attrib_spec[attr], 227b2a4ac0cSDoug Thompson attrib_spec[attr].attr.name 228b2a4ac0cSDoug Thompson ); 229e27e3dacSDouglas Thompson } 230e27e3dacSDouglas Thompson } 231e27e3dacSDouglas Thompson } 232e27e3dacSDouglas Thompson 233e27e3dacSDouglas Thompson /* Mark this instance as merely ALLOCATED */ 234e27e3dacSDouglas Thompson dev_ctl->op_state = OP_ALLOC; 235e27e3dacSDouglas Thompson 2361c3631ffSDouglas Thompson /* 2371c3631ffSDouglas Thompson * Initialize the 'root' kobj for the edac_device controller 2381c3631ffSDouglas Thompson */ 2391c3631ffSDouglas Thompson err = edac_device_register_sysfs_main_kobj(dev_ctl); 2401c3631ffSDouglas Thompson if (err) { 2411c3631ffSDouglas Thompson kfree(dev_ctl); 2421c3631ffSDouglas Thompson return NULL; 2431c3631ffSDouglas Thompson } 2441c3631ffSDouglas Thompson 2451c3631ffSDouglas Thompson /* at this point, the root kobj is valid, and in order to 2461c3631ffSDouglas Thompson * 'free' the object, then the function: 2471c3631ffSDouglas Thompson * edac_device_unregister_sysfs_main_kobj() must be called 2481c3631ffSDouglas Thompson * which will perform kobj unregistration and the actual free 2491c3631ffSDouglas Thompson * will occur during the kobject callback operation 2501c3631ffSDouglas Thompson */ 2511c3631ffSDouglas Thompson 252e27e3dacSDouglas Thompson return dev_ctl; 253e27e3dacSDouglas Thompson } 254e27e3dacSDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info); 255e27e3dacSDouglas Thompson 256e27e3dacSDouglas Thompson /* 257e27e3dacSDouglas Thompson * edac_device_free_ctl_info() 258e27e3dacSDouglas Thompson * frees the memory allocated by the edac_device_alloc_ctl_info() 259e27e3dacSDouglas Thompson * function 260e27e3dacSDouglas Thompson */ 261079708b9SDouglas Thompson void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info) 262079708b9SDouglas Thompson { 2631c3631ffSDouglas Thompson edac_device_unregister_sysfs_main_kobj(ctl_info); 264e27e3dacSDouglas Thompson } 265e27e3dacSDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_free_ctl_info); 266e27e3dacSDouglas Thompson 267e27e3dacSDouglas Thompson /* 268e27e3dacSDouglas Thompson * find_edac_device_by_dev 269e27e3dacSDouglas Thompson * scans the edac_device list for a specific 'struct device *' 27052490c8dSDouglas Thompson * 27152490c8dSDouglas Thompson * lock to be held prior to call: device_ctls_mutex 27252490c8dSDouglas Thompson * 27352490c8dSDouglas Thompson * Return: 27452490c8dSDouglas Thompson * pointer to control structure managing 'dev' 27552490c8dSDouglas Thompson * NULL if not found on list 276e27e3dacSDouglas Thompson */ 277079708b9SDouglas Thompson static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev) 278e27e3dacSDouglas Thompson { 279e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_dev; 280e27e3dacSDouglas Thompson struct list_head *item; 281e27e3dacSDouglas Thompson 282b2a4ac0cSDoug Thompson debugf0("%s()\n", __func__); 283e27e3dacSDouglas Thompson 284e27e3dacSDouglas Thompson list_for_each(item, &edac_device_list) { 285e27e3dacSDouglas Thompson edac_dev = list_entry(item, struct edac_device_ctl_info, link); 286e27e3dacSDouglas Thompson 287e27e3dacSDouglas Thompson if (edac_dev->dev == dev) 288e27e3dacSDouglas Thompson return edac_dev; 289e27e3dacSDouglas Thompson } 290e27e3dacSDouglas Thompson 291e27e3dacSDouglas Thompson return NULL; 292e27e3dacSDouglas Thompson } 293e27e3dacSDouglas Thompson 294e27e3dacSDouglas Thompson /* 295e27e3dacSDouglas Thompson * add_edac_dev_to_global_list 296e27e3dacSDouglas Thompson * Before calling this function, caller must 297e27e3dacSDouglas Thompson * assign a unique value to edac_dev->dev_idx. 29852490c8dSDouglas Thompson * 29952490c8dSDouglas Thompson * lock to be held prior to call: device_ctls_mutex 30052490c8dSDouglas Thompson * 301e27e3dacSDouglas Thompson * Return: 302e27e3dacSDouglas Thompson * 0 on success 303e27e3dacSDouglas Thompson * 1 on failure. 304e27e3dacSDouglas Thompson */ 305e27e3dacSDouglas Thompson static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev) 306e27e3dacSDouglas Thompson { 307e27e3dacSDouglas Thompson struct list_head *item, *insert_before; 308e27e3dacSDouglas Thompson struct edac_device_ctl_info *rover; 309e27e3dacSDouglas Thompson 310e27e3dacSDouglas Thompson insert_before = &edac_device_list; 311e27e3dacSDouglas Thompson 312e27e3dacSDouglas Thompson /* Determine if already on the list */ 31352490c8dSDouglas Thompson rover = find_edac_device_by_dev(edac_dev->dev); 31452490c8dSDouglas Thompson if (unlikely(rover != NULL)) 315e27e3dacSDouglas Thompson goto fail0; 316e27e3dacSDouglas Thompson 317e27e3dacSDouglas Thompson /* Insert in ascending order by 'dev_idx', so find position */ 318e27e3dacSDouglas Thompson list_for_each(item, &edac_device_list) { 319e27e3dacSDouglas Thompson rover = list_entry(item, struct edac_device_ctl_info, link); 320e27e3dacSDouglas Thompson 321e27e3dacSDouglas Thompson if (rover->dev_idx >= edac_dev->dev_idx) { 322e27e3dacSDouglas Thompson if (unlikely(rover->dev_idx == edac_dev->dev_idx)) 323e27e3dacSDouglas Thompson goto fail1; 324e27e3dacSDouglas Thompson 325e27e3dacSDouglas Thompson insert_before = item; 326e27e3dacSDouglas Thompson break; 327e27e3dacSDouglas Thompson } 328e27e3dacSDouglas Thompson } 329e27e3dacSDouglas Thompson 330e27e3dacSDouglas Thompson list_add_tail_rcu(&edac_dev->link, insert_before); 331e27e3dacSDouglas Thompson return 0; 332e27e3dacSDouglas Thompson 333e27e3dacSDouglas Thompson fail0: 334e27e3dacSDouglas Thompson edac_printk(KERN_WARNING, EDAC_MC, 335e27e3dacSDouglas Thompson "%s (%s) %s %s already assigned %d\n", 336c4192705SDave Jiang rover->dev->bus_id, dev_name(rover), 337e27e3dacSDouglas Thompson rover->mod_name, rover->ctl_name, rover->dev_idx); 338e27e3dacSDouglas Thompson return 1; 339e27e3dacSDouglas Thompson 340e27e3dacSDouglas Thompson fail1: 341e27e3dacSDouglas Thompson edac_printk(KERN_WARNING, EDAC_MC, 342e27e3dacSDouglas Thompson "bug in low-level driver: attempt to assign\n" 343079708b9SDouglas Thompson " duplicate dev_idx %d in %s()\n", rover->dev_idx, 344079708b9SDouglas Thompson __func__); 345e27e3dacSDouglas Thompson return 1; 346e27e3dacSDouglas Thompson } 347e27e3dacSDouglas Thompson 348e27e3dacSDouglas Thompson /* 349e27e3dacSDouglas Thompson * complete_edac_device_list_del 35052490c8dSDouglas Thompson * 35152490c8dSDouglas Thompson * callback function when reference count is zero 352e27e3dacSDouglas Thompson */ 353e27e3dacSDouglas Thompson static void complete_edac_device_list_del(struct rcu_head *head) 354e27e3dacSDouglas Thompson { 355e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_dev; 356e27e3dacSDouglas Thompson 357e27e3dacSDouglas Thompson edac_dev = container_of(head, struct edac_device_ctl_info, rcu); 358e27e3dacSDouglas Thompson INIT_LIST_HEAD(&edac_dev->link); 3591c3631ffSDouglas Thompson complete(&edac_dev->removal_complete); 360e27e3dacSDouglas Thompson } 361e27e3dacSDouglas Thompson 362e27e3dacSDouglas Thompson /* 363e27e3dacSDouglas Thompson * del_edac_device_from_global_list 36452490c8dSDouglas Thompson * 3651c3631ffSDouglas Thompson * remove the RCU, setup for a callback call, 3661c3631ffSDouglas Thompson * then wait for the callback to occur 367e27e3dacSDouglas Thompson */ 368079708b9SDouglas Thompson static void del_edac_device_from_global_list(struct edac_device_ctl_info 369079708b9SDouglas Thompson *edac_device) 370e27e3dacSDouglas Thompson { 371e27e3dacSDouglas Thompson list_del_rcu(&edac_device->link); 3721c3631ffSDouglas Thompson 3731c3631ffSDouglas Thompson init_completion(&edac_device->removal_complete); 374e27e3dacSDouglas Thompson call_rcu(&edac_device->rcu, complete_edac_device_list_del); 3751c3631ffSDouglas Thompson wait_for_completion(&edac_device->removal_complete); 376e27e3dacSDouglas Thompson } 377e27e3dacSDouglas Thompson 378e27e3dacSDouglas Thompson /** 379e27e3dacSDouglas Thompson * edac_device_find 380e27e3dacSDouglas Thompson * Search for a edac_device_ctl_info structure whose index is 'idx'. 381e27e3dacSDouglas Thompson * 382e27e3dacSDouglas Thompson * If found, return a pointer to the structure. 383e27e3dacSDouglas Thompson * Else return NULL. 384e27e3dacSDouglas Thompson * 385e27e3dacSDouglas Thompson * Caller must hold device_ctls_mutex. 386e27e3dacSDouglas Thompson */ 387e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_device_find(int idx) 388e27e3dacSDouglas Thompson { 389e27e3dacSDouglas Thompson struct list_head *item; 390e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_dev; 391e27e3dacSDouglas Thompson 392e27e3dacSDouglas Thompson /* Iterate over list, looking for exact match of ID */ 393e27e3dacSDouglas Thompson list_for_each(item, &edac_device_list) { 394e27e3dacSDouglas Thompson edac_dev = list_entry(item, struct edac_device_ctl_info, link); 395e27e3dacSDouglas Thompson 396e27e3dacSDouglas Thompson if (edac_dev->dev_idx >= idx) { 397e27e3dacSDouglas Thompson if (edac_dev->dev_idx == idx) 398e27e3dacSDouglas Thompson return edac_dev; 399e27e3dacSDouglas Thompson 400e27e3dacSDouglas Thompson /* not on list, so terminate early */ 401e27e3dacSDouglas Thompson break; 402e27e3dacSDouglas Thompson } 403e27e3dacSDouglas Thompson } 404e27e3dacSDouglas Thompson 405e27e3dacSDouglas Thompson return NULL; 406e27e3dacSDouglas Thompson } 40752490c8dSDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_find); 408e27e3dacSDouglas Thompson 409e27e3dacSDouglas Thompson /* 41081d87cb1SDave Jiang * edac_device_workq_function 411e27e3dacSDouglas Thompson * performs the operation scheduled by a workq request 412bf52fa4aSDoug Thompson * 413bf52fa4aSDoug Thompson * this workq is embedded within an edac_device_ctl_info 414bf52fa4aSDoug Thompson * structure, that needs to be polled for possible error events. 415bf52fa4aSDoug Thompson * 416bf52fa4aSDoug Thompson * This operation is to acquire the list mutex lock 417bf52fa4aSDoug Thompson * (thus preventing insertation or deletion) 418bf52fa4aSDoug Thompson * and then call the device's poll function IFF this device is 419bf52fa4aSDoug Thompson * running polled and there is a poll function defined. 420e27e3dacSDouglas Thompson */ 42181d87cb1SDave Jiang static void edac_device_workq_function(struct work_struct *work_req) 422e27e3dacSDouglas Thompson { 423e27e3dacSDouglas Thompson struct delayed_work *d_work = (struct delayed_work *)work_req; 424079708b9SDouglas Thompson struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work); 425e27e3dacSDouglas Thompson 4260ca84761SDoug Thompson mutex_lock(&device_ctls_mutex); 427e27e3dacSDouglas Thompson 428e27e3dacSDouglas Thompson /* Only poll controllers that are running polled and have a check */ 429e27e3dacSDouglas Thompson if ((edac_dev->op_state == OP_RUNNING_POLL) && 430e27e3dacSDouglas Thompson (edac_dev->edac_check != NULL)) { 431e27e3dacSDouglas Thompson edac_dev->edac_check(edac_dev); 432e27e3dacSDouglas Thompson } 433e27e3dacSDouglas Thompson 4340ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 435e27e3dacSDouglas Thompson 436bf52fa4aSDoug Thompson /* Reschedule the workq for the next time period to start again 437bf52fa4aSDoug Thompson * if the number of msec is for 1 sec, then adjust to the next 438bf52fa4aSDoug Thompson * whole one second to save timers fireing all over the period 439bf52fa4aSDoug Thompson * between integral seconds 440bf52fa4aSDoug Thompson */ 441bf52fa4aSDoug Thompson if (edac_dev->poll_msec == 1000) 442bf52fa4aSDoug Thompson queue_delayed_work(edac_workqueue, &edac_dev->work, 443*c2ae24cfSAnton Blanchard round_jiffies_relative(edac_dev->delay)); 444bf52fa4aSDoug Thompson else 445bf52fa4aSDoug Thompson queue_delayed_work(edac_workqueue, &edac_dev->work, 446bf52fa4aSDoug Thompson edac_dev->delay); 447e27e3dacSDouglas Thompson } 448e27e3dacSDouglas Thompson 449e27e3dacSDouglas Thompson /* 45081d87cb1SDave Jiang * edac_device_workq_setup 451e27e3dacSDouglas Thompson * initialize a workq item for this edac_device instance 452e27e3dacSDouglas Thompson * passing in the new delay period in msec 453e27e3dacSDouglas Thompson */ 45481d87cb1SDave Jiang void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev, 45581d87cb1SDave Jiang unsigned msec) 456e27e3dacSDouglas Thompson { 457e27e3dacSDouglas Thompson debugf0("%s()\n", __func__); 458e27e3dacSDouglas Thompson 459bf52fa4aSDoug Thompson /* take the arg 'msec' and set it into the control structure 460bf52fa4aSDoug Thompson * to used in the time period calculation 461bf52fa4aSDoug Thompson * then calc the number of jiffies that represents 462bf52fa4aSDoug Thompson */ 463e27e3dacSDouglas Thompson edac_dev->poll_msec = msec; 464bf52fa4aSDoug Thompson edac_dev->delay = msecs_to_jiffies(msec); 465e27e3dacSDouglas Thompson 46681d87cb1SDave Jiang INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function); 467bf52fa4aSDoug Thompson 468bf52fa4aSDoug Thompson /* optimize here for the 1 second case, which will be normal value, to 469bf52fa4aSDoug Thompson * fire ON the 1 second time event. This helps reduce all sorts of 470bf52fa4aSDoug Thompson * timers firing on sub-second basis, while they are happy 471bf52fa4aSDoug Thompson * to fire together on the 1 second exactly 472bf52fa4aSDoug Thompson */ 473bf52fa4aSDoug Thompson if (edac_dev->poll_msec == 1000) 474bf52fa4aSDoug Thompson queue_delayed_work(edac_workqueue, &edac_dev->work, 475*c2ae24cfSAnton Blanchard round_jiffies_relative(edac_dev->delay)); 476bf52fa4aSDoug Thompson else 477bf52fa4aSDoug Thompson queue_delayed_work(edac_workqueue, &edac_dev->work, 478bf52fa4aSDoug Thompson edac_dev->delay); 479e27e3dacSDouglas Thompson } 480e27e3dacSDouglas Thompson 481e27e3dacSDouglas Thompson /* 48281d87cb1SDave Jiang * edac_device_workq_teardown 483e27e3dacSDouglas Thompson * stop the workq processing on this edac_dev 484e27e3dacSDouglas Thompson */ 48581d87cb1SDave Jiang void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev) 486e27e3dacSDouglas Thompson { 487e27e3dacSDouglas Thompson int status; 488e27e3dacSDouglas Thompson 489e27e3dacSDouglas Thompson status = cancel_delayed_work(&edac_dev->work); 490e27e3dacSDouglas Thompson if (status == 0) { 491e27e3dacSDouglas Thompson /* workq instance might be running, wait for it */ 492e27e3dacSDouglas Thompson flush_workqueue(edac_workqueue); 493e27e3dacSDouglas Thompson } 494e27e3dacSDouglas Thompson } 495e27e3dacSDouglas Thompson 496e27e3dacSDouglas Thompson /* 497e27e3dacSDouglas Thompson * edac_device_reset_delay_period 498bf52fa4aSDoug Thompson * 499bf52fa4aSDoug Thompson * need to stop any outstanding workq queued up at this time 500bf52fa4aSDoug Thompson * because we will be resetting the sleep time. 501bf52fa4aSDoug Thompson * Then restart the workq on the new delay 502e27e3dacSDouglas Thompson */ 503079708b9SDouglas Thompson void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, 504e27e3dacSDouglas Thompson unsigned long value) 505e27e3dacSDouglas Thompson { 506bf52fa4aSDoug Thompson /* cancel the current workq request, without the mutex lock */ 50781d87cb1SDave Jiang edac_device_workq_teardown(edac_dev); 508e27e3dacSDouglas Thompson 509bf52fa4aSDoug Thompson /* acquire the mutex before doing the workq setup */ 510bf52fa4aSDoug Thompson mutex_lock(&device_ctls_mutex); 511bf52fa4aSDoug Thompson 512e27e3dacSDouglas Thompson /* restart the workq request, with new delay value */ 51381d87cb1SDave Jiang edac_device_workq_setup(edac_dev, value); 514e27e3dacSDouglas Thompson 5150ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 516e27e3dacSDouglas Thompson } 517e27e3dacSDouglas Thompson 518e27e3dacSDouglas Thompson /** 519e27e3dacSDouglas Thompson * edac_device_add_device: Insert the 'edac_dev' structure into the 520e27e3dacSDouglas Thompson * edac_device global list and create sysfs entries associated with 521e27e3dacSDouglas Thompson * edac_device structure. 522e27e3dacSDouglas Thompson * @edac_device: pointer to the edac_device structure to be added to the list 523e27e3dacSDouglas Thompson * 'edac_device' structure. 524e27e3dacSDouglas Thompson * 525e27e3dacSDouglas Thompson * Return: 526e27e3dacSDouglas Thompson * 0 Success 527e27e3dacSDouglas Thompson * !0 Failure 528e27e3dacSDouglas Thompson */ 529d45e7823SDoug Thompson int edac_device_add_device(struct edac_device_ctl_info *edac_dev) 530e27e3dacSDouglas Thompson { 531e27e3dacSDouglas Thompson debugf0("%s()\n", __func__); 532e27e3dacSDouglas Thompson 533e27e3dacSDouglas Thompson #ifdef CONFIG_EDAC_DEBUG 534e27e3dacSDouglas Thompson if (edac_debug_level >= 3) 535e27e3dacSDouglas Thompson edac_device_dump_device(edac_dev); 536e27e3dacSDouglas Thompson #endif 5370ca84761SDoug Thompson mutex_lock(&device_ctls_mutex); 538e27e3dacSDouglas Thompson 539e27e3dacSDouglas Thompson if (add_edac_dev_to_global_list(edac_dev)) 540e27e3dacSDouglas Thompson goto fail0; 541e27e3dacSDouglas Thompson 542e27e3dacSDouglas Thompson /* set load time so that error rate can be tracked */ 543e27e3dacSDouglas Thompson edac_dev->start_time = jiffies; 544e27e3dacSDouglas Thompson 545e27e3dacSDouglas Thompson /* create this instance's sysfs entries */ 546e27e3dacSDouglas Thompson if (edac_device_create_sysfs(edac_dev)) { 547e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_WARNING, 548e27e3dacSDouglas Thompson "failed to create sysfs device\n"); 549e27e3dacSDouglas Thompson goto fail1; 550e27e3dacSDouglas Thompson } 551e27e3dacSDouglas Thompson 552e27e3dacSDouglas Thompson /* If there IS a check routine, then we are running POLLED */ 553e27e3dacSDouglas Thompson if (edac_dev->edac_check != NULL) { 554e27e3dacSDouglas Thompson /* This instance is NOW RUNNING */ 555e27e3dacSDouglas Thompson edac_dev->op_state = OP_RUNNING_POLL; 556e27e3dacSDouglas Thompson 55781d87cb1SDave Jiang /* 55881d87cb1SDave Jiang * enable workq processing on this instance, 55981d87cb1SDave Jiang * default = 1000 msec 56081d87cb1SDave Jiang */ 56181d87cb1SDave Jiang edac_device_workq_setup(edac_dev, 1000); 562e27e3dacSDouglas Thompson } else { 563e27e3dacSDouglas Thompson edac_dev->op_state = OP_RUNNING_INTERRUPT; 564e27e3dacSDouglas Thompson } 565e27e3dacSDouglas Thompson 566e27e3dacSDouglas Thompson /* Report action taken */ 567e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_INFO, 568052dfb45SDouglas Thompson "Giving out device to module '%s' controller " 569052dfb45SDouglas Thompson "'%s': DEV '%s' (%s)\n", 570e27e3dacSDouglas Thompson edac_dev->mod_name, 571e27e3dacSDouglas Thompson edac_dev->ctl_name, 572c4192705SDave Jiang dev_name(edac_dev), 573494d0d55SDouglas Thompson edac_op_state_to_string(edac_dev->op_state)); 574e27e3dacSDouglas Thompson 5750ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 576e27e3dacSDouglas Thompson return 0; 577e27e3dacSDouglas Thompson 578e27e3dacSDouglas Thompson fail1: 579e27e3dacSDouglas Thompson /* Some error, so remove the entry from the lsit */ 580e27e3dacSDouglas Thompson del_edac_device_from_global_list(edac_dev); 581e27e3dacSDouglas Thompson 582e27e3dacSDouglas Thompson fail0: 5830ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 584e27e3dacSDouglas Thompson return 1; 585e27e3dacSDouglas Thompson } 586e27e3dacSDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_add_device); 587e27e3dacSDouglas Thompson 588e27e3dacSDouglas Thompson /** 589e27e3dacSDouglas Thompson * edac_device_del_device: 590e27e3dacSDouglas Thompson * Remove sysfs entries for specified edac_device structure and 591e27e3dacSDouglas Thompson * then remove edac_device structure from global list 592e27e3dacSDouglas Thompson * 593e27e3dacSDouglas Thompson * @pdev: 594e27e3dacSDouglas Thompson * Pointer to 'struct device' representing edac_device 595e27e3dacSDouglas Thompson * structure to remove. 596e27e3dacSDouglas Thompson * 597e27e3dacSDouglas Thompson * Return: 598e27e3dacSDouglas Thompson * Pointer to removed edac_device structure, 599e27e3dacSDouglas Thompson * OR NULL if device not found. 600e27e3dacSDouglas Thompson */ 601e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_device_del_device(struct device *dev) 602e27e3dacSDouglas Thompson { 603e27e3dacSDouglas Thompson struct edac_device_ctl_info *edac_dev; 604e27e3dacSDouglas Thompson 605b2a4ac0cSDoug Thompson debugf0("%s()\n", __func__); 606e27e3dacSDouglas Thompson 6070ca84761SDoug Thompson mutex_lock(&device_ctls_mutex); 608e27e3dacSDouglas Thompson 60952490c8dSDouglas Thompson /* Find the structure on the list, if not there, then leave */ 61052490c8dSDouglas Thompson edac_dev = find_edac_device_by_dev(dev); 61152490c8dSDouglas Thompson if (edac_dev == NULL) { 6120ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 613e27e3dacSDouglas Thompson return NULL; 614e27e3dacSDouglas Thompson } 615e27e3dacSDouglas Thompson 616e27e3dacSDouglas Thompson /* mark this instance as OFFLINE */ 617e27e3dacSDouglas Thompson edac_dev->op_state = OP_OFFLINE; 618e27e3dacSDouglas Thompson 619e27e3dacSDouglas Thompson /* clear workq processing on this instance */ 62081d87cb1SDave Jiang edac_device_workq_teardown(edac_dev); 621e27e3dacSDouglas Thompson 622e27e3dacSDouglas Thompson /* deregister from global list */ 623e27e3dacSDouglas Thompson del_edac_device_from_global_list(edac_dev); 624e27e3dacSDouglas Thompson 6250ca84761SDoug Thompson mutex_unlock(&device_ctls_mutex); 626e27e3dacSDouglas Thompson 6271c3631ffSDouglas Thompson /* Tear down the sysfs entries for this instance */ 6281c3631ffSDouglas Thompson edac_device_remove_sysfs(edac_dev); 6291c3631ffSDouglas Thompson 630e27e3dacSDouglas Thompson edac_printk(KERN_INFO, EDAC_MC, 631e27e3dacSDouglas Thompson "Removed device %d for %s %s: DEV %s\n", 632e27e3dacSDouglas Thompson edac_dev->dev_idx, 633079708b9SDouglas Thompson edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev)); 634e27e3dacSDouglas Thompson 635e27e3dacSDouglas Thompson return edac_dev; 636e27e3dacSDouglas Thompson } 637079708b9SDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_del_device); 638e27e3dacSDouglas Thompson 639e27e3dacSDouglas Thompson static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev) 640e27e3dacSDouglas Thompson { 641e27e3dacSDouglas Thompson return edac_dev->log_ce; 642e27e3dacSDouglas Thompson } 643e27e3dacSDouglas Thompson 644e27e3dacSDouglas Thompson static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev) 645e27e3dacSDouglas Thompson { 646e27e3dacSDouglas Thompson return edac_dev->log_ue; 647e27e3dacSDouglas Thompson } 648e27e3dacSDouglas Thompson 649079708b9SDouglas Thompson static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info 650079708b9SDouglas Thompson *edac_dev) 651e27e3dacSDouglas Thompson { 652e27e3dacSDouglas Thompson return edac_dev->panic_on_ue; 653e27e3dacSDouglas Thompson } 654e27e3dacSDouglas Thompson 655e27e3dacSDouglas Thompson /* 656e27e3dacSDouglas Thompson * edac_device_handle_ce 657e27e3dacSDouglas Thompson * perform a common output and handling of an 'edac_dev' CE event 658e27e3dacSDouglas Thompson */ 659e27e3dacSDouglas Thompson void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, 660e27e3dacSDouglas Thompson int inst_nr, int block_nr, const char *msg) 661e27e3dacSDouglas Thompson { 662e27e3dacSDouglas Thompson struct edac_device_instance *instance; 663e27e3dacSDouglas Thompson struct edac_device_block *block = NULL; 664e27e3dacSDouglas Thompson 665e27e3dacSDouglas Thompson if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { 666e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_ERR, 667e27e3dacSDouglas Thompson "INTERNAL ERROR: 'instance' out of range " 668079708b9SDouglas Thompson "(%d >= %d)\n", inst_nr, 669079708b9SDouglas Thompson edac_dev->nr_instances); 670e27e3dacSDouglas Thompson return; 671e27e3dacSDouglas Thompson } 672e27e3dacSDouglas Thompson 673e27e3dacSDouglas Thompson instance = edac_dev->instances + inst_nr; 674e27e3dacSDouglas Thompson 675e27e3dacSDouglas Thompson if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { 676e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_ERR, 677052dfb45SDouglas Thompson "INTERNAL ERROR: instance %d 'block' " 678052dfb45SDouglas Thompson "out of range (%d >= %d)\n", 679052dfb45SDouglas Thompson inst_nr, block_nr, 680079708b9SDouglas Thompson instance->nr_blocks); 681e27e3dacSDouglas Thompson return; 682e27e3dacSDouglas Thompson } 683e27e3dacSDouglas Thompson 684e27e3dacSDouglas Thompson if (instance->nr_blocks > 0) { 685e27e3dacSDouglas Thompson block = instance->blocks + block_nr; 686e27e3dacSDouglas Thompson block->counters.ce_count++; 687e27e3dacSDouglas Thompson } 688e27e3dacSDouglas Thompson 689e27e3dacSDouglas Thompson /* Propogate the count up the 'totals' tree */ 690e27e3dacSDouglas Thompson instance->counters.ce_count++; 691e27e3dacSDouglas Thompson edac_dev->counters.ce_count++; 692e27e3dacSDouglas Thompson 693e27e3dacSDouglas Thompson if (edac_device_get_log_ce(edac_dev)) 694e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_WARNING, 695d391a7b8SDouglas Thompson "CE: %s instance: %s block: %s '%s'\n", 696e27e3dacSDouglas Thompson edac_dev->ctl_name, instance->name, 697e27e3dacSDouglas Thompson block ? block->name : "N/A", msg); 698e27e3dacSDouglas Thompson } 699e27e3dacSDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_handle_ce); 700e27e3dacSDouglas Thompson 701e27e3dacSDouglas Thompson /* 702e27e3dacSDouglas Thompson * edac_device_handle_ue 703e27e3dacSDouglas Thompson * perform a common output and handling of an 'edac_dev' UE event 704e27e3dacSDouglas Thompson */ 705e27e3dacSDouglas Thompson void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, 706e27e3dacSDouglas Thompson int inst_nr, int block_nr, const char *msg) 707e27e3dacSDouglas Thompson { 708e27e3dacSDouglas Thompson struct edac_device_instance *instance; 709e27e3dacSDouglas Thompson struct edac_device_block *block = NULL; 710e27e3dacSDouglas Thompson 711e27e3dacSDouglas Thompson if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { 712e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_ERR, 713e27e3dacSDouglas Thompson "INTERNAL ERROR: 'instance' out of range " 714079708b9SDouglas Thompson "(%d >= %d)\n", inst_nr, 715079708b9SDouglas Thompson edac_dev->nr_instances); 716e27e3dacSDouglas Thompson return; 717e27e3dacSDouglas Thompson } 718e27e3dacSDouglas Thompson 719e27e3dacSDouglas Thompson instance = edac_dev->instances + inst_nr; 720e27e3dacSDouglas Thompson 721e27e3dacSDouglas Thompson if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { 722e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_ERR, 723052dfb45SDouglas Thompson "INTERNAL ERROR: instance %d 'block' " 724052dfb45SDouglas Thompson "out of range (%d >= %d)\n", 725052dfb45SDouglas Thompson inst_nr, block_nr, 726079708b9SDouglas Thompson instance->nr_blocks); 727e27e3dacSDouglas Thompson return; 728e27e3dacSDouglas Thompson } 729e27e3dacSDouglas Thompson 730e27e3dacSDouglas Thompson if (instance->nr_blocks > 0) { 731e27e3dacSDouglas Thompson block = instance->blocks + block_nr; 732e27e3dacSDouglas Thompson block->counters.ue_count++; 733e27e3dacSDouglas Thompson } 734e27e3dacSDouglas Thompson 735e27e3dacSDouglas Thompson /* Propogate the count up the 'totals' tree */ 736e27e3dacSDouglas Thompson instance->counters.ue_count++; 737e27e3dacSDouglas Thompson edac_dev->counters.ue_count++; 738e27e3dacSDouglas Thompson 739e27e3dacSDouglas Thompson if (edac_device_get_log_ue(edac_dev)) 740e27e3dacSDouglas Thompson edac_device_printk(edac_dev, KERN_EMERG, 741d391a7b8SDouglas Thompson "UE: %s instance: %s block: %s '%s'\n", 742e27e3dacSDouglas Thompson edac_dev->ctl_name, instance->name, 743e27e3dacSDouglas Thompson block ? block->name : "N/A", msg); 744e27e3dacSDouglas Thompson 745e27e3dacSDouglas Thompson if (edac_device_get_panic_on_ue(edac_dev)) 746d391a7b8SDouglas Thompson panic("EDAC %s: UE instance: %s block %s '%s'\n", 747e27e3dacSDouglas Thompson edac_dev->ctl_name, instance->name, 748e27e3dacSDouglas Thompson block ? block->name : "N/A", msg); 749e27e3dacSDouglas Thompson } 750079708b9SDouglas Thompson EXPORT_SYMBOL_GPL(edac_device_handle_ue); 751