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