edac_device.c 20 KB

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