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