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