edac_device.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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/sysdev.h>
  25. #include <linux/ctype.h>
  26. #include <linux/workqueue.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/page.h>
  29. #include "edac_core.h"
  30. #include "edac_module.h"
  31. /* lock to memory controller's control array 'edac_device_list' */
  32. static DEFINE_MUTEX(device_ctls_mutex);
  33. static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list);
  34. #ifdef CONFIG_EDAC_DEBUG
  35. static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
  36. {
  37. debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx);
  38. debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check);
  39. debugf3("\tdev = %p\n", edac_dev->dev);
  40. debugf3("\tmod_name:ctl_name = %s:%s\n",
  41. edac_dev->mod_name, edac_dev->ctl_name);
  42. debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info);
  43. }
  44. #endif /* CONFIG_EDAC_DEBUG */
  45. /*
  46. * edac_device_alloc_ctl_info()
  47. * Allocate a new edac device control info structure
  48. *
  49. * The control structure is allocated in complete chunk
  50. * from the OS. It is in turn sub allocated to the
  51. * various objects that compose the struture
  52. *
  53. * The structure has a 'nr_instance' array within itself.
  54. * Each instance represents a major component
  55. * Example: L1 cache and L2 cache are 2 instance components
  56. *
  57. * Within each instance is an array of 'nr_blocks' blockoffsets
  58. */
  59. struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  60. unsigned sz_private,
  61. char *edac_device_name, unsigned nr_instances,
  62. char *edac_block_name, unsigned nr_blocks,
  63. unsigned offset_value, /* zero, 1, or other based offset */
  64. struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib)
  65. {
  66. struct edac_device_ctl_info *dev_ctl;
  67. struct edac_device_instance *dev_inst, *inst;
  68. struct edac_device_block *dev_blk, *blk_p, *blk;
  69. struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib;
  70. unsigned total_size;
  71. unsigned count;
  72. unsigned instance, block, attr;
  73. void *pvt;
  74. debugf1("%s() instances=%d blocks=%d\n",
  75. __func__, nr_instances, nr_blocks);
  76. /* Calculate the size of memory we need to allocate AND
  77. * determine the offsets of the various item arrays
  78. * (instance,block,attrib) from the start of an allocated structure.
  79. * We want the alignment of each item (instance,block,attrib)
  80. * to be at least as stringent as what the compiler would
  81. * provide if we could simply hardcode everything into a single struct.
  82. */
  83. dev_ctl = (struct edac_device_ctl_info *)NULL;
  84. /* Calc the 'end' offset past end of ONE ctl_info structure
  85. * which will become the start of the 'instance' array
  86. */
  87. dev_inst = edac_align_ptr(&dev_ctl[1], sizeof(*dev_inst));
  88. /* Calc the 'end' offset past the instance array within the ctl_info
  89. * which will become the start of the block array
  90. */
  91. dev_blk = edac_align_ptr(&dev_inst[nr_instances], sizeof(*dev_blk));
  92. /* Calc the 'end' offset past the dev_blk array
  93. * which will become the start of the attrib array, if any.
  94. */
  95. count = nr_instances * nr_blocks;
  96. dev_attrib = edac_align_ptr(&dev_blk[count], sizeof(*dev_attrib));
  97. /* Check for case of when an attribute array is specified */
  98. if (nr_attrib > 0) {
  99. /* calc how many nr_attrib we need */
  100. count *= nr_attrib;
  101. /* Calc the 'end' offset past the attributes array */
  102. pvt = edac_align_ptr(&dev_attrib[count], sz_private);
  103. } else {
  104. /* no attribute array specificed */
  105. pvt = edac_align_ptr(dev_attrib, sz_private);
  106. }
  107. /* 'pvt' now points to where the private data area is.
  108. * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib)
  109. * is baselined at ZERO
  110. */
  111. total_size = ((unsigned long)pvt) + sz_private;
  112. /* Allocate the amount of memory for the set of control structures */
  113. dev_ctl = kzalloc(total_size, GFP_KERNEL);
  114. if (dev_ctl == NULL)
  115. return NULL;
  116. /* Adjust pointers so they point within the actual memory we
  117. * just allocated rather than an imaginary chunk of memory
  118. * located at address 0.
  119. * 'dev_ctl' points to REAL memory, while the others are
  120. * ZERO based and thus need to be adjusted to point within
  121. * the allocated memory.
  122. */
  123. dev_inst = (struct edac_device_instance *)
  124. (((char *)dev_ctl) + ((unsigned long)dev_inst));
  125. dev_blk = (struct edac_device_block *)
  126. (((char *)dev_ctl) + ((unsigned long)dev_blk));
  127. dev_attrib = (struct edac_dev_sysfs_block_attribute *)
  128. (((char *)dev_ctl) + ((unsigned long)dev_attrib));
  129. pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL;
  130. /* Begin storing the information into the control info structure */
  131. dev_ctl->nr_instances = nr_instances;
  132. dev_ctl->instances = dev_inst;
  133. dev_ctl->pvt_info = pvt;
  134. /* Name of this edac device */
  135. snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name);
  136. /* Initialize every Instance */
  137. for (instance = 0; instance < nr_instances; instance++) {
  138. inst = &dev_inst[instance];
  139. inst->ctl = dev_ctl;
  140. inst->nr_blocks = nr_blocks;
  141. blk_p = &dev_blk[instance * nr_blocks];
  142. inst->blocks = blk_p;
  143. /* name of this instance */
  144. snprintf(inst->name, sizeof(inst->name),
  145. "%s%u", edac_device_name, instance);
  146. /* Initialize every block in each instance */
  147. for (block = 0; block < nr_blocks; block++) {
  148. blk = &blk_p[block];
  149. blk->instance = inst;
  150. snprintf(blk->name, sizeof(blk->name),
  151. "%s%d", edac_block_name, block+offset_value);
  152. debugf1("%s() instance=%d block=%d name=%s\n",
  153. __func__, instance, block, blk->name);
  154. /* if there are NO attributes OR no attribute pointer
  155. * then continue on to next block iteration
  156. */
  157. if ((nr_attrib == 0) || (attrib_spec == NULL))
  158. continue;
  159. /* setup the attribute array for this block */
  160. blk->nr_attribs = nr_attrib;
  161. attrib_p = &dev_attrib[block*nr_instances*nr_attrib];
  162. blk->block_attributes = attrib_p;
  163. /* Initialize every user specified attribute in this
  164. * block with the data the caller passed in
  165. */
  166. for (attr = 0; attr < nr_attrib; attr++) {
  167. attrib = &attrib_p[attr];
  168. attrib->attr = attrib_spec->attr;
  169. attrib->show = attrib_spec->show;
  170. attrib->store = attrib_spec->store;
  171. /* up reference this block */
  172. attrib->block = blk;
  173. /* bump the attrib_spec */
  174. attrib_spec++;
  175. }
  176. }
  177. }
  178. /* Mark this instance as merely ALLOCATED */
  179. dev_ctl->op_state = OP_ALLOC;
  180. return dev_ctl;
  181. }
  182. EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
  183. /*
  184. * edac_device_free_ctl_info()
  185. * frees the memory allocated by the edac_device_alloc_ctl_info()
  186. * function
  187. */
  188. void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
  189. {
  190. kfree(ctl_info);
  191. }
  192. EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
  193. /*
  194. * find_edac_device_by_dev
  195. * scans the edac_device list for a specific 'struct device *'
  196. *
  197. * lock to be held prior to call: device_ctls_mutex
  198. *
  199. * Return:
  200. * pointer to control structure managing 'dev'
  201. * NULL if not found on list
  202. */
  203. static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
  204. {
  205. struct edac_device_ctl_info *edac_dev;
  206. struct list_head *item;
  207. debugf3("%s()\n", __func__);
  208. list_for_each(item, &edac_device_list) {
  209. edac_dev = list_entry(item, struct edac_device_ctl_info, link);
  210. if (edac_dev->dev == dev)
  211. return edac_dev;
  212. }
  213. return NULL;
  214. }
  215. /*
  216. * add_edac_dev_to_global_list
  217. * Before calling this function, caller must
  218. * assign a unique value to edac_dev->dev_idx.
  219. *
  220. * lock to be held prior to call: device_ctls_mutex
  221. *
  222. * Return:
  223. * 0 on success
  224. * 1 on failure.
  225. */
  226. static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
  227. {
  228. struct list_head *item, *insert_before;
  229. struct edac_device_ctl_info *rover;
  230. insert_before = &edac_device_list;
  231. /* Determine if already on the list */
  232. rover = find_edac_device_by_dev(edac_dev->dev);
  233. if (unlikely(rover != NULL))
  234. goto fail0;
  235. /* Insert in ascending order by 'dev_idx', so find position */
  236. list_for_each(item, &edac_device_list) {
  237. rover = list_entry(item, struct edac_device_ctl_info, link);
  238. if (rover->dev_idx >= edac_dev->dev_idx) {
  239. if (unlikely(rover->dev_idx == edac_dev->dev_idx))
  240. goto fail1;
  241. insert_before = item;
  242. break;
  243. }
  244. }
  245. list_add_tail_rcu(&edac_dev->link, insert_before);
  246. return 0;
  247. fail0:
  248. edac_printk(KERN_WARNING, EDAC_MC,
  249. "%s (%s) %s %s already assigned %d\n",
  250. rover->dev->bus_id, dev_name(rover),
  251. rover->mod_name, rover->ctl_name, rover->dev_idx);
  252. return 1;
  253. fail1:
  254. edac_printk(KERN_WARNING, EDAC_MC,
  255. "bug in low-level driver: attempt to assign\n"
  256. " duplicate dev_idx %d in %s()\n", rover->dev_idx,
  257. __func__);
  258. return 1;
  259. }
  260. /*
  261. * complete_edac_device_list_del
  262. *
  263. * callback function when reference count is zero
  264. */
  265. static void complete_edac_device_list_del(struct rcu_head *head)
  266. {
  267. struct edac_device_ctl_info *edac_dev;
  268. edac_dev = container_of(head, struct edac_device_ctl_info, rcu);
  269. INIT_LIST_HEAD(&edac_dev->link);
  270. complete(&edac_dev->complete);
  271. }
  272. /*
  273. * del_edac_device_from_global_list
  274. *
  275. * remove the RCU, setup for a callback call, then wait for the
  276. * callback to occur
  277. */
  278. static void del_edac_device_from_global_list(struct edac_device_ctl_info
  279. *edac_device)
  280. {
  281. list_del_rcu(&edac_device->link);
  282. init_completion(&edac_device->complete);
  283. call_rcu(&edac_device->rcu, complete_edac_device_list_del);
  284. wait_for_completion(&edac_device->complete);
  285. }
  286. /**
  287. * edac_device_find
  288. * Search for a edac_device_ctl_info structure whose index is 'idx'.
  289. *
  290. * If found, return a pointer to the structure.
  291. * Else return NULL.
  292. *
  293. * Caller must hold device_ctls_mutex.
  294. */
  295. struct edac_device_ctl_info *edac_device_find(int idx)
  296. {
  297. struct list_head *item;
  298. struct edac_device_ctl_info *edac_dev;
  299. /* Iterate over list, looking for exact match of ID */
  300. list_for_each(item, &edac_device_list) {
  301. edac_dev = list_entry(item, struct edac_device_ctl_info, link);
  302. if (edac_dev->dev_idx >= idx) {
  303. if (edac_dev->dev_idx == idx)
  304. return edac_dev;
  305. /* not on list, so terminate early */
  306. break;
  307. }
  308. }
  309. return NULL;
  310. }
  311. EXPORT_SYMBOL_GPL(edac_device_find);
  312. /*
  313. * edac_device_workq_function
  314. * performs the operation scheduled by a workq request
  315. */
  316. static void edac_device_workq_function(struct work_struct *work_req)
  317. {
  318. struct delayed_work *d_work = (struct delayed_work *)work_req;
  319. struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
  320. //debugf0("%s() here and running\n", __func__);
  321. mutex_lock(&device_ctls_mutex);
  322. /* Only poll controllers that are running polled and have a check */
  323. if ((edac_dev->op_state == OP_RUNNING_POLL) &&
  324. (edac_dev->edac_check != NULL)) {
  325. edac_dev->edac_check(edac_dev);
  326. }
  327. mutex_unlock(&device_ctls_mutex);
  328. /* Reschedule */
  329. queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
  330. }
  331. /*
  332. * edac_device_workq_setup
  333. * initialize a workq item for this edac_device instance
  334. * passing in the new delay period in msec
  335. */
  336. void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
  337. unsigned msec)
  338. {
  339. debugf0("%s()\n", __func__);
  340. edac_dev->poll_msec = msec;
  341. edac_dev->delay = msecs_to_jiffies(msec); /* Calc delay jiffies */
  342. INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
  343. queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
  344. }
  345. /*
  346. * edac_device_workq_teardown
  347. * stop the workq processing on this edac_dev
  348. */
  349. void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
  350. {
  351. int status;
  352. status = cancel_delayed_work(&edac_dev->work);
  353. if (status == 0) {
  354. /* workq instance might be running, wait for it */
  355. flush_workqueue(edac_workqueue);
  356. }
  357. }
  358. /*
  359. * edac_device_reset_delay_period
  360. */
  361. void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
  362. unsigned long value)
  363. {
  364. mutex_lock(&device_ctls_mutex);
  365. /* cancel the current workq request */
  366. edac_device_workq_teardown(edac_dev);
  367. /* restart the workq request, with new delay value */
  368. edac_device_workq_setup(edac_dev, value);
  369. mutex_unlock(&device_ctls_mutex);
  370. }
  371. /**
  372. * edac_device_add_device: Insert the 'edac_dev' structure into the
  373. * edac_device global list and create sysfs entries associated with
  374. * edac_device structure.
  375. * @edac_device: pointer to the edac_device structure to be added to the list
  376. * @edac_idx: A unique numeric identifier to be assigned to the
  377. * 'edac_device' structure.
  378. *
  379. * Return:
  380. * 0 Success
  381. * !0 Failure
  382. */
  383. int edac_device_add_device(struct edac_device_ctl_info *edac_dev, int edac_idx)
  384. {
  385. debugf0("%s()\n", __func__);
  386. edac_dev->dev_idx = edac_idx;
  387. #ifdef CONFIG_EDAC_DEBUG
  388. if (edac_debug_level >= 3)
  389. edac_device_dump_device(edac_dev);
  390. #endif
  391. mutex_lock(&device_ctls_mutex);
  392. if (add_edac_dev_to_global_list(edac_dev))
  393. goto fail0;
  394. /* set load time so that error rate can be tracked */
  395. edac_dev->start_time = jiffies;
  396. /* create this instance's sysfs entries */
  397. if (edac_device_create_sysfs(edac_dev)) {
  398. edac_device_printk(edac_dev, KERN_WARNING,
  399. "failed to create sysfs device\n");
  400. goto fail1;
  401. }
  402. /* If there IS a check routine, then we are running POLLED */
  403. if (edac_dev->edac_check != NULL) {
  404. /* This instance is NOW RUNNING */
  405. edac_dev->op_state = OP_RUNNING_POLL;
  406. /*
  407. * enable workq processing on this instance,
  408. * default = 1000 msec
  409. */
  410. edac_device_workq_setup(edac_dev, 1000);
  411. } else {
  412. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  413. }
  414. /* Report action taken */
  415. edac_device_printk(edac_dev, KERN_INFO,
  416. "Giving out device to module '%s' controller "
  417. "'%s': DEV '%s' (%s)\n",
  418. edac_dev->mod_name,
  419. edac_dev->ctl_name,
  420. dev_name(edac_dev),
  421. edac_op_state_to_string(edac_dev->op_state));
  422. mutex_unlock(&device_ctls_mutex);
  423. return 0;
  424. fail1:
  425. /* Some error, so remove the entry from the lsit */
  426. del_edac_device_from_global_list(edac_dev);
  427. fail0:
  428. mutex_unlock(&device_ctls_mutex);
  429. return 1;
  430. }
  431. EXPORT_SYMBOL_GPL(edac_device_add_device);
  432. /**
  433. * edac_device_del_device:
  434. * Remove sysfs entries for specified edac_device structure and
  435. * then remove edac_device structure from global list
  436. *
  437. * @pdev:
  438. * Pointer to 'struct device' representing edac_device
  439. * structure to remove.
  440. *
  441. * Return:
  442. * Pointer to removed edac_device structure,
  443. * OR NULL if device not found.
  444. */
  445. struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
  446. {
  447. struct edac_device_ctl_info *edac_dev;
  448. debugf0("MC: %s()\n", __func__);
  449. mutex_lock(&device_ctls_mutex);
  450. /* Find the structure on the list, if not there, then leave */
  451. edac_dev = find_edac_device_by_dev(dev);
  452. if (edac_dev == NULL) {
  453. mutex_unlock(&device_ctls_mutex);
  454. return NULL;
  455. }
  456. /* mark this instance as OFFLINE */
  457. edac_dev->op_state = OP_OFFLINE;
  458. /* clear workq processing on this instance */
  459. edac_device_workq_teardown(edac_dev);
  460. /* Tear down the sysfs entries for this instance */
  461. edac_device_remove_sysfs(edac_dev);
  462. /* deregister from global list */
  463. del_edac_device_from_global_list(edac_dev);
  464. mutex_unlock(&device_ctls_mutex);
  465. edac_printk(KERN_INFO, EDAC_MC,
  466. "Removed device %d for %s %s: DEV %s\n",
  467. edac_dev->dev_idx,
  468. edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev));
  469. return edac_dev;
  470. }
  471. EXPORT_SYMBOL_GPL(edac_device_del_device);
  472. static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
  473. {
  474. return edac_dev->log_ce;
  475. }
  476. static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev)
  477. {
  478. return edac_dev->log_ue;
  479. }
  480. static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info
  481. *edac_dev)
  482. {
  483. return edac_dev->panic_on_ue;
  484. }
  485. /*
  486. * edac_device_handle_ce
  487. * perform a common output and handling of an 'edac_dev' CE event
  488. */
  489. void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  490. int inst_nr, int block_nr, const char *msg)
  491. {
  492. struct edac_device_instance *instance;
  493. struct edac_device_block *block = NULL;
  494. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  495. edac_device_printk(edac_dev, KERN_ERR,
  496. "INTERNAL ERROR: 'instance' out of range "
  497. "(%d >= %d)\n", inst_nr,
  498. edac_dev->nr_instances);
  499. return;
  500. }
  501. instance = edac_dev->instances + inst_nr;
  502. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  503. edac_device_printk(edac_dev, KERN_ERR,
  504. "INTERNAL ERROR: instance %d 'block' "
  505. "out of range (%d >= %d)\n",
  506. inst_nr, block_nr,
  507. instance->nr_blocks);
  508. return;
  509. }
  510. if (instance->nr_blocks > 0) {
  511. block = instance->blocks + block_nr;
  512. block->counters.ce_count++;
  513. }
  514. /* Propogate the count up the 'totals' tree */
  515. instance->counters.ce_count++;
  516. edac_dev->counters.ce_count++;
  517. if (edac_device_get_log_ce(edac_dev))
  518. edac_device_printk(edac_dev, KERN_WARNING,
  519. "CE: %s instance: %s block: %s '%s'\n",
  520. edac_dev->ctl_name, instance->name,
  521. block ? block->name : "N/A", msg);
  522. }
  523. EXPORT_SYMBOL_GPL(edac_device_handle_ce);
  524. /*
  525. * edac_device_handle_ue
  526. * perform a common output and handling of an 'edac_dev' UE event
  527. */
  528. void edac_device_handle_ue(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.ue_count++;
  552. }
  553. /* Propogate the count up the 'totals' tree */
  554. instance->counters.ue_count++;
  555. edac_dev->counters.ue_count++;
  556. if (edac_device_get_log_ue(edac_dev))
  557. edac_device_printk(edac_dev, KERN_EMERG,
  558. "UE: %s instance: %s block: %s '%s'\n",
  559. edac_dev->ctl_name, instance->name,
  560. block ? block->name : "N/A", msg);
  561. if (edac_device_get_panic_on_ue(edac_dev))
  562. panic("EDAC %s: UE instance: %s block %s '%s'\n",
  563. edac_dev->ctl_name, instance->name,
  564. block ? block->name : "N/A", msg);
  565. }
  566. EXPORT_SYMBOL_GPL(edac_device_handle_ue);