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