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 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 15 | #include <asm/page.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 16 | #include <linux/uaccess.h> |
Mauro Carvalho Chehab | 6d8ef24 | 2016-10-29 10:01:41 -0200 | [diff] [blame] | 17 | #include <linux/ctype.h> |
| 18 | #include <linux/highmem.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/jiffies.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/smp.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/sysctl.h> |
| 26 | #include <linux/timer.h> |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 27 | |
Mauro Carvalho Chehab | 6d8ef24 | 2016-10-29 10:01:41 -0200 | [diff] [blame] | 28 | #include "edac_device.h" |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 29 | #include "edac_module.h" |
| 30 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 31 | /* lock for the list: 'edac_device_list', manipulation of this list |
| 32 | * is protected by the 'device_ctls_mutex' lock |
| 33 | */ |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 34 | static DEFINE_MUTEX(device_ctls_mutex); |
Robert P. J. Day | ff6ac2a | 2008-04-29 01:03:17 -0700 | [diff] [blame] | 35 | static LIST_HEAD(edac_device_list); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 36 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_EDAC_DEBUG |
| 38 | static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev) |
| 39 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 40 | edac_dbg(3, "\tedac_dev = %p dev_idx=%d\n", |
| 41 | edac_dev, edac_dev->dev_idx); |
| 42 | edac_dbg(4, "\tedac_dev->edac_check = %p\n", edac_dev->edac_check); |
| 43 | edac_dbg(3, "\tdev = %p\n", edac_dev->dev); |
| 44 | edac_dbg(3, "\tmod_name:ctl_name = %s:%s\n", |
| 45 | edac_dev->mod_name, edac_dev->ctl_name); |
| 46 | edac_dbg(3, "\tpvt_info = %p\n\n", edac_dev->pvt_info); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 47 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 48 | #endif /* CONFIG_EDAC_DEBUG */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 49 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 50 | struct edac_device_ctl_info *edac_device_alloc_ctl_info( |
| 51 | unsigned sz_private, |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 52 | char *edac_device_name, unsigned nr_instances, |
| 53 | char *edac_block_name, unsigned nr_blocks, |
| 54 | unsigned offset_value, /* zero, 1, or other based offset */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 55 | struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib, |
| 56 | int device_index) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 57 | { |
| 58 | struct edac_device_ctl_info *dev_ctl; |
| 59 | struct edac_device_instance *dev_inst, *inst; |
| 60 | struct edac_device_block *dev_blk, *blk_p, *blk; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 61 | struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 62 | unsigned total_size; |
| 63 | unsigned count; |
| 64 | unsigned instance, block, attr; |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 65 | void *pvt, *p; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 66 | int err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 67 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 68 | edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 69 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 70 | /* Calculate the size of memory we need to allocate AND |
| 71 | * determine the offsets of the various item arrays |
| 72 | * (instance,block,attrib) from the start of an allocated structure. |
| 73 | * We want the alignment of each item (instance,block,attrib) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 74 | * to be at least as stringent as what the compiler would |
| 75 | * provide if we could simply hardcode everything into a single struct. |
| 76 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 77 | p = NULL; |
| 78 | dev_ctl = edac_align_ptr(&p, sizeof(*dev_ctl), 1); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 79 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 80 | /* Calc the 'end' offset past end of ONE ctl_info structure |
| 81 | * which will become the start of the 'instance' array |
| 82 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 83 | dev_inst = edac_align_ptr(&p, sizeof(*dev_inst), nr_instances); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 84 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 85 | /* Calc the 'end' offset past the instance array within the ctl_info |
| 86 | * which will become the start of the block array |
| 87 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 88 | count = nr_instances * nr_blocks; |
| 89 | dev_blk = edac_align_ptr(&p, sizeof(*dev_blk), count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 90 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 91 | /* Calc the 'end' offset past the dev_blk array |
| 92 | * which will become the start of the attrib array, if any. |
| 93 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 94 | /* calc how many nr_attrib we need */ |
| 95 | if (nr_attrib > 0) |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 96 | count *= nr_attrib; |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 97 | dev_attrib = edac_align_ptr(&p, sizeof(*dev_attrib), count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 98 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 99 | /* Calc the 'end' offset past the attributes array */ |
| 100 | pvt = edac_align_ptr(&p, sz_private, 1); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 101 | |
| 102 | /* 'pvt' now points to where the private data area is. |
| 103 | * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib) |
| 104 | * is baselined at ZERO |
| 105 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 106 | total_size = ((unsigned long)pvt) + sz_private; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* Allocate the amount of memory for the set of control structures */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 109 | dev_ctl = kzalloc(total_size, GFP_KERNEL); |
| 110 | if (dev_ctl == NULL) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 111 | return NULL; |
| 112 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 113 | /* Adjust pointers so they point within the actual memory we |
| 114 | * just allocated rather than an imaginary chunk of memory |
| 115 | * located at address 0. |
| 116 | * 'dev_ctl' points to REAL memory, while the others are |
| 117 | * ZERO based and thus need to be adjusted to point within |
| 118 | * the allocated memory. |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 119 | */ |
| 120 | dev_inst = (struct edac_device_instance *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 121 | (((char *)dev_ctl) + ((unsigned long)dev_inst)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 122 | dev_blk = (struct edac_device_block *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 123 | (((char *)dev_ctl) + ((unsigned long)dev_blk)); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 124 | dev_attrib = (struct edac_dev_sysfs_block_attribute *) |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 125 | (((char *)dev_ctl) + ((unsigned long)dev_attrib)); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 126 | pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 127 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 128 | /* Begin storing the information into the control info structure */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 129 | dev_ctl->dev_idx = device_index; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 130 | dev_ctl->nr_instances = nr_instances; |
| 131 | dev_ctl->instances = dev_inst; |
| 132 | dev_ctl->pvt_info = pvt; |
| 133 | |
Doug Thompson | 56e61a9 | 2008-02-07 00:14:51 -0800 | [diff] [blame] | 134 | /* Default logging of CEs and UEs */ |
| 135 | dev_ctl->log_ce = 1; |
| 136 | dev_ctl->log_ue = 1; |
| 137 | |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 138 | /* Name of this edac device */ |
| 139 | snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 140 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 141 | edac_dbg(4, "edac_dev=%p next after end=%p\n", |
| 142 | dev_ctl, pvt + sz_private); |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 143 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 144 | /* Initialize every Instance */ |
| 145 | for (instance = 0; instance < nr_instances; instance++) { |
| 146 | inst = &dev_inst[instance]; |
| 147 | inst->ctl = dev_ctl; |
| 148 | inst->nr_blocks = nr_blocks; |
| 149 | blk_p = &dev_blk[instance * nr_blocks]; |
| 150 | inst->blocks = blk_p; |
| 151 | |
| 152 | /* name of this instance */ |
| 153 | snprintf(inst->name, sizeof(inst->name), |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 154 | "%s%u", edac_device_name, instance); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* Initialize every block in each instance */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 157 | for (block = 0; block < nr_blocks; block++) { |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 158 | blk = &blk_p[block]; |
| 159 | blk->instance = inst; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 160 | snprintf(blk->name, sizeof(blk->name), |
Douglas Thompson | d391a7b | 2007-07-19 01:50:11 -0700 | [diff] [blame] | 161 | "%s%d", edac_block_name, block+offset_value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 162 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 163 | edac_dbg(4, "instance=%d inst_p=%p block=#%d block_p=%p name='%s'\n", |
| 164 | instance, inst, block, blk, blk->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 165 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 166 | /* if there are NO attributes OR no attribute pointer |
| 167 | * then continue on to next block iteration |
| 168 | */ |
| 169 | if ((nr_attrib == 0) || (attrib_spec == NULL)) |
| 170 | continue; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 171 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 172 | /* setup the attribute array for this block */ |
| 173 | blk->nr_attribs = nr_attrib; |
| 174 | attrib_p = &dev_attrib[block*nr_instances*nr_attrib]; |
| 175 | blk->block_attributes = attrib_p; |
| 176 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 177 | edac_dbg(4, "THIS BLOCK_ATTRIB=%p\n", |
| 178 | blk->block_attributes); |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 179 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 180 | /* Initialize every user specified attribute in this |
| 181 | * block with the data the caller passed in |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 182 | * Each block gets its own copy of pointers, |
| 183 | * and its unique 'value' |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 184 | */ |
| 185 | for (attr = 0; attr < nr_attrib; attr++) { |
| 186 | attrib = &attrib_p[attr]; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 187 | |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 188 | /* populate the unique per attrib |
| 189 | * with the code pointers and info |
| 190 | */ |
| 191 | attrib->attr = attrib_spec[attr].attr; |
| 192 | attrib->show = attrib_spec[attr].show; |
| 193 | attrib->store = attrib_spec[attr].store; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 194 | |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 195 | attrib->block = blk; /* up link */ |
| 196 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 197 | edac_dbg(4, "alloc-attrib=%p attrib_name='%s' attrib-spec=%p spec-name=%s\n", |
| 198 | attrib, attrib->attr.name, |
| 199 | &attrib_spec[attr], |
| 200 | attrib_spec[attr].attr.name |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 201 | ); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /* Mark this instance as merely ALLOCATED */ |
| 207 | dev_ctl->op_state = OP_ALLOC; |
| 208 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 209 | /* |
| 210 | * Initialize the 'root' kobj for the edac_device controller |
| 211 | */ |
| 212 | err = edac_device_register_sysfs_main_kobj(dev_ctl); |
| 213 | if (err) { |
| 214 | kfree(dev_ctl); |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | /* at this point, the root kobj is valid, and in order to |
| 219 | * 'free' the object, then the function: |
| 220 | * edac_device_unregister_sysfs_main_kobj() must be called |
| 221 | * which will perform kobj unregistration and the actual free |
| 222 | * will occur during the kobject callback operation |
| 223 | */ |
| 224 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 225 | return dev_ctl; |
| 226 | } |
| 227 | EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info); |
| 228 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 229 | void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info) |
| 230 | { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 231 | edac_device_unregister_sysfs_main_kobj(ctl_info); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 232 | } |
| 233 | EXPORT_SYMBOL_GPL(edac_device_free_ctl_info); |
| 234 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 235 | /* |
| 236 | * find_edac_device_by_dev |
| 237 | * scans the edac_device list for a specific 'struct device *' |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 238 | * |
| 239 | * lock to be held prior to call: device_ctls_mutex |
| 240 | * |
| 241 | * Return: |
| 242 | * pointer to control structure managing 'dev' |
| 243 | * NULL if not found on list |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 244 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 245 | 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] | 246 | { |
| 247 | struct edac_device_ctl_info *edac_dev; |
| 248 | struct list_head *item; |
| 249 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 250 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 251 | |
| 252 | list_for_each(item, &edac_device_list) { |
| 253 | edac_dev = list_entry(item, struct edac_device_ctl_info, link); |
| 254 | |
| 255 | if (edac_dev->dev == dev) |
| 256 | return edac_dev; |
| 257 | } |
| 258 | |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * add_edac_dev_to_global_list |
| 264 | * Before calling this function, caller must |
| 265 | * assign a unique value to edac_dev->dev_idx. |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 266 | * |
| 267 | * lock to be held prior to call: device_ctls_mutex |
| 268 | * |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 269 | * Return: |
| 270 | * 0 on success |
| 271 | * 1 on failure. |
| 272 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 273 | 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] | 274 | { |
| 275 | struct list_head *item, *insert_before; |
| 276 | struct edac_device_ctl_info *rover; |
| 277 | |
| 278 | insert_before = &edac_device_list; |
| 279 | |
| 280 | /* Determine if already on the list */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 281 | rover = find_edac_device_by_dev(edac_dev->dev); |
| 282 | if (unlikely(rover != NULL)) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 283 | goto fail0; |
| 284 | |
| 285 | /* Insert in ascending order by 'dev_idx', so find position */ |
| 286 | list_for_each(item, &edac_device_list) { |
| 287 | rover = list_entry(item, struct edac_device_ctl_info, link); |
| 288 | |
| 289 | if (rover->dev_idx >= edac_dev->dev_idx) { |
| 290 | if (unlikely(rover->dev_idx == edac_dev->dev_idx)) |
| 291 | goto fail1; |
| 292 | |
| 293 | insert_before = item; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | list_add_tail_rcu(&edac_dev->link, insert_before); |
| 299 | return 0; |
| 300 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 301 | fail0: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 302 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 303 | "%s (%s) %s %s already assigned %d\n", |
Kay Sievers | 281efb1 | 2009-01-06 14:42:57 -0800 | [diff] [blame] | 304 | dev_name(rover->dev), edac_dev_name(rover), |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 305 | rover->mod_name, rover->ctl_name, rover->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 306 | return 1; |
| 307 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 308 | fail1: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 309 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 310 | "bug in low-level driver: attempt to assign\n" |
| 311 | " duplicate dev_idx %d in %s()\n", rover->dev_idx, |
| 312 | __func__); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | /* |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 317 | * del_edac_device_from_global_list |
| 318 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 319 | 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] | 320 | *edac_device) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 321 | { |
| 322 | list_del_rcu(&edac_device->link); |
Lai Jiangshan | e2e7709 | 2011-05-26 16:25:58 -0700 | [diff] [blame] | 323 | |
| 324 | /* these are for safe removal of devices from global list while |
| 325 | * NMI handlers may be traversing list |
| 326 | */ |
| 327 | synchronize_rcu(); |
| 328 | INIT_LIST_HEAD(&edac_device->link); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 331 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 332 | * edac_device_workq_function |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 333 | * performs the operation scheduled by a workq request |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 334 | * |
| 335 | * this workq is embedded within an edac_device_ctl_info |
| 336 | * structure, that needs to be polled for possible error events. |
| 337 | * |
| 338 | * This operation is to acquire the list mutex lock |
Jiri Kosina | f70d4a9 | 2012-05-22 10:56:21 +0200 | [diff] [blame] | 339 | * (thus preventing insertation or deletion) |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 340 | * and then call the device's poll function IFF this device is |
| 341 | * running polled and there is a poll function defined. |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 342 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 343 | static void edac_device_workq_function(struct work_struct *work_req) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 344 | { |
Jean Delvare | fbeb438 | 2009-04-13 14:40:21 -0700 | [diff] [blame] | 345 | struct delayed_work *d_work = to_delayed_work(work_req); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 346 | 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] | 347 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 348 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 349 | |
Harry Ciao | d519c8d | 2008-12-23 13:57:16 -0800 | [diff] [blame] | 350 | /* If we are being removed, bail out immediately */ |
| 351 | if (edac_dev->op_state == OP_OFFLINE) { |
| 352 | mutex_unlock(&device_ctls_mutex); |
| 353 | return; |
| 354 | } |
| 355 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 356 | /* Only poll controllers that are running polled and have a check */ |
| 357 | if ((edac_dev->op_state == OP_RUNNING_POLL) && |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 358 | (edac_dev->edac_check != NULL)) { |
| 359 | edac_dev->edac_check(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 362 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 363 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 364 | /* Reschedule the workq for the next time period to start again |
| 365 | * if the number of msec is for 1 sec, then adjust to the next |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 366 | * whole one second to save timers firing all over the period |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 367 | * between integral seconds |
| 368 | */ |
| 369 | if (edac_dev->poll_msec == 1000) |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 370 | edac_queue_work(&edac_dev->work, round_jiffies_relative(edac_dev->delay)); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 371 | else |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 372 | edac_queue_work(&edac_dev->work, edac_dev->delay); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 376 | * edac_device_workq_setup |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 377 | * initialize a workq item for this edac_device instance |
| 378 | * passing in the new delay period in msec |
| 379 | */ |
Borislav Petkov | e136fa0 | 2015-11-30 15:07:28 +0100 | [diff] [blame] | 380 | static void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev, |
| 381 | unsigned msec) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 382 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 383 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 384 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 385 | /* take the arg 'msec' and set it into the control structure |
| 386 | * to used in the time period calculation |
| 387 | * then calc the number of jiffies that represents |
| 388 | */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 389 | edac_dev->poll_msec = msec; |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 390 | edac_dev->delay = msecs_to_jiffies(msec); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 391 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 392 | INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 393 | |
| 394 | /* optimize here for the 1 second case, which will be normal value, to |
| 395 | * fire ON the 1 second time event. This helps reduce all sorts of |
| 396 | * timers firing on sub-second basis, while they are happy |
| 397 | * to fire together on the 1 second exactly |
| 398 | */ |
| 399 | if (edac_dev->poll_msec == 1000) |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 400 | edac_queue_work(&edac_dev->work, round_jiffies_relative(edac_dev->delay)); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 401 | else |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 402 | edac_queue_work(&edac_dev->work, edac_dev->delay); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /* |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 406 | * edac_device_workq_teardown |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 407 | * stop the workq processing on this edac_dev |
| 408 | */ |
Borislav Petkov | e136fa0 | 2015-11-30 15:07:28 +0100 | [diff] [blame] | 409 | static void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 410 | { |
Stephen Boyd | 881f0fc | 2013-12-30 12:14:12 -0800 | [diff] [blame] | 411 | if (!edac_dev->edac_check) |
| 412 | return; |
| 413 | |
Borislav Petkov | fcd5c4d | 2015-11-27 10:38:38 +0100 | [diff] [blame] | 414 | edac_dev->op_state = OP_OFFLINE; |
| 415 | |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 416 | edac_stop_work(&edac_dev->work); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
| 420 | * edac_device_reset_delay_period |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 421 | * |
| 422 | * need to stop any outstanding workq queued up at this time |
| 423 | * because we will be resetting the sleep time. |
| 424 | * Then restart the workq on the new delay |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 425 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 426 | 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] | 427 | unsigned long value) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 428 | { |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 429 | unsigned long jiffs = msecs_to_jiffies(value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 430 | |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 431 | if (value == 1000) |
| 432 | jiffs = round_jiffies_relative(value); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 433 | |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 434 | edac_dev->poll_msec = value; |
| 435 | edac_dev->delay = jiffs; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 436 | |
Borislav Petkov | c4cf3b4 | 2015-11-30 19:02:01 +0100 | [diff] [blame] | 437 | edac_mod_work(&edac_dev->work, jiffs); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Harry Ciao | 1dc9b70 | 2009-06-17 16:27:59 -0700 | [diff] [blame] | 440 | int edac_device_alloc_index(void) |
| 441 | { |
| 442 | static atomic_t device_indexes = ATOMIC_INIT(0); |
| 443 | |
| 444 | return atomic_inc_return(&device_indexes) - 1; |
| 445 | } |
| 446 | EXPORT_SYMBOL_GPL(edac_device_alloc_index); |
| 447 | |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 448 | int edac_device_add_device(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 449 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 450 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 451 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 452 | #ifdef CONFIG_EDAC_DEBUG |
| 453 | if (edac_debug_level >= 3) |
| 454 | edac_device_dump_device(edac_dev); |
| 455 | #endif |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 456 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 457 | |
| 458 | if (add_edac_dev_to_global_list(edac_dev)) |
| 459 | goto fail0; |
| 460 | |
| 461 | /* set load time so that error rate can be tracked */ |
| 462 | edac_dev->start_time = jiffies; |
| 463 | |
| 464 | /* create this instance's sysfs entries */ |
| 465 | if (edac_device_create_sysfs(edac_dev)) { |
| 466 | edac_device_printk(edac_dev, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 467 | "failed to create sysfs device\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 468 | goto fail1; |
| 469 | } |
| 470 | |
| 471 | /* If there IS a check routine, then we are running POLLED */ |
| 472 | if (edac_dev->edac_check != NULL) { |
| 473 | /* This instance is NOW RUNNING */ |
| 474 | edac_dev->op_state = OP_RUNNING_POLL; |
| 475 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 476 | /* |
| 477 | * enable workq processing on this instance, |
| 478 | * default = 1000 msec |
| 479 | */ |
| 480 | edac_device_workq_setup(edac_dev, 1000); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 481 | } else { |
| 482 | edac_dev->op_state = OP_RUNNING_INTERRUPT; |
| 483 | } |
| 484 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 485 | /* Report action taken */ |
| 486 | edac_device_printk(edac_dev, KERN_INFO, |
Robert Richter | 7270a60 | 2013-10-10 18:22:36 +0200 | [diff] [blame] | 487 | "Giving out device to module %s controller %s: DEV %s (%s)\n", |
| 488 | edac_dev->mod_name, edac_dev->ctl_name, edac_dev->dev_name, |
| 489 | edac_op_state_to_string(edac_dev->op_state)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 490 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 491 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 494 | fail1: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 495 | /* Some error, so remove the entry from the lsit */ |
| 496 | del_edac_device_from_global_list(edac_dev); |
| 497 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 498 | fail0: |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 499 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 500 | return 1; |
| 501 | } |
| 502 | EXPORT_SYMBOL_GPL(edac_device_add_device); |
| 503 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 504 | struct edac_device_ctl_info *edac_device_del_device(struct device *dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 505 | { |
| 506 | struct edac_device_ctl_info *edac_dev; |
| 507 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 508 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 509 | |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 510 | mutex_lock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 511 | |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 512 | /* Find the structure on the list, if not there, then leave */ |
| 513 | edac_dev = find_edac_device_by_dev(dev); |
| 514 | if (edac_dev == NULL) { |
Doug Thompson | 0ca8476 | 2007-07-19 01:50:22 -0700 | [diff] [blame] | 515 | mutex_unlock(&device_ctls_mutex); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 516 | return NULL; |
| 517 | } |
| 518 | |
| 519 | /* mark this instance as OFFLINE */ |
| 520 | edac_dev->op_state = OP_OFFLINE; |
| 521 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 522 | /* deregister from global list */ |
| 523 | del_edac_device_from_global_list(edac_dev); |
| 524 | |
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 | |
Harry Ciao | d519c8d | 2008-12-23 13:57:16 -0800 | [diff] [blame] | 527 | /* clear workq processing on this instance */ |
| 528 | edac_device_workq_teardown(edac_dev); |
| 529 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 530 | /* Tear down the sysfs entries for this instance */ |
| 531 | edac_device_remove_sysfs(edac_dev); |
| 532 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 533 | edac_printk(KERN_INFO, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 534 | "Removed device %d for %s %s: DEV %s\n", |
| 535 | edac_dev->dev_idx, |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 536 | edac_dev->mod_name, edac_dev->ctl_name, edac_dev_name(edac_dev)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 537 | |
| 538 | return edac_dev; |
| 539 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 540 | EXPORT_SYMBOL_GPL(edac_device_del_device); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 541 | |
| 542 | static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev) |
| 543 | { |
| 544 | return edac_dev->log_ce; |
| 545 | } |
| 546 | |
| 547 | static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev) |
| 548 | { |
| 549 | return edac_dev->log_ue; |
| 550 | } |
| 551 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 552 | 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] | 553 | *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 554 | { |
| 555 | return edac_dev->panic_on_ue; |
| 556 | } |
| 557 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 558 | void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 559 | int inst_nr, int block_nr, const char *msg) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 560 | { |
| 561 | struct edac_device_instance *instance; |
| 562 | struct edac_device_block *block = NULL; |
| 563 | |
| 564 | if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { |
| 565 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 566 | "INTERNAL ERROR: 'instance' out of range " |
| 567 | "(%d >= %d)\n", inst_nr, |
| 568 | edac_dev->nr_instances); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 569 | return; |
| 570 | } |
| 571 | |
| 572 | instance = edac_dev->instances + inst_nr; |
| 573 | |
| 574 | if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { |
| 575 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 576 | "INTERNAL ERROR: instance %d 'block' " |
| 577 | "out of range (%d >= %d)\n", |
| 578 | inst_nr, block_nr, |
| 579 | instance->nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 580 | return; |
| 581 | } |
| 582 | |
| 583 | if (instance->nr_blocks > 0) { |
| 584 | block = instance->blocks + block_nr; |
| 585 | block->counters.ce_count++; |
| 586 | } |
| 587 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 588 | /* Propagate the count up the 'totals' tree */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 589 | instance->counters.ce_count++; |
| 590 | edac_dev->counters.ce_count++; |
| 591 | |
| 592 | if (edac_device_get_log_ce(edac_dev)) |
| 593 | edac_device_printk(edac_dev, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 594 | "CE: %s instance: %s block: %s '%s'\n", |
| 595 | edac_dev->ctl_name, instance->name, |
| 596 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 597 | } |
| 598 | EXPORT_SYMBOL_GPL(edac_device_handle_ce); |
| 599 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 600 | void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 601 | int inst_nr, int block_nr, const char *msg) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 602 | { |
| 603 | struct edac_device_instance *instance; |
| 604 | struct edac_device_block *block = NULL; |
| 605 | |
| 606 | if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { |
| 607 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 608 | "INTERNAL ERROR: 'instance' out of range " |
| 609 | "(%d >= %d)\n", inst_nr, |
| 610 | edac_dev->nr_instances); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 611 | return; |
| 612 | } |
| 613 | |
| 614 | instance = edac_dev->instances + inst_nr; |
| 615 | |
| 616 | if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { |
| 617 | edac_device_printk(edac_dev, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 618 | "INTERNAL ERROR: instance %d 'block' " |
| 619 | "out of range (%d >= %d)\n", |
| 620 | inst_nr, block_nr, |
| 621 | instance->nr_blocks); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | |
| 625 | if (instance->nr_blocks > 0) { |
| 626 | block = instance->blocks + block_nr; |
| 627 | block->counters.ue_count++; |
| 628 | } |
| 629 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 630 | /* Propagate the count up the 'totals' tree */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 631 | instance->counters.ue_count++; |
| 632 | edac_dev->counters.ue_count++; |
| 633 | |
| 634 | if (edac_device_get_log_ue(edac_dev)) |
| 635 | edac_device_printk(edac_dev, KERN_EMERG, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 636 | "UE: %s instance: %s block: %s '%s'\n", |
| 637 | edac_dev->ctl_name, instance->name, |
| 638 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 639 | |
| 640 | if (edac_device_get_panic_on_ue(edac_dev)) |
Douglas Thompson | d391a7b | 2007-07-19 01:50:11 -0700 | [diff] [blame] | 641 | panic("EDAC %s: UE instance: %s block %s '%s'\n", |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 642 | edac_dev->ctl_name, instance->name, |
| 643 | block ? block->name : "N/A", msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 644 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 645 | EXPORT_SYMBOL_GPL(edac_device_handle_ue); |