blob: 4ce978b72d348f0db0e5a45515adb0e0ba5b371f [file] [log] [blame]
Douglas Thompsone27e3da2007-07-19 01:49:36 -07001
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>
23#include <linux/spinlock.h>
24#include <linux/list.h>
25#include <linux/sysdev.h>
26#include <linux/ctype.h>
27#include <linux/workqueue.h>
28#include <asm/uaccess.h>
29#include <asm/page.h>
30
31#include "edac_core.h"
32#include "edac_module.h"
33
34/* lock to memory controller's control array */
35static DECLARE_MUTEX(device_ctls_mutex);
36static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list);
37
Douglas Thompsone27e3da2007-07-19 01:49:36 -070038static inline void lock_device_list(void)
39{
40 down(&device_ctls_mutex);
41}
42
43static inline void unlock_device_list(void)
44{
45 up(&device_ctls_mutex);
46}
47
Douglas Thompsone27e3da2007-07-19 01:49:36 -070048#ifdef CONFIG_EDAC_DEBUG
49static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
50{
Douglas Thompson079708b2007-07-19 01:49:58 -070051 debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx);
Douglas Thompsone27e3da2007-07-19 01:49:36 -070052 debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check);
53 debugf3("\tdev = %p\n", edac_dev->dev);
54 debugf3("\tmod_name:ctl_name = %s:%s\n",
55 edac_dev->mod_name, edac_dev->ctl_name);
56 debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info);
57}
Douglas Thompson079708b2007-07-19 01:49:58 -070058#endif /* CONFIG_EDAC_DEBUG */
Douglas Thompsone27e3da2007-07-19 01:49:36 -070059
60/*
61 * The alloc() and free() functions for the 'edac_device' control info
62 * structure. A MC driver will allocate one of these for each edac_device
63 * it is going to control/register with the EDAC CORE.
64 */
65struct edac_device_ctl_info *edac_device_alloc_ctl_info(
66 unsigned sz_private,
67 char *edac_device_name,
68 unsigned nr_instances,
69 char *edac_block_name,
70 unsigned nr_blocks,
71 unsigned offset_value,
Douglas Thompson079708b2007-07-19 01:49:58 -070072 struct edac_attrib_spec
73 *attrib_spec,
Douglas Thompsone27e3da2007-07-19 01:49:36 -070074 unsigned nr_attribs)
75{
76 struct edac_device_ctl_info *dev_ctl;
77 struct edac_device_instance *dev_inst, *inst;
78 struct edac_device_block *dev_blk, *blk_p, *blk;
79 struct edac_attrib *dev_attrib, *attrib_p, *attrib;
80 unsigned total_size;
81 unsigned count;
82 unsigned instance, block, attr;
83 void *pvt;
84
85 debugf1("%s() instances=%d blocks=%d\n",
Douglas Thompson079708b2007-07-19 01:49:58 -070086 __func__, nr_instances, nr_blocks);
Douglas Thompsone27e3da2007-07-19 01:49:36 -070087
88 /* Figure out the offsets of the various items from the start of an
89 * ctl_info structure. We want the alignment of each item
90 * to be at least as stringent as what the compiler would
91 * provide if we could simply hardcode everything into a single struct.
92 */
Douglas Thompson079708b2007-07-19 01:49:58 -070093 dev_ctl = (struct edac_device_ctl_info *)0;
Douglas Thompsone27e3da2007-07-19 01:49:36 -070094
95 /* Calc the 'end' offset past the ctl_info structure */
96 dev_inst = (struct edac_device_instance *)
Douglas Thompson079708b2007-07-19 01:49:58 -070097 edac_align_ptr(&dev_ctl[1], sizeof(*dev_inst));
Douglas Thompsone27e3da2007-07-19 01:49:36 -070098
99 /* Calc the 'end' offset past the instance array */
100 dev_blk = (struct edac_device_block *)
Douglas Thompson079708b2007-07-19 01:49:58 -0700101 edac_align_ptr(&dev_inst[nr_instances], sizeof(*dev_blk));
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700102
103 /* Calc the 'end' offset past the dev_blk array */
104 count = nr_instances * nr_blocks;
105 dev_attrib = (struct edac_attrib *)
Douglas Thompson079708b2007-07-19 01:49:58 -0700106 edac_align_ptr(&dev_blk[count], sizeof(*dev_attrib));
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700107
108 /* Check for case of NO attributes specified */
109 if (nr_attribs > 0)
110 count *= nr_attribs;
111
112 /* Calc the 'end' offset past the attributes array */
Douglas Thompson079708b2007-07-19 01:49:58 -0700113 pvt = edac_align_ptr(&dev_attrib[count], sz_private);
114 total_size = ((unsigned long)pvt) + sz_private;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700115
116 /* Allocate the amount of memory for the set of control structures */
117 if ((dev_ctl = kmalloc(total_size, GFP_KERNEL)) == NULL)
118 return NULL;
119
120 /* Adjust pointers so they point within the memory we just allocated
121 * rather than an imaginary chunk of memory located at address 0.
122 */
123 dev_inst = (struct edac_device_instance *)
Douglas Thompson079708b2007-07-19 01:49:58 -0700124 (((char *)dev_ctl) + ((unsigned long)dev_inst));
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700125 dev_blk = (struct edac_device_block *)
Douglas Thompson079708b2007-07-19 01:49:58 -0700126 (((char *)dev_ctl) + ((unsigned long)dev_blk));
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700127 dev_attrib = (struct edac_attrib *)
Douglas Thompson079708b2007-07-19 01:49:58 -0700128 (((char *)dev_ctl) + ((unsigned long)dev_attrib));
129 pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700130
Douglas Thompson079708b2007-07-19 01:49:58 -0700131 memset(dev_ctl, 0, total_size); /* clear all fields */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700132 dev_ctl->nr_instances = nr_instances;
133 dev_ctl->instances = dev_inst;
134 dev_ctl->pvt_info = pvt;
135
136 /* Name of this edac device, ensure null terminated */
Douglas Thompson079708b2007-07-19 01:49:58 -0700137 snprintf(dev_ctl->name, sizeof(dev_ctl->name), "%s", edac_device_name);
138 dev_ctl->name[sizeof(dev_ctl->name) - 1] = '\0';
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700139
140 /* Initialize every Instance */
141 for (instance = 0; instance < nr_instances; instance++) {
142 inst = &dev_inst[instance];
143 inst->ctl = dev_ctl;
144 inst->nr_blocks = nr_blocks;
145 blk_p = &dev_blk[instance * nr_blocks];
146 inst->blocks = blk_p;
147
148 /* name of this instance */
149 snprintf(inst->name, sizeof(inst->name),
Douglas Thompson079708b2007-07-19 01:49:58 -0700150 "%s%u", edac_device_name, instance);
151 inst->name[sizeof(inst->name) - 1] = '\0';
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700152
153 /* Initialize every block in each instance */
Douglas Thompson079708b2007-07-19 01:49:58 -0700154 for (block = 0; block < nr_blocks; block++) {
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700155 blk = &blk_p[block];
156 blk->instance = inst;
157 blk->nr_attribs = nr_attribs;
158 attrib_p = &dev_attrib[block * nr_attribs];
159 blk->attribs = attrib_p;
160 snprintf(blk->name, sizeof(blk->name),
Douglas Thompson079708b2007-07-19 01:49:58 -0700161 "%s%d", edac_block_name, block + 1);
162 blk->name[sizeof(blk->name) - 1] = '\0';
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700163
164 debugf1("%s() instance=%d block=%d name=%s\n",
Douglas Thompson079708b2007-07-19 01:49:58 -0700165 __func__, instance, block, blk->name);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700166
167 if (attrib_spec != NULL) {
168 /* when there is an attrib_spec passed int then
169 * Initialize every attrib of each block
170 */
171 for (attr = 0; attr < nr_attribs; attr++) {
172 attrib = &attrib_p[attr];
173 attrib->block = blk;
174
175 /* Link each attribute to the caller's
176 * spec entry, for name and type
Douglas Thompson079708b2007-07-19 01:49:58 -0700177 */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700178 attrib->spec = &attrib_spec[attr];
179 }
180 }
181 }
182 }
183
184 /* Mark this instance as merely ALLOCATED */
185 dev_ctl->op_state = OP_ALLOC;
186
187 return dev_ctl;
188}
Douglas Thompson079708b2007-07-19 01:49:58 -0700189
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700190EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
191
192/*
193 * edac_device_free_ctl_info()
194 * frees the memory allocated by the edac_device_alloc_ctl_info()
195 * function
196 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700197void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
198{
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700199 kfree(ctl_info);
200}
Douglas Thompson079708b2007-07-19 01:49:58 -0700201
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700202EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
203
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700204/*
205 * find_edac_device_by_dev
206 * scans the edac_device list for a specific 'struct device *'
207 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700208static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700209{
210 struct edac_device_ctl_info *edac_dev;
211 struct list_head *item;
212
213 debugf3("%s()\n", __func__);
214
215 list_for_each(item, &edac_device_list) {
216 edac_dev = list_entry(item, struct edac_device_ctl_info, link);
217
218 if (edac_dev->dev == dev)
219 return edac_dev;
220 }
221
222 return NULL;
223}
224
225/*
226 * add_edac_dev_to_global_list
227 * Before calling this function, caller must
228 * assign a unique value to edac_dev->dev_idx.
229 * Return:
230 * 0 on success
231 * 1 on failure.
232 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700233static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700234{
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 */
241 if (unlikely((rover = find_edac_device_by_dev(edac_dev->dev)) != NULL))
242 goto fail0;
243
244 /* Insert in ascending order by 'dev_idx', so find position */
245 list_for_each(item, &edac_device_list) {
246 rover = list_entry(item, struct edac_device_ctl_info, link);
247
248 if (rover->dev_idx >= edac_dev->dev_idx) {
249 if (unlikely(rover->dev_idx == edac_dev->dev_idx))
250 goto fail1;
251
252 insert_before = item;
253 break;
254 }
255 }
256
257 list_add_tail_rcu(&edac_dev->link, insert_before);
258 return 0;
259
Douglas Thompson079708b2007-07-19 01:49:58 -0700260 fail0:
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700261 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson079708b2007-07-19 01:49:58 -0700262 "%s (%s) %s %s already assigned %d\n",
263 rover->dev->bus_id, dev_name(rover),
264 rover->mod_name, rover->ctl_name, rover->dev_idx);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700265 return 1;
266
Douglas Thompson079708b2007-07-19 01:49:58 -0700267 fail1:
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700268 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson079708b2007-07-19 01:49:58 -0700269 "bug in low-level driver: attempt to assign\n"
270 " duplicate dev_idx %d in %s()\n", rover->dev_idx,
271 __func__);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700272 return 1;
273}
274
275/*
276 * complete_edac_device_list_del
277 */
278static void complete_edac_device_list_del(struct rcu_head *head)
279{
280 struct edac_device_ctl_info *edac_dev;
281
282 edac_dev = container_of(head, struct edac_device_ctl_info, rcu);
283 INIT_LIST_HEAD(&edac_dev->link);
284 complete(&edac_dev->complete);
285}
286
287/*
288 * del_edac_device_from_global_list
289 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700290static void del_edac_device_from_global_list(struct edac_device_ctl_info
291 *edac_device)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700292{
293 list_del_rcu(&edac_device->link);
294 init_completion(&edac_device->complete);
295 call_rcu(&edac_device->rcu, complete_edac_device_list_del);
296 wait_for_completion(&edac_device->complete);
297}
298
299/**
300 * edac_device_find
301 * Search for a edac_device_ctl_info structure whose index is 'idx'.
302 *
303 * If found, return a pointer to the structure.
304 * Else return NULL.
305 *
306 * Caller must hold device_ctls_mutex.
307 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700308struct edac_device_ctl_info *edac_device_find(int idx)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700309{
310 struct list_head *item;
311 struct edac_device_ctl_info *edac_dev;
312
313 /* Iterate over list, looking for exact match of ID */
314 list_for_each(item, &edac_device_list) {
315 edac_dev = list_entry(item, struct edac_device_ctl_info, link);
316
317 if (edac_dev->dev_idx >= idx) {
318 if (edac_dev->dev_idx == idx)
319 return edac_dev;
320
321 /* not on list, so terminate early */
322 break;
323 }
324 }
325
326 return NULL;
327}
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700328
Douglas Thompson079708b2007-07-19 01:49:58 -0700329EXPORT_SYMBOL(edac_device_find);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700330
331/*
Dave Jiang81d87cb2007-07-19 01:49:52 -0700332 * edac_device_workq_function
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700333 * performs the operation scheduled by a workq request
334 */
335#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
Dave Jiang81d87cb2007-07-19 01:49:52 -0700336static void edac_device_workq_function(struct work_struct *work_req)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700337{
Douglas Thompson079708b2007-07-19 01:49:58 -0700338 struct delayed_work *d_work = (struct delayed_work *)work_req;
339 struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700340#else
Dave Jiang81d87cb2007-07-19 01:49:52 -0700341static void edac_device_workq_function(void *ptr)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700342{
343 struct edac_device_ctl_info *edac_dev =
Douglas Thompson079708b2007-07-19 01:49:58 -0700344 (struct edac_device_ctl_info *)ptr;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700345#endif
346
347 //debugf0("%s() here and running\n", __func__);
348 lock_device_list();
349
350 /* Only poll controllers that are running polled and have a check */
351 if ((edac_dev->op_state == OP_RUNNING_POLL) &&
Douglas Thompson079708b2007-07-19 01:49:58 -0700352 (edac_dev->edac_check != NULL)) {
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700353 edac_dev->edac_check(edac_dev);
354 }
355
356 unlock_device_list();
357
358 /* Reschedule */
Douglas Thompson079708b2007-07-19 01:49:58 -0700359 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700360}
361
362/*
Dave Jiang81d87cb2007-07-19 01:49:52 -0700363 * edac_device_workq_setup
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700364 * initialize a workq item for this edac_device instance
365 * passing in the new delay period in msec
366 */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700367void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
Douglas Thompson079708b2007-07-19 01:49:58 -0700368 unsigned msec)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700369{
370 debugf0("%s()\n", __func__);
371
372 edac_dev->poll_msec = msec;
Dave Jiang81d87cb2007-07-19 01:49:52 -0700373 edac_calc_delay(edac_dev); /* Calc delay jiffies */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700374
375#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
Dave Jiang81d87cb2007-07-19 01:49:52 -0700376 INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700377#else
Dave Jiang81d87cb2007-07-19 01:49:52 -0700378 INIT_WORK(&edac_dev->work, edac_device_workq_function, edac_dev);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700379#endif
Dave Jiang81d87cb2007-07-19 01:49:52 -0700380 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700381}
382
383/*
Dave Jiang81d87cb2007-07-19 01:49:52 -0700384 * edac_device_workq_teardown
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700385 * stop the workq processing on this edac_dev
386 */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700387void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700388{
389 int status;
390
391 status = cancel_delayed_work(&edac_dev->work);
392 if (status == 0) {
393 /* workq instance might be running, wait for it */
394 flush_workqueue(edac_workqueue);
395 }
396}
397
398/*
399 * edac_device_reset_delay_period
400 */
401
Douglas Thompson079708b2007-07-19 01:49:58 -0700402void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
403 unsigned long value)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700404{
405 lock_device_list();
406
407 /* cancel the current workq request */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700408 edac_device_workq_teardown(edac_dev);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700409
410 /* restart the workq request, with new delay value */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700411 edac_device_workq_setup(edac_dev, value);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700412
413 unlock_device_list();
414}
415
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700416/**
417 * edac_device_add_device: Insert the 'edac_dev' structure into the
418 * edac_device global list and create sysfs entries associated with
419 * edac_device structure.
420 * @edac_device: pointer to the edac_device structure to be added to the list
421 * @edac_idx: A unique numeric identifier to be assigned to the
422 * 'edac_device' structure.
423 *
424 * Return:
425 * 0 Success
426 * !0 Failure
427 */
428int edac_device_add_device(struct edac_device_ctl_info *edac_dev, int edac_idx)
429{
430 debugf0("%s()\n", __func__);
431
432 edac_dev->dev_idx = edac_idx;
433#ifdef CONFIG_EDAC_DEBUG
434 if (edac_debug_level >= 3)
435 edac_device_dump_device(edac_dev);
436#endif
437 lock_device_list();
438
439 if (add_edac_dev_to_global_list(edac_dev))
440 goto fail0;
441
442 /* set load time so that error rate can be tracked */
443 edac_dev->start_time = jiffies;
444
445 /* create this instance's sysfs entries */
446 if (edac_device_create_sysfs(edac_dev)) {
447 edac_device_printk(edac_dev, KERN_WARNING,
Douglas Thompson079708b2007-07-19 01:49:58 -0700448 "failed to create sysfs device\n");
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700449 goto fail1;
450 }
451
452 /* If there IS a check routine, then we are running POLLED */
453 if (edac_dev->edac_check != NULL) {
454 /* This instance is NOW RUNNING */
455 edac_dev->op_state = OP_RUNNING_POLL;
456
Dave Jiang81d87cb2007-07-19 01:49:52 -0700457 /*
458 * enable workq processing on this instance,
459 * default = 1000 msec
460 */
461 edac_device_workq_setup(edac_dev, 1000);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700462 } else {
463 edac_dev->op_state = OP_RUNNING_INTERRUPT;
464 }
465
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700466 /* Report action taken */
467 edac_device_printk(edac_dev, KERN_INFO,
Douglas Thompson079708b2007-07-19 01:49:58 -0700468 "Giving out device to module '%s' controller '%s': DEV '%s' (%s)\n",
469 edac_dev->mod_name,
470 edac_dev->ctl_name,
471 dev_name(edac_dev),
472 edac_op_state_toString(edac_dev->op_state)
473 );
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700474
475 unlock_device_list();
476 return 0;
477
Douglas Thompson079708b2007-07-19 01:49:58 -0700478 fail1:
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700479 /* Some error, so remove the entry from the lsit */
480 del_edac_device_from_global_list(edac_dev);
481
Douglas Thompson079708b2007-07-19 01:49:58 -0700482 fail0:
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700483 unlock_device_list();
484 return 1;
485}
Douglas Thompson079708b2007-07-19 01:49:58 -0700486
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700487EXPORT_SYMBOL_GPL(edac_device_add_device);
488
489/**
490 * edac_device_del_device:
491 * Remove sysfs entries for specified edac_device structure and
492 * then remove edac_device structure from global list
493 *
494 * @pdev:
495 * Pointer to 'struct device' representing edac_device
496 * structure to remove.
497 *
498 * Return:
499 * Pointer to removed edac_device structure,
500 * OR NULL if device not found.
501 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700502struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700503{
504 struct edac_device_ctl_info *edac_dev;
505
506 debugf0("MC: %s()\n", __func__);
507
508 lock_device_list();
509
510 if ((edac_dev = find_edac_device_by_dev(dev)) == NULL) {
511 unlock_device_list();
512 return NULL;
513 }
514
515 /* mark this instance as OFFLINE */
516 edac_dev->op_state = OP_OFFLINE;
517
518 /* clear workq processing on this instance */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700519 edac_device_workq_teardown(edac_dev);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700520
521 /* Tear down the sysfs entries for this instance */
522 edac_device_remove_sysfs(edac_dev);
523
524 /* deregister from global list */
525 del_edac_device_from_global_list(edac_dev);
526
527 unlock_device_list();
528
529 edac_printk(KERN_INFO, EDAC_MC,
Douglas Thompson079708b2007-07-19 01:49:58 -0700530 "Removed device %d for %s %s: DEV %s\n",
531 edac_dev->dev_idx,
532 edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev));
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700533
534 return edac_dev;
535}
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700536
Douglas Thompson079708b2007-07-19 01:49:58 -0700537EXPORT_SYMBOL_GPL(edac_device_del_device);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700538
539static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
540{
541 return edac_dev->log_ce;
542}
543
544static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev)
545{
546 return edac_dev->log_ue;
547}
548
Douglas Thompson079708b2007-07-19 01:49:58 -0700549static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info
550 *edac_dev)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700551{
552 return edac_dev->panic_on_ue;
553}
554
555/*
556 * edac_device_handle_ce
557 * perform a common output and handling of an 'edac_dev' CE event
558 */
559void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
Douglas Thompson079708b2007-07-19 01:49:58 -0700560 int inst_nr, int block_nr, const char *msg)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700561{
562 struct edac_device_instance *instance;
563 struct edac_device_block *block = NULL;
564
565 if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
566 edac_device_printk(edac_dev, KERN_ERR,
Douglas Thompson079708b2007-07-19 01:49:58 -0700567 "INTERNAL ERROR: 'instance' out of range "
568 "(%d >= %d)\n", inst_nr,
569 edac_dev->nr_instances);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700570 return;
571 }
572
573 instance = edac_dev->instances + inst_nr;
574
575 if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
576 edac_device_printk(edac_dev, KERN_ERR,
Douglas Thompson079708b2007-07-19 01:49:58 -0700577 "INTERNAL ERROR: instance %d 'block' out of range "
578 "(%d >= %d)\n", inst_nr, block_nr,
579 instance->nr_blocks);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700580 return;
581 }
582
583 if (instance->nr_blocks > 0) {
584 block = instance->blocks + block_nr;
585 block->counters.ce_count++;
586 }
587
588 /* Propogate the count up the 'totals' tree */
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 Thompson079708b2007-07-19 01:49:58 -0700594 "CE ctl: %s, instance: %s, block: %s: %s\n",
595 edac_dev->ctl_name, instance->name,
596 block ? block->name : "N/A", msg);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700597}
Douglas Thompson079708b2007-07-19 01:49:58 -0700598
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700599EXPORT_SYMBOL_GPL(edac_device_handle_ce);
600
601/*
602 * edac_device_handle_ue
603 * perform a common output and handling of an 'edac_dev' UE event
604 */
605void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
Douglas Thompson079708b2007-07-19 01:49:58 -0700606 int inst_nr, int block_nr, const char *msg)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700607{
608 struct edac_device_instance *instance;
609 struct edac_device_block *block = NULL;
610
611 if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
612 edac_device_printk(edac_dev, KERN_ERR,
Douglas Thompson079708b2007-07-19 01:49:58 -0700613 "INTERNAL ERROR: 'instance' out of range "
614 "(%d >= %d)\n", inst_nr,
615 edac_dev->nr_instances);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700616 return;
617 }
618
619 instance = edac_dev->instances + inst_nr;
620
621 if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
622 edac_device_printk(edac_dev, KERN_ERR,
Douglas Thompson079708b2007-07-19 01:49:58 -0700623 "INTERNAL ERROR: instance %d 'block' out of range "
624 "(%d >= %d)\n", inst_nr, block_nr,
625 instance->nr_blocks);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700626 return;
627 }
628
629 if (instance->nr_blocks > 0) {
630 block = instance->blocks + block_nr;
631 block->counters.ue_count++;
632 }
633
634 /* Propogate the count up the 'totals' tree */
635 instance->counters.ue_count++;
636 edac_dev->counters.ue_count++;
637
638 if (edac_device_get_log_ue(edac_dev))
639 edac_device_printk(edac_dev, KERN_EMERG,
Douglas Thompson079708b2007-07-19 01:49:58 -0700640 "UE ctl: %s, instance: %s, block: %s: %s\n",
641 edac_dev->ctl_name, instance->name,
642 block ? block->name : "N/A", msg);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700643
644 if (edac_device_get_panic_on_ue(edac_dev))
645 panic("EDAC %s: UE instance: %s, block %s: %s\n",
Douglas Thompson079708b2007-07-19 01:49:58 -0700646 edac_dev->ctl_name, instance->name,
647 block ? block->name : "N/A", msg);
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700648}
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700649
Douglas Thompson079708b2007-07-19 01:49:58 -0700650EXPORT_SYMBOL_GPL(edac_device_handle_ue);